xxxxxxxxxx
77
// title: maurer triangle two color swish
// author: Winston Smith, @sequentialchaos
// created: Aug. 5, 2020
// https://editor.p5js.org/sequentialchaos/sketches/OxlrTVclo
const NUM_TRIANGLES = 30;
let n = 2.192;
let d = 42.984;
let i = 0.959;
let j = 1.328;
let p, r;
let h1, h2, hrange, hinc;
function setup() {
createCanvas(innerWidth, innerHeight);
colorMode(HSB, 1, 1, 1, 1);
noStroke();
p = PI
r = (width + height) / 2 * 0.75;
hrange = 0.10
h1 = 0
h2 = h1 + hrange
hinc = 0.00001
}
function draw() {
translate(width / 2, height / 2);
background(0, 0.05);
for (let w = 0; w < NUM_TRIANGLES; w++) {
let t = i + w;
let p1 = maurer(t, n, d, r);
let p2 = maurer(t + p, n, d, r);
let p3 = maurer(t + p + 0.01, n, d, r);
h1 = (h1 + hinc) % (1-hrange)
h2 = (h1 + hrange) % 1
h = map(w / NUM_TRIANGLES, 0, 1, h1, (h1 + h2))
fill(h, 1, 1, 0.01);
triangle(p1.x, p1.y, p2.x, p2.y, p3.x, p3.y);
}
i += PI / 100000;
j += PI / 50000;
p = map(easeInOutQuad((j % PI) / PI), 0, 1, PI, PI * 3);
d += 0.0001;
n += 0.00001;
// showValues()
}
function maurer(t, n, d, rMax) {
let k = t * d;
let r = rMax * sin(n * k);
let x = r * cos(k);
let y = r * sin(k);
return { x, y };
}
function showValues() {
push()
resetMatrix()
fill(1)
stroke(0)
textSize(40)
text(`n = ${n.toFixed(3)}`, 20, 50)
text(`d = ${d.toFixed(3)}`, 20, 100)
text(`i = ${i.toFixed(3)}`, 20, 150)
text(`j = ${j.toFixed(3)}`, 20, 200)
text(`p = ${p.toFixed(3)}`, 20, 250)
pop()
}
function easeInOutQuad(t) {
return t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t;
}