xxxxxxxxxx
119
var lineX = 0;
var lineY = 0;
var loops = 1000;
var lineX2 = 0;
var lineY2 = 0;
var loops2 = 1000;
var x = 600;
var y = 300;
let der = 0;
var ran=[10,20];
var move = 0;
var x2 = 200;
var y2 = 500;
let der2 = 0;
function setup() {
createCanvas(1000, 1000);
background(200);
}
function draw() {
frameRate(60);
background(200, 200, 200, 0.1);
cubeThing();
lineX = 0;
lineY = 0;
loops = 100;
lineX2 = 0;
lineY2 = 0;
loops2 = 100;
line(lineX, lineY, lineX + 1000, lineY);
while (loops > 0) {
line(lineX, lineY, lineX + 1000, lineY);
lineY = lineY + 20;
loops = loops - 1;
}
line(lineX2, lineY2, lineX2, lineY2 + 1000);
while (loops2 > 0) {
line(lineX2, lineY2, lineX2, lineY2 + 1000);
lineX2 = lineX2 + 20;
loops2 = loops2 - 1;
}
move = random(ran);
der = int(random(4));
if (der === 0) {
x = x + move; //right
} else if (der === 1) {
x = x - move; //left
} else if (der === 2) {
y = y + move; //down
} else {
y = y - move; //up
}
if (y > 1000) {
y = 0;
} else if (y < -10) {
y = 1000;
} else if (x > 1000) {
x = 0;
} else if (x < -10) {
x = 1000;
}
der2 = int(random(4));
if (der2 === 0) {
x2 = x2 + move; //right
} else if (der2 === 1) {
x2 = x2 - move; //left
} else if (der2 === 2) {
y2 = y2 + move; //down
} else {
y2 = y2 - move; //up
}
if (y2 > 1000) {
y2 = 0;
} else if (y2 < -10) {
y2 = 1000;
} else if (x2 > 1000) {
x2 = 0;
} else if (x2 < -10) {
x2 = 1000;
}
}
function cubeThing() {
fill("red");
rect(x, y, 10, 10);
fill("white");
rect(x + 5, y + 3, 5, 2.5);
fill("blue");
rect(x2, y2, 10, 10);
fill("white");
rect(x2 + 5, y2 + 3, 5, 2.5);
}
var m = 200;
function keyPressed(){
background(m,m,m);
stroke("black");
lineX = 0;
lineY = 0;
loops = 100;
lineX2 = 0;
lineY2 = 0;
loops2 = 100;
line(lineX, lineY, lineX + 1000, lineY);
while (loops > 0) {
line(lineX, lineY, lineX + 1000, lineY);
lineY = lineY + 20;
loops = loops - 1;
}
line(lineX2, lineY2, lineX2, lineY2 + 1000);
while (loops2 > 0) {
line(lineX2, lineY2, lineX2, lineY2 + 1000);
lineX2 = lineX2 + 20;
loops2 = loops2 - 1;
}
}