xxxxxxxxxx
31
let distances = [];
let maxDistance;
let spacer;
function setup() {
createCanvas(400 , 400);
maxDistance = dist(width / 2, height / 2, width, height);
for (let potatoHead = 0; potatoHead < width; potatoHead++) {
distances[potatoHead] = []; // create nested array
for (let pickle = 0; pickle < height; pickle++) {
let distance = dist(width / 2, height / 2, potatoHead, pickle);
distances[potatoHead][pickle] = (distance / maxDistance) * 255;
}
}
spacer = 8;
noLoop(); // Run once and stop
}
function draw() {
background(0);
// This embedded loop skips over values in the arrays based on
// the spacer variable, so there are more values in the array
// than are drawn here. Change the value of the spacer variable
// to change the density of the points
for (let x = 0; x < width; x += spacer) {
for (let y = 0; y < height; y += spacer) {
stroke(distances[x][y]);
point(x + spacer / 2, y + spacer / 2);
}
}
}