Skip to content

Instantly share code, notes, and snippets.

@u-ndefine
Last active November 30, 2020 09:18
Show Gist options
  • Save u-ndefine/69fd960ed22ef51aa21160d773249f2e to your computer and use it in GitHub Desktop.
Save u-ndefine/69fd960ed22ef51aa21160d773249f2e to your computer and use it in GitHub Desktop.
int grid=7;
float size=60;
float h_grid=float(grid)/2;
boolean[][] drawn;
color color_burn(color a, color b) {
return color(255-(255-red(b))/red(a)*255,255-(255-green(b))/green(a)*255,255-(255-blue(b))/blue(a)*255);
}
void setup() {
drawn = new boolean[grid+1][grid+1];
// init
size(1000,1000);
clear();
background(255);
colorMode(RGB);
// paper texture
noiseDetail(10,0.75);
loadPixels();
for (int x = 0;x < width;x++) {
for (int y = 0;y < height;y++) {
float bright = noise(x*0.02, (y-x*0.7)*0.02) * 200 * min(float(min(x, height-x)*4 + height / 4)/height, float(min(y, width-y)*4 + width / 4)/width,1.1);
if (random(1.) < 0.25) { bright = bright * random(0.75,1.); }
pixels[x+y*width] = color_burn(color(bright),#FEF5E8);
}
}
updatePixels();
translate(width/2,height/2);
noStroke();
// links
for(int x=0;x<=grid;x++) {
for(int y=0;y<=grid;y++) {
// colors
if (random(1.) > 0.4) {
colorMode(HSB);
fill(random(255.),120.,200.);
} else {
colorMode(RGB);
fill(0);
}
boolean dir = random(1.)>.5;
int len = floor(random(6.)*random(6.)/6.+.5);
if(!drawn[x][y]) {
drawn[x][y] = true;
int fin = 0;
for(int off=0; off < len && !(drawn[min(x+(dir?off+1:0),grid)][min(y+(dir?0:off+1),grid)] | x+(dir?off+1:0) > grid | y+(dir?0:off+1) > grid); off++) {
int xx = x+(dir?off:0);
int yy = y+(dir?0:off);
drawn[min(xx,grid)][min(yy,grid)] = true;
fin = off + 1;
}
int xx = x+(dir?fin:0);
int yy = y+(dir?0:fin);
beginShape();
vertex((x-h_grid)*size-size/3+random(-(size/10),size/10),(y-h_grid)*size-size/3+random(-(size/10),size/10));
vertex((x-h_grid)*size-size/3+random(-(size/10),size/10),(yy-h_grid)*size+size/3+random(-(size/10),size/10));
vertex((xx-h_grid)*size+size/3+random(-(size/10),size/10),(yy-h_grid)*size+size/3+random(-(size/10),size/10));
vertex((xx-h_grid)*size+size/3+random(-(size/10),size/10),(y-h_grid)*size-size/3+random(-(size/10),size/10));
drawn[min(xx,grid)][min(yy,grid)] = true;
endShape();
}
}
}
saveFrame("png.png");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment