-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParticleSystem.pde
More file actions
126 lines (96 loc) · 2.37 KB
/
Copy pathParticleSystem.pde
File metadata and controls
126 lines (96 loc) · 2.37 KB
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
public class ParticleSystem{
private color endColor = color(100,100,100,HSB);
private color startColor= color(100,100,100,HSB);
private float saturation = 0;
private ArrayList<Particle> particles = new ArrayList<Particle>();
public void update(){
Iterator<Particle> i = particles.iterator();
while (i.hasNext()) {
Particle p = i.next();
// Remove any particles outside of the screen
if (p.pos.x > width /*|| p.pos.x < 0*/) {
i.remove();
continue;
} else if (p.pos.y > height /*|| p.pos.y < 0*/) {
i.remove();
continue;
}
// Apply gravity
p.applyForce(PVector.random2D());
// Move particle position
p.move();
// Remove dead particles
if (p.isDead()) {
i.remove();
} else {
p.display();
}
}
}
public void addParticles(PVector position,int id) {
//int cor = int(random(8));
this.startColor = choseColor(id);
//cor = int(random(8));
this.endColor = choseColor(id+20);
for (int i = 0; i < numberOfParticles; i++) {
float amount = random(1);
color col = lerpColor(this.startColor, this.endColor, amount);
col = color(hue(col),this.saturation,100);
//col = desaturate(col, this.saturation);
this.particles.add(new Particle(new PVector(position.x,position.y), col));
//println("HUE1",hue(col));
//println("SAT1",saturation(col));
//println("BRI1",brightness(col));
}
}
public color choseColor(int id){
color cor = color(0,0,0,HSB);
switch(id){
case 1:
cor = red1;
break;
case 21:
cor = red2;
break;
case -1:
cor = red1;
break;
case 19:
cor = red2;
break;
case -2:
cor = blu1;
break;
case 18:
cor = blu2;
break;
case 2:
cor = blu2;
break;
case 22:
cor = purple1;
break;
case 3:
cor = green;
break;
case 23:
cor = yellow2;
break;
case -3:
cor = red1;
break;
case 17:
cor = orange;
break;
}
return cor;
}
public color desaturate(color col, float factor) {
float sat = saturation(col) * factor;
return color(
hue(col),
sat,
brightness(col)
);
}
}