xxxxxxxxxx
80
let robotarm1;
let robotarm2;
let robotarm3;
let robotarm4;
const segLen = 12;
const numSegs = 35;
let followMouse = false;
let pos;
let vel;
let noisyBall = false;
let noiseVal = 0.15;
function setup() {
createCanvas(700, 700);
robotarm1 = new RobotArm(width / 2, height, numSegs, segLen, 0);
robotarm2 = new RobotArm(width / 2, 0, numSegs, segLen, 0);
robotarm3 = new RobotArm(0, height / 2, numSegs, segLen, 0);
robotarm4 = new RobotArm(width, height / 2, numSegs, segLen, 0);
pos = createVector(width/2, height/2);
vel = createVector(random(2), random(2));
vel.mult(3);
}
function draw() {
background(51);
let followX;
let followY;
if (followMouse) {
followX = mouseX;
followY = mouseY;
} else {
followX = pos.x;
followY = pos.y;
pos.add(vel);
noStroke();
fill(255, 255, 255);
ellipse(pos.x, pos.y, 32, 32);
if (pos.x > width || pos.x < 0) {
vel.x *= -1;
}
if (pos.y > height || pos.y < 0) {
vel.y *= -1;
}
if (noisyBall) {
let choice = int(random(4));
if (choice == 0) {
vel.x += noiseVal;
vel.y += noiseVal;
} else if (choice == 1) {
vel.x -= noiseVal;
vel.y += noiseVal;
} else if (choice == 2) {
vel.x += noiseVal;
vel.y -= noiseVal;
} else {
vel.x -= noiseVal;
vel.y -= noiseVal;
}
}
}
robotarm1.update(followX, followY);
robotarm2.update(followX, followY);
robotarm3.update(followX, followY);
robotarm4.update(followX, followY);
robotarm1.show();
robotarm2.show();
robotarm3.show();
robotarm4.show();
}