xxxxxxxxxx
33
const myShape = {
x: 200,
y: 200,
w: 50,
h: 50
}
function setup() {
createCanvas(400, 400);
rectMode(CENTER)
p5.tween.manager.addTween(myShape)
.addMotions([
{ key: 'x', target: 10 },
{ key: 'y', target: 10 },
], 1000)
.addMotions([
{ key: 'x', target: width - 10 },
{ key: 'y', target: height - 10 },
], 1000)
.addMotions([
{ key: 'x', target: 200 },
{ key: 'y', target: 200 },
], 500)
.startLoop()
}
function draw() {
background(220);
noStroke()
fill(255, 0, 0)
rect(myShape.x, myShape.y, myShape.w, myShape.h)
}