xxxxxxxxxx
26
let loc; //位置ベクトル
let vel; //速度ベクトル
function setup() {
createCanvas(windowWidth, windowHeight);
frameRate(60);
loc = createVector(width / 2, height / 2);
vel = createVector(random(-10, 10), random(-10, 10));
}
function draw() {
background(63);
fill(31, 127, 255);
noStroke();
circle(loc.x, loc.y, 40);
loc.add(vel);
if (loc.x < 0 || loc.x > width) {
//左右の壁
vel.x = vel.x * -1;
}
if (loc.y < 0 || loc.y > height) {
//上下の壁
vel.y = vel.y * -1;
}
}