Skip to content

Instantly share code, notes, and snippets.

@pzp1997
Last active August 29, 2015 14:15
Show Gist options
  • Save pzp1997/14222a996e4e5aafa8ad to your computer and use it in GitHub Desktop.
Save pzp1997/14222a996e4e5aafa8ad to your computer and use it in GitHub Desktop.
When you click and hold down on a ball, it will vibrate.
// Array to hold ball objects
Ball[] balls = new Ball[int(random(8, 18))];
void setup() {
size(600, 600);
noStroke();
// Creates balls with random properties
for (int i = 0; i < balls.length; i++) {
balls[i] = new Ball(random(width), random(height), int(random(80, 120)), random(1, 5), color(random(255), random(255), random(255)));
}
}
void draw() {
background(0);
cursor(ARROW); // changes how the mouse looks
// iterates through the array of balls and executes
// the code in the for loop for each ball
for (Ball ball : balls) {
// checks if mouse is over ball (see how it works inside Ball class)
if (ball.hover()) {
cursor(HAND);
if (mousePressed) {
ball.x = mouseX + random(-ball.intense, ball.intense);
ball.y = mouseY + random(-ball.intense, ball.intense);
}
}
ball.display();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment