-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPsychicLines.pde
189 lines (159 loc) · 5.04 KB
/
PsychicLines.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
/* Animation réalisé par Benbb96 */
final int NB = 1000; // Nombre de Moving Lines
MovingLine[] lines = new MovingLine[NB];
MyColor myColor = new MyColor();
float rotation = 0;
void setup() {
size(1280, 720); // HD
// Initialisation de toutes les Moving Lines
for (int i = 0; i < NB; i++) {
//lines[i] = new MovingLine(new PVector((width/MovingLine.SIZE) /2, (height/MovingLine.SIZE) /2 +0.5), new PVector(1, 0));
lines[i] = new MovingLine(new PVector(-0.5,0), new PVector(1, 0));
}
}
void draw() {
myColor.update();
background(color(255 - myColor.R, 255 - myColor.G, 255 - myColor.B));
translate(width/2, height/2); // Fixe le plan au milieu
if (frameCount > 1996) rotate(rotation += 0.003);
else if (frameCount > 1789) rotate(rotation += 0.0016);
else if (frameCount > 1444) rotate(rotation += 0.0004);
// Affichage des Moving Lines
for (int i = 0; i < NB; i++) {
lines[i].show();
}
// Lancer une animation aléatoire à intervalle régulier.
if (frameCount % 100 == 0) {
for (int i = 0; i < NB; i++) {
lines[i].setAnimation(int(random(0,10)));
}
}
}
void mousePressed()
{
myColor.init(); // Réinitialise les couleurs
}
class MovingLine {
PVector a, b, t, initialT;
float r = 0;
float initialR = 0;
float speed = 0.004; // ==> Jouer sur la vitesse
int animation = 0;
boolean ready = true;
static final int SIZE = 100; // ==> Jouer sur la taille
int weight = int(random(4,10));
MovingLine(PVector a, PVector b) {
t = a;
initialT = new PVector();
this.a = new PVector(0,0);
this.b = b;
}
void show() {
stroke(color(myColor.R, myColor.G, myColor.B, 100));
strokeWeight(weight);
switch (animation) {
// Rotations dans le sens horaire
case 1 :
case 3 :
if (r < initialR + HALF_PI) r += speed / 0.65;
else endAnimation(true);
break;
// Rotations dans le sens anti-horaire
case 2 :
case 4 :
if (r > initialR - HALF_PI) r -= speed / 0.65;
else endAnimation(true);
break;
// Translations
case 5 :
if ( (b.x + b.y) * (t.x + t.y) < (b.x + b.y) * ( (initialT.x + initialT.y) + (b.x + b.y) ) ) {
t.set(t.x + b.x * speed, t.y + b.y * speed);
}
else endAnimation(false);
break;
case 6 :
if ( (b.x + b.y) * (t.x + t.y) > (b.x + b.y) * ( (initialT.x + initialT.y) - (b.x + b.y) ) ) {
t.set(t.x - b.x * speed, t.y - b.y * speed);
}
else endAnimation(false);
break;
// Pour tout autre nombre : aucun mouvement et près à recevoir une nouvelle animation
default :
animation = 0;
ready = true;
}
pushMatrix();
translate(t.x * SIZE, t.y * SIZE);
rotate(r);
line(a.x * SIZE , a.y * SIZE, b.x * SIZE, b.y * SIZE);
popMatrix();
}
// Prépare et lance l'animation passée en paramètre
void setAnimation(int n) {
if (ready) {
ready = false;
animation = n;
if (n == 3 || n == 4) { // Permutation sur la translation pour faire la rotation sur l'autre point
t.add(b);
a.set(-b.x, -b.y);
b.set(0,0); // b devient le point de pivot
} else if (n == 5 || n == 6) {
initialT.set(t.x, t.y);
}
}
}
// Restaure les paramètres comme il faut et en fonction de si c'est une rotation ou une translation
void endAnimation(boolean rotation) {
initialR = 0;
initialT.set(t.x, t.y);
r = 0;
if (rotation) replace();
animation = 0;
ready = true;
}
// Permet de replacer les points correctement en fonction de la rotation qui a eu lieu
void replace() {
if (animation == 1 || animation == 3) { // Rotation horaire
if (a.x == 0 && a.y == 0) { // Le point de pivot est a
b.set(-b.y,b.x);
} else { // Le point de pivot est b
t.set(t.x - a.y, t.y + a.x);
b.set(a.y, -a.x);
a.set(0,0);
}
} else { // Rotation anti-horaire
if (a.x == 0 && a.y == 0) {
b.set(b.y,-b.x);
} else {
t.set(t.x + a.y, t.y - a.x);
b.set(-a.y, a.x);
a.set(0,0);
}
}
} //<>//
}
class MyColor
{
float R, G, B, Rspeed, Gspeed, Bspeed;
final static float minSpeed = .7;
final static float maxSpeed = 1.5;
MyColor()
{
init();
}
public void init()
{
R = random(255);
G = random(255);
B = random(255);
Rspeed = (random(1) > .5 ? 1 : -1) * random(minSpeed, maxSpeed);
Gspeed = (random(1) > .5 ? 1 : -1) * random(minSpeed, maxSpeed);
Bspeed = (random(1) > .5 ? 1 : -1) * random(minSpeed, maxSpeed);
}
public void update()
{
Rspeed = ((R += Rspeed) > 255 || (R < 0)) ? -Rspeed : Rspeed;
Gspeed = ((G += Gspeed) > 255 || (G < 0)) ? -Gspeed : Gspeed;
Bspeed = ((B += Bspeed) > 255 || (B < 0)) ? -Bspeed : Bspeed;
}
}