xxxxxxxxxx
103
let pos1;
let pos2;
let vel1;
let vel2;
let col1;
let col2;
let changingcolor1;
let colchangespeed1 = 1;
const size = 25;
let s = 0.25;
let ticks = 2;
function setup() {
createCanvas(800, 800);
background(220);
col1 = color(250, 1, 1)
changingColor = "r";
//Start box1 at 0 + offset 0 + offset
pos1 = createVector(size/2, size/2)
vel1 = createVector(15.1 * s, 0.5 * s);
pos2 = createVector(width - size/2, height - size/2)
vel2 = createVector(-0.5 * s, -15.1 * s);
rectMode(CENTER)
// frameRate(5)
}
function draw() {
// background(220);
for (let i = 0; i < ticks; i++) {
noStroke();
// stroke(color(("2C2C2C")))
// fill(col1)
fill(28)
rect(pos1.x, pos1.y, size, size);
// noFill()
ellipse(pos2.x, pos2.y, size, size);
// if (changingColor == "r") {
// col1 = color(red(col1) + colchangespeed1, green(col1), blue(col1));
// if (red(col1) > 254 || red(col1) < 1) {
// col1 = color(253, green(col1), blue(col1))
// changingColor = "g";
// }
// }
// if (changingColor == "g") {
// col1 = color(red(col1), green(col1) + colchangespeed1, blue(col1));
// if (green(col1) > 254 || green(col1) < 1) {
// col1 = color(red(col1), 253, blue(col1))
// changingColor = "b";
// }
// }
// if (changingColor == "b") {
// col1 = color(red(col1), green(col1), blue(col1) + colchangespeed1);
// if (blue(col1) > 254 || blue(col1) < 1) {
// col1 = color(red(col1), green(col1), 253)
// changingColor = "r";
// colchangespeed1 = -colchangespeed1;
// }
// }
// console.log(changingColor)
// // console.log(red(col1))
// console.log(green(col1))
// // console.log(blue(col1))
pos1.add(vel1)
pos2.add(vel2)
if (pos1.x > width || pos1.x < 0) {
vel1 = createVector(-vel1.x, vel1.y);
}
if (pos1.y > height || pos1.y < 0) {
vel1 = createVector(vel1.x, -vel1.y);
}
if (pos2.x > width || pos2.x < 0) {
vel2 = createVector(-vel2.x, vel2.y);
}
if (pos2.y > height || pos2.y < 0) {
vel2 = createVector(vel2.x, -vel2.y);
}
}
}