-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsceneWaveLandscapeTrigger.pde
149 lines (111 loc) · 3.35 KB
/
sceneWaveLandscapeTrigger.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
class waveLandscapeTrigger extends Scene {
Wave waves[];
waveLandscapeTrigger(SceneTime[] times) {
super("waveLandscapeTrigger",times);
}
void setup() {
waves = new Wave[6];
int size = width;
int w=0;
waves[w++] = new Wave( size, color(255,0,0) );
waves[w++] = new Wave( size, color(255,255,0) );
waves[w++] = new Wave( size, color(255,0,255) );
waves[w++] = new Wave( size, color(0,255,255) );
waves[w++] = new Wave( size, color(0,255,0) );
waves[w++] = new Wave( size, color(255,255,255) );
}
void draw() {
for( int w=0; w<waves.length; w++) {
waves[w].moveAndDraw();
}
}
class Wave {
MovingPoint point[] = new MovingPoint[2];
int range;
color c;
Wave(int size, color c) {
float maxSpeed = 1;
point[0] = new MovingPoint( int(random(0,width)), int(random(0,height)), maxSpeed);
point[1] = new MovingPoint( int(random(point[0].x()-size,point[0].x()+size)), int(random(point[0].y()-size,point[0].y()+size)), maxSpeed);
this.c = c;
this.range = size/5;
}
void moveAndDraw() {
this.move();
this.draw();
}
void move() {
if (player.mix.level() > .2) {
point[0].move(true);
point[1].move(true);
// slice();
}
else {
point[0].move(false);
point[1].move(false);
}
}
void slice() {
int w = int(random(width/2));
int h = int(random(height/2));
int x1 = int(random(0, width));
int y1 = int(random(0, height));
int x2 = int(random(0, width));
int y2 = int(random(0, height));
copy(x1, y1, w, h, x2, y2, w, h);
}
void draw() {
float level = player.mix.level();
float red = red(c);
float green = green(c);
float blue = blue(c);
float alpha = 2 + 100*level;
color currentColor = color(red,green,blue,alpha);
stroke(currentColor);
strokeWeight(1 + level);
int size = player.bufferSize();
for(int i = 0; i < size - 1; i++)
{
float angle = PVector.angleBetween(point[0].getVector(), point[1].getVector());
float volume = player.mix.get(i)*range;
float x1 = map( i, 0,size, point[0].x(),point[1].x() ) + volume * cos(angle);
float y1 = map( i, 0,size, point[0].y(),point[1].y() ) + volume * sin(angle);
volume = player.mix.get(i+1)*range;
float x2 = map( i+1, 0,size, point[0].x(),point[1].x() ) + volume * cos(angle);
float y2 = map( i+1, 0,size, point[0].y(),point[1].y() ) + volume * sin(angle);
line( x1, y1, x2, y2);
}
}
}
class MovingPoint {
PVector position,speed;
MovingPoint(int x, int y, float maxSpeed) {
position = new PVector( x, y );
speed = new PVector( random(1,maxSpeed), random(1,maxSpeed) );
}
void move(boolean fast) {
if (fast) {
PVector fastSpeed = PVector.mult(speed,40);
position.add(fastSpeed);
}
else {
position.add(speed);
}
if (position.x > width*1.1 || position.x < 0-width*0.1 ) {
speed.x = - speed.x;
}
if (position.y > height*1.1 || position.y < 0-height*0.1 ) {
speed.y = - speed.y;
}
}
PVector getVector() {
return position;
}
int x() {
return int(position.x);
}
int y() {
return int(position.y);
}
}
}