-
Notifications
You must be signed in to change notification settings - Fork 2
/
x.pde
213 lines (172 loc) · 5.25 KB
/
x.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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
/*---- YOUR CUSTOM CODE BELOW --------------------------*/
import java.util.Iterator;
float acc =0;
class ParticleSystem {
ArrayList particles;
PVector origin;
PVector dir;
float speed;
PVector wiggle;
ParticleSystem(PVector location, PVector dir_, float speed_, PVector wiggle_) {
origin = location.copy();
dir = dir_.copy();
particles = new ArrayList();
speed = speed_;
wiggle = wiggle_.copy();
}
void addParticle() {
particles.add(new Particle(origin, dir, speed, wiggle));
}
void run() {
Iterator<Particle> it = particles.iterator();
while (it.hasNext()) {
Particle p = it.next();
p.update();
p.display();
if (p.isDead()) {
it.remove();
}
}
}
}
class Particle {
PVector location;
PVector velocity;
PVector acceleration;
boolean laser;
//PVector wiggle;
Particle(PVector l, PVector dir_, float speed_, PVector wiggle_) {
//[offset-up] For demonstration purposes we assign the Particle an initial velocity and constant acceleration.
acceleration = new PVector(0, acc);
//velocity = new PVector(random(-1,1),random(-2,0));
velocity = dir_.copy().setMag(speed_).add(random(-wiggle_.x, wiggle_.x), random(wiggle_.y));
location = l.copy();
if (random(1)<0.005) {
laser = true;
}
}
// Sometimes it’s convenient to have a “run”
// function that calls all the other functions we need.
void run() {
update();
display();
}
void update() {
velocity.add(acceleration);
location.add(velocity);
}
void display() {
stroke(255);
fill(0);
if (laser) {
xellipse(location.x, location.y, rad, rad);
} else {
ellipse(location.x, location.y, rad*2, rad*2);
}
//point(location.x, location.y);
}
// Is the Particle alive or dead?
boolean isDead() {
if (location.x >width || location.x <-10 || location.y > height || location.y < -10) {
return true;
} else {
return false;
}
}
}
/*---- PUT OWN VARIABLES JUST BEFORE customSetup()-----*/
// name vars starting with your letter to avoid duplicate variables!
// float aXpos = 0;
// int aSpeed = 0;
int numPS = 50;
float rad =2;
//ParticleSystem ps = new ParticleSystem(new PVector(150, -rad));
ParticleSystem[] ps;
PVector direction = new PVector(0, 1);
float speed = 2;
float wiggleX = speed/10;
float wiggleY = speed/10;
float x1 = 200;
float y1 = 20;
float x2 = 200;
float y2 = 400;
int clickCounter =0;
float xOffset;
float yOffset;
//int numLines = 20;
float radPS;
float angle;
float prevAvg = 0;
boolean movie = false;
void xSetup() { // custom setup = runs once
rad = round(height/300.0);
speed = rad;
numPS = round(height/10.0);
angle = radians(360/float(numPS));
radPS = height/4;
easing = 0.05;
ps =new ParticleSystem[numPS];
for ( int i = 0; i<ps.length; i++) {
float xTemp = width/2 + cos(angle*i)*radPS;
float yTemp = height/2 + sin(angle*i)*radPS;
PVector wiggleInit = new PVector(wiggleX, wiggleY);
ps[i] = new ParticleSystem(new PVector(xTemp, yTemp), new PVector(0, 1).rotate(angle*i), speed, wiggleInit);
drawLaserLines = true;
}
}
void xDraw() { // custom draw = renders fooorever
//SETTINGS [change, but don't delete any]
credits = "elias.hodel"; // put your name[s] here!
myTextFont = "FreeSans.ttf"; // ie. "apple_ii.ttf";
myTextSize = height/3.5; // <- custom size
myTextLength = 1; // <- custom length for cuts
processType(); // <- function below (comment out if you prefer custom)
//background(0); // <- up to you if you want a background!
backgroundFade(20); // prefer fade?
//speed = map(easeAudio,0,maxAudio,.5,10);
//wiggleX = speed/10;
//wiggleY = speed/10;
println(avgAudio, easeAudio, avgAudio-easeAudio);
strokeWeight(1);
for (int i = 0; i< ps.length; i++) {
//ps[i].speed = speed+map(avgAudio-easeAudio,-avgAudio,avgAudio,0,1);
ps[i].speed = speed + (avgAudio-prevAvg)/5;
if (ps[i].speed>-speed && ps[i].speed<0) {
ps[i].speed = -speed;
} else if (ps[i].speed< speed && ps[i].speed >=0) {
ps[i].speed = speed;
}
ps[i].dir.set(new PVector(0, 1).rotate(angle*i+radians(map(avgAudio, 0, easeAudio, 0, -25))));
//ps[i].run(lines);
ps[i].run();
if (frameCount%10== 0 || avgAudio>prevAvg*2) {
ps[i].addParticle();
}
}
pushMatrix(); // only adjusts translate/scale within matrix
translate(width/2, height/2, 0); // suggestion to draw from center out
rotate(radians(-frameCount*1)); // changed from 2 = slow = better for laser keep up
//scale(.3);
strokeWeight(1.5);
if (pointPaths != null) { // only draw if points ready
//noFill(); // optional..
for (int i = 0; i < pointPaths.length; i++) {
//noFill();
stroke(255); // optional...
//fill(255); // optional...
xbeginShape();
for (int j=0; j < pointPaths[i].length; j++) {
xvertex(pointPaths[i][j].x, pointPaths[i][j].y); // try other shapes
// [i] refers to which character, [j] refers to which point in that character
}
xendShape();
}
}
popMatrix();
prevAvg = avgAudio;
//if (movie) {
//saveFrame("movie/output#####.png");
//}
}
/*---- YOUR CUSTOM CODE ABOVE ------------------------*/
/***** DON'T EDIT BELOW *******************************/