xxxxxxxxxx
/*
Broken symmetry #genuary26 #genuary #genuary2526
Symmetry.
https://openprocessing.org/sketch/2522675
#generativeart #creativecoding #p5js
*/
let pal;
let rndWlkrs;
function setup() {
createCanvas(S=min(windowWidth, windowHeight), S);
describe("random walker lines which breaks on borders")
frameRate(15);
background(32);
strokeWeight(3);
pal = random(palettes)
const num = ~~random(3, 8);
rndWlkrs = [];
for (let i = 0; i < num; i++) {
rndWlkrs.push(new RandomWalker(width/2, height/2, i/num*TWO_PI, i === 0 ? random(palettes) : pal));
}
}
function draw() {
const len = random(S*0.01, S*0.025)
const da = random(-0.2, 0.2);
for (let rw of rndWlkrs) {
rw.go(len);
rw.show();
rw.rotate(da);
}
drawMsg("Broken symmetry (epi) #genuary2526")
}
function drawMsg(msg) {
push();
blendMode(BLEND);
fill("black")
noStroke();
textAlign(LEFT, TOP)
text(msg, 1, 1)
fill("white")
noStroke();
textAlign(LEFT, TOP)
text(msg, 0, 0)
pop();
}
function mousePressed() {
if (mouseButton != RIGHT) setup();
}
class RandomWalker {
constructor(x, y, a, pal) {
this.pos = createVector(x, y);
this.nxt = this.pos.copy();
this.a = a;
this.pal = pal;
this.cid = 0;
}
go(len) {
this.pos = this.nxt.copy();
const vec = createVector(len, 0).rotate(this.a);
this.nxt.add(vec);
/*
let correctDir = false;
if (this.nxt.x < 0 || this.nxt.x >= width) {
correctDir = true;
vec.x *= -1;
}
if (this.nxt.y < 0 || this.nxt.y >= height) {
correctDir = true;
vec.y *= -1;
}
if (correctDir) {
this.nxt.add(vec);
}
*/
}
rotate(a) {
this.a += a;
this.cid = (this.cid+1) % this.pal.length;
}
show() {
stroke(this.pal[this.cid]);
let x1 = this.pos.x;
let y1 = this.pos.y;
let x2 = this.nxt.x;
let y2 = this.nxt.y;
// line(this.pos.x, this.pos.y, this.nxt.x, this.nxt.y);
x1 = x1 % (1*width);
if (x1 >= width) x1 = abs(width-x1);
if (x1 < 0) x1 = abs(x1);
y1 = y1 % (1*height);
if (y1 >= height) y1 = abs(height-y1);
if (y1 < 0) y1 = abs(y1);
x2 = x2 % (1*width);
if (x2 < 0) x2 = abs(x2);
if (x2 >= width) x2 = abs(width-x2);
y2 = y2 % (1*height);
if (y2 < 0) y2 = abs(y2);
if (y2 >= height) y2 = abs(height-y2);
line(x1, y1, x2, y2);
}
}