xxxxxxxxxx
// Number of strokes to draw per frame
var strokesPerFrame = 6;
// Autonomous Agent 0
var x;
var y;
var xSpeed1;
var ySpeed1;
// Autonomous Agent 1
var x1;
var y1;
var x1Speed;
var y1Speed;
// Track hue
var h;
var hueSpeed;
function initSettings() {
x = random(2, width - 3);
y = random(2, height - 3);
xSpeed = random(0.8, 1);
ySpeed = random(0.8, 1);
x1Speed = random(0.8, 1);
y1Speed = random(0.8, 1);
x1 = random(2, width - 3);
y1 = random(2, height - 3);
h = random(360);
hueSpeed = random(0.25, 1);
}
//Setting up canvas and background
function setup() {
createCanvas(600, 600);
background(250);
colorMode(HSB);
initSettings();
}
//Random Draw
function draw() {
for (var i = 0; i < strokesPerFrame; i++)
// Update color
stroke(h, 80, 100, 0.1);
h = (h + hueSpeed) % 360;
// Draw line
line(x, y, x1, y1);
// Update positions
x += xSpeed;
y += ySpeed;
x1 += x1Speed;
y1 += y1Speed;
// Bounce autonomous agents
if (x >= width || x <= 0) {
xSpeed *= -1;
}
if (y >= height || y <= 0) {
ySpeed *= -1;
}
if (x1 >= width || x1 <= 0) {
x1Speed *= -1;
}
if (y1 >= height || y1 <= 0) {
y1Speed *= -1;
}
}