Some P5 sketches I made.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

33 lines
527 B

ball = {
x: 100,
y: 100,
dx: -10,
dy: 10,
r : 80,
};
ball.update = function(){
this.y += this.dy;
this.x += ball.dx;
}
function setup() {
// put setup code here
createCanvas(400, 400);
frameRate(30);
}
function draw() {
// update code here
ball.dy -= (ball.y - height/2)/20;
ball.dx -= (ball.x - width/2)/20;
ball.update();
// put drawing code here
background(220);
stroke(0,0,255);
strokeWeight(4);
line(width/2, height/2, ball.x, ball.y);
noStroke();
ellipse(ball.x,ball.y,ball.r);
}