Datasheet
The Ring class has a respawn() function which computes a new particle's intensity and hue
based on the speed and angle of mouse motion. As parameters, it takes the X and Y
coordinates for a previous and a new mouse position.
class Ring
{
float x, y, size, intensity, hue;
void respawn(float x1, float y1, float x2, float y2)
{
// Start at the newer mouse position
x = x2;
y = y2;
// Intensity is just the distance between mouse points
intensity = dist(x1, y1, x2, y2);
// Hue is the angle of mouse movement, scaled from -PI..PI to 0..100
hue = map(atan2(y2 - y1, x2 - x1), -PI, PI, 0, 100);
// Default size is based on the screen size
size = height * 0.1;
}
void draw()
{
// Particles fade each frame
intensity *= 0.95;
// They grow at a rate based on their intensity
size += height * intensity * 0.01;
// If the particle is still alive, draw it
if (intensity >= 1) {
blendMode(ADD);
tint(hue, 50, intensity);
image(texture, x - size/2, y - size/2, size, size);
}
}
};
Now we need to define the rest of the program to drive a system of these Ring particles.
Aside from the Ring class, this is what the rest of our program looks like:
OPC opc;
PImage texture;
Ring rings[];
float smoothX, smoothY;
boolean f = false;
void setup()
© Adafruit Industries https://learn.adafruit.com/led-art-with-fadecandy Page 54 of 60










