SketchBook

カオス

var rad = 50;
var xpos, ypos;

var xspeed = 10;
var yspeed = 10;

var xdirection = 1;
var ydirection = 1;

function setup() {
createCanvas(windowWidth,
windowHeight);
noStroke();
ellipseMode(RADIUS);

xpos = width / 2;
ypos = height / 2;
}

function draw() {
background(234, 234, 234);
fill(random(0,255),random(0,255),random(0,255),random(0,255));

xpos = xpos + xspeed * xdirection;
ypos = ypos + yspeed * ydirection;

if (xpos > width - rad || xpos < rad) {
xdirection *= -1;
}

if (ypos > height - rad || ypos < rad) {
ydirection *= -1;
}


ellipse(xpos, ypos, random(50,100), random(50,100));
rect(ypos, xpos, random(50,100), random(50,100));
 ellipse(xpos, xpos, random(50,100), random(50,100));
rect(ypos, ypos, random(50,100), random(50,100))
}