xxxxxxxxxx
circleArray = []
const step = 3
let direction1 = 'downright'
let direction2 = 'downleft'
function setup() {
createCanvas(600, 600);
background('grey');
frameRate(20)
colours = [
"#fe4365",
"#fc9d9a",
"#f9cdad",
"#c8c8a9",
"#83af9b"
]
for (let i = 0; i < 1000; i++) {
let c = {
x: random(0, 600),
y: random(0, 600),
colour: random(colours)
}
circleArray.push(c)
}
}
function draw() {
drawMultipleWalkers()
moveMultipleWalkerLeft()
//if frame count is a multiple of 30
// change direction
if ((frameCount % 10) === 0) {
changeDirectionLeft()
}
}
function drawMultipleWalkers() {
for (let c of circleArray) {
circle(c.x, c.y, 10);
fill(c.colour);
// noStroke();
}
}
function mousePressed() {
changeDirectionRight()
}
function changeDirectionRight() {
if (direction1 === 'downright') {
direction1 = 'upright'
} else {
direction1 = 'downright'
}
}
function changeDirectionLeft() {
if (direction2 === 'downleft') {
direction2 = 'upleft'
} else {
direction2 = 'downleft'
}
}
function moveMultipleWalkerRight() {
for (let c of circleArray) {
if (direction1 === 'downright') {
c.x += step
c.y += step
} else {
c.x += step
c.y += -step
}
}
}
function moveMultipleWalkerLeft() {
for (let c of circleArray) {
if (direction2 === 'downleft') {
c.x += -step
c.y += step
} else {
c.x += -step
c.y += -step
}
}
}
// function moveMultipleWalker() {
// for (let c of circleArray) {
// if (c.x > 600 || c.y < 0) {
// c.x = random(0, 600)
// c.y = random(0, 600)
// } else {
// c.x += step
// c.y += -step
// }
// // c.x += random(-step, step)
// // c.y += random(-step, step)
// }
// }
// make direction that goes right or down
// frame count
// for the first five frames go up
// for the next five go down
// or
// variable that represents the direction, right or down, boolean
// move all the circles according to the direction