xxxxxxxxxx
let ball = {
x: 0,
y: 0,
radius: 5,
speed: 1
}
function setup() {
createCanvas(windowWidth, windowHeight);
frameRate(60);
//初期設定
ball.x = random(width);
ball.y = random(height);
ball.radius = 4;
ball.speed = 1000;
background(0);
}
function draw() {
//くりかえす(スピードアップ)
for (let i = 0; i < ball.speed; i++) {
//移動
ball.x += random(-1, 1);
ball.y += random(-1, 1);
//画面の端にきたら反対側へ
if (ball.x > width) {
ball.x = 0;
}
if (ball.x < 0) {
ball.x = width;
}
if (ball.y > height) {
ball.y = 0;
}
if (ball.y < 0) {
ball.y = height;
}
//円を描く
noStroke();
fill(255, 3);
circle(ball.x, ball.y, ball.radius);
}
}