Skip to content

Instantly share code, notes, and snippets.

@marvinpoo
Created March 20, 2025 22:14
Show Gist options
  • Select an option

  • Save marvinpoo/d646580f5c5c949443fc277e77b14e53 to your computer and use it in GitHub Desktop.

Select an option

Save marvinpoo/d646580f5c5c949443fc277e77b14e53 to your computer and use it in GitHub Desktop.
stop gugging on my green shirt - the code
let canvasWidth = 800; // Update canvas width
let canvasHeight = 800; // Update canvas height
let threadCount = 425; //tinker
function setup() {
createCanvas(canvasWidth, canvasHeight);
angleMode(DEGREES);
noLoop();
}
function draw() {
background(random(0, 255), random(0, 255), random(0, 255));
drawWeft();
warp();
}
function drawWeft() {
stroke(random(0, 255));
weft = [];
const pos1 = createVector(canvasHeight, 0);
const pos2 = createVector(canvasWidth, 0);
const dir1 = createVector(0, canvasHeight / threadCount);
const dir2 = createVector(0, canvasHeight / threadCount);
while ((pos1.y < canvasHeight || pos2.y < canvasHeight) && weft.length < 1275 /*tinker*/) {
dir1.rotate(random(-3, 3)); //tinker
dir2.rotate(random(-4, 3)); //tinker
pos1.add(dir1);
pos2.add(dir2);
pos1.x = min(pos1.x, 0);
pos2.x = max(pos2.x, canvasWidth);
line(pos1.x, pos1.y, pos2.x, pos2.y);
weft.push([pos1.copy(), pos2.copy()]);
}
threadCount = weft.length;
for (i = 1; i < 9; i++) nf(125, 1420 /*tinker*/, i);
}
function warp() {
strokeWeight(2);
pattern = [1, 6, PI];
for (let i = 0; i < threadCount; i++) {
const t = i / threadCount;
for (let j = 0; j < threadCount - 1; j++) {
if (pattern[0] == 1) {
const p1 = p5.Vector.lerp(weft[j + 0][0], weft[j + 0][1], t);
const p2 = p5.Vector.lerp(weft[j + 1][0], weft[j + 1][1], t);
const p3 = p5.Vector.lerp(weft[j + 1][0], weft[j + 0][1], t);
stroke(random(0, 110), random(200, 255), random(111, 199), noise(p1.x / 250, p1.y / 250) * 255);
lineV(p1, p2, p3);
}
pattern.push(pattern.shift());
}
}
function f(x, y, r, d, i) {
if (d > 1.237) {
line(x, y, (x += cos(r) * d), (y += sin(r) * d));
f(x, y, r + PI / 2.5 - i * 0.6, d * 0.7, i);
f(x, y, r - PI / 9 + i * 0.6, d * 0.7, -i);
}
}
function effects(x_) {
return cos(4 * x_ + 1) / 2;
}
}
const lineV = (v1, v2, v3) => line(v1.x, v1.y, v2.x, v2.y);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment