-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathParticle.pde
167 lines (128 loc) · 2.96 KB
/
Particle.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
class Particle {
PVector pos;
PVector speed;
PVector accel;
float rdmx, rdmy;
float stm;
float vibr;
float amp;
float angle;
float Aspeed;
float size;
float bsize;
float lifespan;
float lifespanspeed;
float mass;
float topSpeed;
color colorfig ;
color colorStroke;
float Bsize;
float hue, sat, bri;
int cantpoints;
Particle(PVector _pos,
float _topSpeed,
PVector _accel,
float _rdmx, float _rdmy,
float _amp,
float _size, float _bsize,
float _hue, float _sat, float _bri,
int _cantpoints,
float _lifespanspeed) {
mass = 1;
pos = _pos;
topSpeed = _topSpeed;
speed = new PVector(0, 0);
accel = _accel;
rdmx = _rdmx;
rdmy =_rdmy;
size = _size;
bsize = _bsize;
cantpoints = _cantpoints;
amp = _amp;
Aspeed = 0.05;
hue = _hue;
sat = _sat;
bri = _bri;
lifespanspeed = _lifespanspeed;
lifespan = 255;
stm = 8;
}
void run() {
display();
update();
}
void applyForce(PVector _f) {
_f.div(mass);
accel.add(_f);
}
void display() {
pushMatrix();
translate(pos.x, pos.y);
rotate(speed.heading());
SHSBA();
popMatrix();
}
void update() {
//applyForce(new PVector(map(mouseX,0,width,-0.5,0.5),map(mouseY,0,height,-0.5,0.5)));
//atractTomouse();
addRandom(rdmx, rdmy);
speed.add(accel);
speed.limit(5);
pos.add(speed);
//angular();
lifespan -=lifespanspeed;
}
void angular() {
angle+=Aspeed;
PVector oscilator = new PVector(sin(angle), cos(angle));
//oscilator.normalize();
oscilator.mult(amp);
pos.add(oscilator);
}
void atractTomouse() {
if (mousePressed) {
PVector mouse = new PVector (mouseX, mouseY);
PVector dir = PVector.sub(mouse, pos);
dir.normalize();
dir.mult(stm);
speed.add(dir);
}
}
boolean isDead() {
if (lifespan < 0) {
return true;
} else {
return false;
}
}
void SHSBA() {
strokeWeight(bsize);
stroke(hue, sat, bri/2, lifespan);
fill(hue, sat, bri, lifespan);
//star(0,0,size*2,size,15);
//ellipse(0, 0, size, size);
polygon(0,0,size,cantpoints);
}
void polygon(float x, float y, float radius, int npoints) {
if (npoints <= 1) {
ellipse(x, y, size, size);
}
else {
float angle = TWO_PI / npoints;
beginShape();
for (float a = 0; a < TWO_PI; a += angle) {
float sx = x + cos(a) * radius;
float sy = y + sin(a) * radius;
vertex(sx, sy);
}
endShape(CLOSE);
}
}
void addRandom(float _rdmx, float _rdmy) {
PVector rdm = PVector.random2D();
rdm.x = rdm.x * _rdmx;
rdm.y = rdm.y * _rdmy;
//rdm.normalize();
speed.add(rdm);
}
}