xxxxxxxxxx
40
let diameter; //直径
let position; //位置
let velocity; //速度
function setup() {
createCanvas(windowWidth, windowHeight);
diameter = 100.0;
position = createVector(width / 2, height / 2);
velocity = createVector(random(-2, 2), random(2, 2));
background(0);
}
function draw() {
background(0, 100);
move(); //移動
bounce(); //壁でバウンド
display(); //表示
}
function move() {
position.add(velocity);
}
function bounce() {
if (position.x < diameter / 2 || position.x > width - diameter / 2) {
velocity.x *= -1;
}
if (position.y < diameter / 2 || position.y > height - diameter / 2) {
velocity.y *= -1;
}
}
function display() {
noStroke();
fill(255, 63);
let currentDiameter = sin(frameCount * 0.1) * (diameter / 4) + diameter;
circle(position.x, position.y, currentDiameter);
fill(255, 31, 31, 190);
circle(position.x, position.y, diameter / 6.0);
}