Skip to content

Instantly share code, notes, and snippets.

@tado
Last active May 23, 2024 05:06
Show Gist options
  • Save tado/93720b49b7453d4f4fb383358f4051e2 to your computer and use it in GitHub Desktop.
Save tado/93720b49b7453d4f4fb383358f4051e2 to your computer and use it in GitHub Desktop.
p5.js Animation
function setup() {
createCanvas(windowWidth, windowHeight);
colorMode(HSB, 360, 100, 100, 100);
locationX = width / 2;
locationY = height / 2;
velocityX = random(-50, 50);
velocityY = random(-50, 50);
}
function draw() {
background(0);
noStroke();
fill(0, 100, 100, 100);
circle(locationX, locationY, 50);
locationX = locationX + velocityX;
locationY = locationY + velocityY;
if (locationX < 0 || locationX > width) {
velocityX = velocityX * -1;
}
if (locationY < 0 || locationY > height) {
velocityY = velocityY * -1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment