-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCollisionAnimation.pde
More file actions
81 lines (70 loc) · 2.42 KB
/
CollisionAnimation.pde
File metadata and controls
81 lines (70 loc) · 2.42 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
class CollisionAnimation {
float x, y; // Position of the animation
float size; // Current size of the animation
float maxSize; // Maximum size the animation will reach
float speed; // How fast the animation expands
float alpha; // Current transparency
color animColor; // Color of the animation
boolean active; // Whether the animation is currently playing
// Multiple circle properties
static final int NUM_CIRCLES = 3; // Number of concentric circles
float[] circleSizes; // Current sizes of each circle
float[] circleSpeeds; // Speeds for each circle
float[] circleAlphas; // Alpha values for each circle
CollisionAnimation(float x, float y, color animColor) {
this.x = x;
this.y = y;
this.animColor = animColor;
this.size = 0;
this.maxSize = 200;
this.speed = 4;
this.alpha = 255;
this.active = true;
// Initialize multiple circles
circleSizes = new float[NUM_CIRCLES];
circleSpeeds = new float[NUM_CIRCLES];
circleAlphas = new float[NUM_CIRCLES];
// Set different speeds and starting sizes for each circle
for (int i = 0; i < NUM_CIRCLES; i++) {
circleSizes[i] = 0;
circleSpeeds[i] = speed * (1 + i * 0.5); // Each circle moves faster
circleAlphas[i] = 255;
}
}
void update() {
if (!active) return;
// Update each circle
for (int i = 0; i < NUM_CIRCLES; i++) {
circleSizes[i] += circleSpeeds[i];
circleAlphas[i] = map(circleSizes[i], 0, maxSize, 255, 0);
}
// Check if all circles are done
boolean allDone = true;
for (int i = 0; i < NUM_CIRCLES; i++) {
if (circleSizes[i] < maxSize) {
allDone = false;
break;
}
}
if (allDone) {
active = false;
}
}
void draw() {
if (!active) return;
// Draw each circle
for (int i = 0; i < NUM_CIRCLES; i++) {
float strokeWeight = 4 - (i * 1.5); // Thinner strokes for outer circles
float alphaMultiplier = 1.0 - (i * 0.2); // Less alpha for outer circles
// Draw outer glow
noFill();
stroke(255, circleAlphas[i] * 0.5 * alphaMultiplier);
strokeWeight(strokeWeight);
circle(x, y, circleSizes[i]);
// Draw inner circle
stroke(255, circleAlphas[i] * alphaMultiplier);
strokeWeight(strokeWeight * 0.5);
circle(x, y, circleSizes[i] * 0.8);
}
}
}