Interactive Art [Week 5] - Arrays
Week 5 - Arrays
For this project I wanted to create a random selector of the main characteristics of the ball, size, color, and "bounciness" that are pre-stored in the corresponding array.
I also wanted to use an array that "creates" more balls but I couldn't do it :( so it's only an infinite array that creates balls of the same characteristics but they can't move.
Code
PVector location;
PVector velocity;
PVector gravity;
int sizeR;
int colorR;
int speedR;
int[] sizes = { 50, 100, 150, 200, 250 };
int[] colors = { #FF0000, #00FF00, #0000FF, #FFFFFF};
float[] speeds = {-0.8, -0.7, -0.95};
ArrayList<PVector> clicks = new ArrayList();
void setup() {
size(500,500);
location = new PVector(100,100);
velocity = new PVector(1,5);
gravity = new PVector(0,0.8);
sizeR = (int) random(0, 5);
colorR = (int) random(0, 4);
speedR = (int) random(0, 3);
print(sizes[sizeR]);
print(speeds[speedR]);
}
void draw() {
background(0);
location.add(velocity);
velocity.add(gravity);
if ((location.x > 500-(sizes[sizeR])/2) || (location.x < (sizes[sizeR])/2 )) {
velocity.x = velocity.x * -1;
}
if (location.y > height) {
velocity.y = velocity.y * speeds[speedR];
location.y = height;
}
for( int i = 0; i < clicks.size(); i++){
ellipse(clicks.get(i).x, clicks.get(i).y, sizes[sizeR], sizes[sizeR]);
}
drawBall();
}
void drawBall(){
fill(colors[colorR]);
circle(location.x,location.y,sizes[sizeR]);
}
void mouseClicked() {
clicks.add( new PVector( mouseX, mouseY, millis() ) );
}
Comentarios
Publicar un comentario