xxxxxxxxxx
37
// Code 2 keyframe A-B-A by Xin Xin, inspired by Dan Shiffman's The Bouncy Ball in p5.js tutorial
let x = 50;
let speed = 1;
function setup() {
createCanvas(400, 400);
textAlign(CENTER, CENTER);
}
function draw() {
background(0);
strokeWeight(1);
stroke(100);
noFill();
ellipse(50, 200, 100, 100);
ellipse(350, 200, 100, 100);
stroke(255);
strokeWeight(2);
ellipse(x, 200, 100, 100);
noStroke();
fill(100);
text("keyframe A", 50, 200);
text("keyframe B", 350, 200);
x = x + speed;
if (x > width - 50) {
speed = -1;
} else if (x == 50) {
speed = 1;
}
}