xxxxxxxxxx
// ArrayList, array, particle, particle system, PImage, cos
// Two sided particles made from the letters that spell "letters"
PImage[] letters = new PImage[10];
ArrayList<Particle> particles = new ArrayList<Particle>();
int index = 0;
void setup() {
size(450, 600);
imageMode(CENTER);
for (int i = 0; i < 10; i++) {
letters[i] = loadImage("letter" + i + ".png");
}
}
void draw() {
//fill(245);
//stroke(0);
background(245);
//rect(0,0, width, height);
if (frameCount % 5 == 0) {
particles.add(new Particle(letters[index], letters[index+1]));
index += 2;
if (index > 8) index = 0;
}
for (int i = particles.size ()-1; i >= 0; i--) {
Particle p = particles.get(i);
p.run();
if (p.pos.y > height + 50) particles.remove(i);
}
}
// class %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
class Particle {
PVector pos, vel;
float incr1, incr2, h;
PImage img0, img1;
Particle(PImage l0, PImage l1) {
img0 = l0;
img1 = l1;
vel = new PVector(random(-.5, .5), random(.5, 1.5));
pos = new PVector(random(50, width-50), -40);
incr1 = random(.01, .02);
incr2 = random(-.02, .02);
}
void run() {
pos.add(vel);
if (pos.y > height-20) {
vel.y = .025;
vel.x = 0;
}
h = cos(frameCount * incr1) * 50;
pushMatrix();
translate(pos.x, pos.y);
rotate(cos(frameCount * incr2));
if (h > 0) image(img0, 0, 0, 30, h);
else image(img1, 0, 0, 30, h);
popMatrix();
}
}