xxxxxxxxxx
24
var angle = 0; // initialize angle variable
var scalar = 300; // set the radius of circle
var startX = 0; // set the x-coordinate for the circle center
var startY = 400; // set the y-coordinate for the circle center
var x = 0;
function setup() {
createCanvas(400, 400);
background(255);
angleMode(DEGREES); // change the angle mode from radians to degrees
}
function draw() {
// var x = startX + scalar * cos(angle);
var y = startY - scalar * abs(sin(angle)); // make sin() always positive with abs()
ellipse(x, y, 8);
angle++; // increment angle for the next frame
x += 0.5; // increment the x-coordiate for the next frame
if(angle%180 == 0) {
scalar *= 0.7; // slowly decrease the value of scalar after each bounce
}
}