-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsketch_7idiots.pde
143 lines (112 loc) · 3.21 KB
/
sketch_7idiots.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
import peasy.*;
import peasy.org.apache.commons.math.*;
import peasy.org.apache.commons.math.geometry.*;
import peasy.test.*;
import ddf.minim.analysis.*;
import ddf.minim.*;
Minim minim;
AudioPlayer jingle;
FFT fft;
PeasyCam cam;
PImage background;
PShader blur;
color[] imagePixels;
void setup()
{
size(600, 600, P3D);
background(10);
pixelDensity(2);
minim = new Minim(this);
blur = loadShader("blur.glsl");
// specify that we want the audio buffers of the AudioPlayer
// to be 1024 samples long because our FFT needs to have
// a power-of-two buffer size and this is a good size.
jingle = minim.loadFile("Velius.mp3", 1024);
// loop the file indefinitely
jingle.loop();
// create an FFT object that has a time-domain buffer
// the same size as jingle's sample buffer
// note that this needs to be a power of two
// and that it means the size of the spectrum will be half as large.
fft = new FFT( jingle.bufferSize(), jingle.sampleRate() );
// calculate the averages by grouping frequency bands linearly. use 30 averages.
fft.logAverages( 22, 2);
//
// cam = new PeasyCam(this, 100);
// cam.setMinimumDistance(50);
// cam.setMaximumDistance(5000);
//
background = loadImage("universe.jpg");
background.loadPixels();
imagePixels = background.pixels;
}
float rotate_x_angle;
float rotate_y_angle;
void draw()
{
// perform a forward FFT on the samples in jingle's mix buffer,
// which contains the mix of both the left and right channels of the file
fft.forward( jingle.mix );
float instr[] = new float[] {
fft.getBand(11), //ding ling
fft.getBand(13), //ding ling 2
fft.getBand(39), //echo
fft.getBand(1) //beat
};
//cube
{
pushMatrix();
fill(0, 10);
translate(width/2, height/2);
sphereDetail(2);
strokeWeight(0.5);
rotateX(rotate_x_angle);
rotateY(rotate_y_angle);
sphere(instr[1]*2);
popMatrix();
}
rotate_x_angle+=0.01;
rotate_y_angle+=0.01;
//ding ling
if (instr[0]>30) {
Stain another_stain = new Stain(instr[0]*20);
another_stain.fillC = imagePixels[ floor(another_stain.center_y * background.width) + floor(another_stain.center_x)];
another_stain.alphaModifier = map(instr[0], 30, 120, 100, 255);
another_stain.display();
}
//beat
if (instr[3]>30) {
int temp_x = int(random(0, width));
int temp_y = int(random(0, height));
int temp_x_2 = temp_x + int(instr[3]);
int temp_y_2 = temp_y + int(instr[3]);
strokeWeight(1);
//beginShape(LINES);
//color temp_c = imagePixels[ floor(temp_y * background.width) + floor(temp_x)];
//fill(temp_c);
//vertex(temp_x_2, temp_y_2);
//vertex(temp_x, temp_y);
//fill(red(temp_c), green(temp_c), blue(temp_c), 20);
//endShape(CLOSE);
}
// // for (int i=0; i<1; i++) {
// // }
// drawBands();
}
void drawBands() {
int w = 20;
for (int i=0; i<fft.specSize (); i++) {
strokeWeight(w-1);
stroke(255);
line(i*w, height, i*w, height-fft.getBand(i));
fill(255, 0, 0);
textAlign(CENTER);
textSize(6);
text(i, i*w, height-20);
}
strokeWeight(0.5);
stroke(0, 255, 0);
for (int o=10; o<100; o+=10) {
line(0, height-o, width, height-o);
}
}