-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTarea_4_3.js
158 lines (135 loc) · 3.42 KB
/
Tarea_4_3.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/*
The big bang
Proyecto final del curso Progrmacación Creativa, introducción a P5.JS por CODED Escuela www.codedescuela.cl
Usando las funciones random y noise
Uso de P5.sound
por Sebastián Arias "the jipi coder"
*/
var t;
var NUM_LINES;
var contador;
var cicle;
var input;
var output;
var mic;
var VELOCITY;
var sw;
var xoff = 0;
var threshold = 0.7;
var inc = 0.5; // nivel de random en noise.
var scl = 7;
var cols,rows;
var zoff = 0;
var limit = 8;
var litle_factor = 0.1;
function setup(){
createCanvas(700,500);
background(20);
t = 0;
NUM_LINES = 100;
VELOCITY = 0.1;
randomSeed(5);
contador = 0;
cicle = 0;
mic = new p5.AudioIn()
mic.start();
fft = new p5.FFT(); //requerido para el análisis de la frecuencia
fft.setInput(mic);
//noLoop();
sw = 0;
//variables para pintura abstacta.
cols = floor( width / scl);
rows = floor (height / scl);
//colorMode(HSB,100);
//frameRate(20);
}
function draw(){
//background(0);
micLevel = mic.getLevel();
if(sw > limit){
drawAbstractPaint(rows,cols,inc,scl);
}
else{
if(micLevel > threshold){
sw ++;
console.log(sw);
}else{
sw =0;
}
t = drawLines(micLevel, t, 0.5);
}
contador ++;
}
function drawLines(micLevel, t, grosor){
background(0);
strokeWeight(grosor);
translate(width / 2,height / 2);
if(micLevel > 0.12){
go_crazy = true;
}
for(var i = 0; i < NUM_LINES; i++){
//escala el valor del volumen del mic a una proporción de 1 a 5
var size = map(micLevel,0.1,1,1,4.5);
drawPinkLine(i, t, size);
drawBlueLine(i, t, size);
rotate(HALF_PI);
drawPinkLine(i, t, size);
drawBlueLine(i, t, size);
rotate(HALF_PI);
drawPinkLine(i, t, size * litle_factor);
drawBlueLine(i, t, size * litle_factor);
rotate(HALF_PI);
drawPinkLine(i, t, size * litle_factor);
drawBlueLine(i, t, size * litle_factor);
}
return t += VELOCITY;
//
}
function drawPinkLine(i, t, size){
stroke(200 * size, 150 * size, 360 * size);
line(x1(t + i),y1(t + i),x2(t + i) * size,y2(t + i) * size);
}
function drawBlueLine(i, t, size){
stroke(0, 150, 360 * size);
line(x1((t + i) * -1 ),y1((t + i) * -1),x2((t + i) * -1) * size ,y2((t + i) * -1) * size);
}
function drawAbstractPaint(){
var yoff = 0
for(var y = 0; y < rows; y++){
var coff = 0;
for (var x = 0; x < cols; x++) {
//en cada bloque se dibujará un vector con angulo.
//var index = (x + y * width) * 4;
var angle = noise(coff, yoff, zoff) * TWO_PI;
var v = p5.Vector.fromAngle(angle);
xoff += inc;
strokeWeight(0.1);
stroke(map(noise(coff),0,1,0,255),map(noise(yoff),0,1,0,255),map(noise(zoff),0,1,0,255));
//stroke(map(random(xoff),0,1,0,255),map(random(yoff),0,1,0,255),map(random(zoff),0,1,0,255),random(50,100));
//push();
translate(x * scl + mapea_miclevel(), y * scl + mapea_miclevel());
rotate(v.heading());
line(0, 0, scl * 20, 0);
//pop();
}
yoff += inc;
zoff += 0.001; // velocidad de movimiento de los vectores.
//t = drawLines(micLevel, t, 0.5);
}
}
function x1(t){
return sin(t /10) * 100 + sin(t / 5) * 20;
}
function y1(t){
return cos(-t / 10) * 10 + sin(t / 5) * 50;
}
function x2(t){
//return sin(t / 10) * 200 + sin(t)* 2;
return sin(t / 10) * 200 + sin(t)* 20;
}
function y2(t){
return -cos(t / 20) * 200 + cos(t / 12) * 20;
}
function mapea_miclevel(){
return map(micLevel,0,1,0.1,0.7);
}