xxxxxxxxxx
let xPos, yPos, xVel, yVel, xAcc, yAcc
function setup() {
createCanvas(500, 500);
xPos = yPos = width / 2
xVel = 1
yVel = 1
xAcc = 0
yAcc = 0
}
function draw() {
fill(34, 155, 215, 50); // r,g,b,a
rect(0, 0, width, height)
update()
}
function update(){
move()
checkBoundary()
display()
}
function move() {
xAcc += random(-0.001, 0.001)
yAcc += random(-0.001, 0.001)
xVel += xAcc
yVel += yAcc
xPos += xVel
yPos += yVel
}
function checkBoundry() {
if ((xPos > width) || (xPos < 0)) {
// xPos = 0
xVel *= -1
}
if ((yPos > height) || (yPos < 0)) {
// yPos = 0
yVel *= -1
}
}
function display() {
let r = sin(millis() / 100) * 100
fill(255,0,255)
circle(xPos, yPos, r); // x,y,r
}