Last active
May 23, 2024 05:06
-
-
Save tado/93720b49b7453d4f4fb383358f4051e2 to your computer and use it in GitHub Desktop.
p5.js Animation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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