xxxxxxxxxx
int NUM = 100;
Particle[] myParticle = new Particle[NUM];
void setup(){
size(500,500,P2D);
frameRate(350);
noStroke();
for(int i = 0; i < NUM; i++){
myParticle[i] = new Particle(random(8,32));
}
}
void draw(){
background(random(255, 255, 90));
for(int i = 0; i < NUM; i++){
myParticle[i].draw();
}
}
class Particle{
color col;
float diameter;
PVector location;
PVector velocity;
Particle(float _diameter){
diameter = _diameter;
location = new PVector(random(0,width),random(0,height));
velocity = new PVector(random(-4,4),random(-4,4));
col = color(random(250),random(250),random(250));
}
void draw(){
fill(col);
ellipse(location.x, location.y, diameter+50, diameter+50);
rectMode(CENTER);
rect(location.x, location.y-30, diameter, diameter);
rectMode(CENTER);
rect(location.x, location.y-50, diameter-20, diameter);
location.add(velocity);
if((location.x < 0) || (location.x > width)){
velocity.x = velocity.x * -1;
}
if((location.y < 0) || (location.y > height)){
velocity.y = velocity.y * -1;
}
}
}
void mousePressed() {
// Save the canvas as an image when the mouse is pressed
String filename = "xmasbaubles.png";
save(filename);
println("Image saved as: " + filename);
}