xxxxxxxxxx
78
let debug = 0;
function setup() {
createCanvas(720, 720);
noLoop();
}
function draw() {
background(255);
doLines();
}
function mousePressed() {
background(255);
doLines();
}
function doLines() {
const iterations = 56;
const spacing = 12;
const len = 8;
const randompoints = int(random(1, 7));
let distanceThreshold = 100;
const pointsx = [];
const pointsy = [];
for (let i = 0; i < randompoints; i++) {
pointsx[i] = random(0, 720);
pointsy[i] = random(0, 720);
if (debug == 1 || debug == 4) {
stroke('red');
ellipse(pointsx[i], pointsy[i], distanceThreshold, distanceThreshold);
stroke(0);
}
}
for (let i = 0; i < iterations; i++) {
for (let j = 0; j < iterations; j++) {
const theta = randomGaussian(-PI / 2.0, PI / 2.0);
const x = Math.cos(theta) * len;
const y = Math.sin(theta) * len;
const offx = spacing*1.5 + (i + 1) * spacing;
const offy = spacing*1.5 + (j + 1) * spacing;
let canPlaceLine = false;
//colorMode(HSB, 100);
distanceThreshold = random(0, 50);
for (let w = 0; w < randompoints; w++) {
const distance = dist(x + offx, y + offy, pointsx[w], pointsy[w]);
if (debug == 2 || debug == 4) {
ellipse(x + offx, y + offy, 10, 10);
ellipse(-x + offx, -y + offy, 10, 10);
}
if (distance > distanceThreshold && dist(-x + offx, -y + offy, pointsx[w], pointsy[w]) > distanceThreshold) {
canPlaceLine = true;
} else {
canPlaceLine = false;
break;
}
}
stroke(0);
if (debug == 3 || debug == 4) {
//colorMode(HSB, 1);
stroke(cos(theta) * 255, sin(theta) * 255, 255);
}
if (canPlaceLine) {
line(x + offx, y + offy, -x + offx, -y + offy);
}
}
}
}