-
Notifications
You must be signed in to change notification settings - Fork 0
/
FINALNOST1.pde
157 lines (124 loc) · 3.5 KB
/
FINALNOST1.pde
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
import processing.pdf.*;
import ddf.minim.*;
import ddf.minim.analysis.*;
import ddf.minim.ugens.*;
PGraphics canvas;
Minim minim;
AudioInput in;
FFT fft;
int sampleRate= 22050;//sapleRate ofr 44100
Gain gain;
boolean crt=false;
float r;
float x;
float y;
float c;
float d;
int a;
int b;
float e;
float f;
float g;
float h;
float j;
float k;
float l;
int value;
int number=0;
void setup()
{
fullScreen();
background(200);
canvas = createGraphics(width, height);
frameRate(30);
minim = new Minim(this);
minim.debugOn();
in = minim.getLineIn(Minim.MONO, 256, sampleRate);
fft = new FFT(in.left.size(), sampleRate);
gain = new Gain(60);
}
void draw() {
background(200);
surface.setTitle(int(frameRate) + " fps");
if (crt=true) {
x = lerp(x, mouseX, 0.5); //što je bliže nuli, to više interpolira. i obrnuto ofc
y = lerp(y, mouseY, 0.5); //što je bliže nuli, to više interpolira. i obrnuto ofc
}
if (in.left.level()>0.004) {
crt=true;
} else crt=false;
if (in.left.level()>0.01) {
b = int(random(100, 350));
} else if (in.left.level()>0.06) {
b = int(random(110, 130));
} else if (in.left.level()>0.1) {
b = int(random(130, 160));
} else if (in.left.level()>0.3) {
b = int(random(160, 250));
} else if (in.left.level()>0.5) {
b = int(random(250, 350));
} else {
b = int(random(-200, 800));
}
if (in.left.level()>0.01) {
f = int(random(width/2-20, width/2+20));
} else if (in.left.level()>0.06) {
f = int(random(width/2-100, width/2+100));
} else if (in.left.level()>0.1) {
f = int(random(width/2-200, width/2+200));
} else if (in.left.level()>0.3) {
f = int(random(width/2-500, width/2+500));
} else if (in.left.level()>0.5) {
f = int(random(width/2-700, width/2+700));
} else {
b = int(random(-200, 800));
}
fadeGraphics(canvas, 2);
canvas.beginDraw();
for (int i = 0; i < in.bufferSize() - 1; i++)
{
if (crt==true) {
int a = int(random(in.left.get(i)*4000, in.left.get(i+1)*4000));
float c =(in.left.level()*10000);
float d =map(in.left.get(i+1),0.0001,0.18,860,1060);
float e =(random(height));
float f =(random(300, 1620));
float h =map(in.left.level(),0.0001,0.18,50,0);
float g =map(in.left.level(),0.0085,0.1,1,15);
float j =map(in.left.get(i+1),0.0001,0.18,1560,1660);
float k =map(in.left.get(i+1),0.0001,0.18,460,500);
canvas.noFill();
canvas.stroke(0);
canvas.strokeWeight(abs(g));
canvas.beginShape();
canvas.curveVertex(f, c+500);
canvas.curveVertex(f, c+500);
canvas.curveVertex(d,b);
canvas.curveVertex(j,k);
canvas.curveVertex(c, e);
canvas.curveVertex(c, e);
} else
crt=false;
break;
}
canvas.endShape();
canvas.endDraw();
image(canvas, 0, 0);
if (key == 'F' || key == 'f') // ako stisneš F ili f, izbrišeš sve
background(200);
}
void fadeGraphics(PGraphics c, int fadeAmount) {
c.beginDraw();
c.loadPixels();
// iterate over pixels
for (int i =0; i<c.pixels.length; i++) {
// get alpha value
int alpha = (c.pixels[i] >> 24) & 0xFF ;
// reduce alpha value
alpha = max(0, alpha-fadeAmount);
// assign color with new alpha-value
c.pixels[i] = alpha<<24 | (c.pixels[i]) & 0xFFFFFF ;
}
canvas.updatePixels();
canvas.endDraw();
}