xxxxxxxxxx
113
let t = 0;
let x = 0;
let y = 0;
let r = 0;
//let xpos, ypos,diam,speedx,speedy;
let xpos1;
let xpos2;
let xpos3;
let xpos4;
let thin = 8;
let thick = 36;
//if, else, else if, millis
function setup() {
createCanvas(400, 400);
noStroke();
rectMode(CENTER);
xpos1 = width / 2;
xpos2 = width / 2;
xpos3 = width / 2;
xpos4 = width / 2;
xpos5 = width/2;
xpos6 = width/2;
/* xpos = 40;
ypos = 40;
diam = 60;
speedx = 5;
speedy = 5;*/
//fill(40, 200, 40);
//frameRate(10);
}
function draw() {
push();
background(30,60,80,20);
//ellipses
x = width/2;
y = height/2;
const myX = x + 20 * cos(2 * PI * t);
const myY = y + 20 * sin(2 * PI * t);
//
const myX2 = x + 40*cos(2*PI*t);
const myY2 = y + 40*sin(2*PI*t);
//
const myX3 = x + 60*cos(2*PI*t);
const myY3 = y + 60*sin(2*PI*t);
//const myX4 = x + 60*cos(2*PI*t);
//const myY4 = y + 60*cos(2*PI*t);
fill(40, 200, 40);
ellipse(myX, myY, 10);
ellipse(myX2,myY2,10);
ellipse(myX3,myY3,10);
//circle(myX4, myY4,10);
t = t+0.01;
pop();
//
let mx = mouseX*0.5- width/6;
fill(102);
rect(xpos2, 0, thick, height / 2);
fill(204);
rect(xpos1, 0, thin, height / 2);
fill(102);
rect(xpos4, height / 2, thick, height / 2);
fill(204);
rect(xpos3, height / 2, thin, height / 2);
xpos1 += mx / 16;
xpos2 += mx / 24;
xpos3 -= mx / 16;
xpos4 -= mx / 24;
if (xpos1 < -thin) {
xpos1 = width;
}
else if(xpos1 > width){
xpos1 = -thin;
}
if (xpos2 < -thick) {
xpos2 = width;
}
if (xpos2 > width) {
xpos2 = -thick;
}
if (xpos3 < -thin) {
xpos3 = width;
}
if (xpos3 > width) {
xpos3 = -thin;
}
if (xpos4 < -thick) {
xpos4 = width;
}
if (xpos4 > width) {
xpos4 = -thick;
}
//bounce
/*push();
fill(255,255,0);
circle(xpos,ypos,diam);
xpos+= speedx;
ypos+= speedy;
if (xpos>=width-diam/2 || xpos<= 0 +diam/2){
speedx *= -1;
}
else if(ypos>=height-diam/2 || ypos<= 0 +diam/2){
speedy*= -1;
}
pop();*/
}