Skip to content

Instantly share code, notes, and snippets.

@dodo
Created June 14, 2012 02:22
Show Gist options
  • Save dodo/2927729 to your computer and use it in GitHub Desktop.
Save dodo/2927729 to your computer and use it in GitHub Desktop.
organic blueprint
float S = 20;
int N = 6;
float M = 500;
float wh, hh;
PGraphics pg;
void setup() {
//size(800, 600, P2D);
size(1280, 800, P2D);
strokeWeight(1.3);
smooth();
wh = width * 0.5;
hh = height * 0.5;
pg = createGraphics(width, height, P2D);
pg.smooth();
draw_bg();
//noLoop();
}
void draw_bg() {
float r;
float wh = width * 0.5;
float hh = height * 0.5;
float _maxr = 0.95 / sqrt(wh * wh + hh * hh);
float s = sin(frameCount * TWO_PI / 25);
pg.loadPixels();
for (int y = 0 ; y < height ; y++ ) {
for (int x = 0 ; x < width ; x++ ) {
r = dist(x, y, wh, hh);
pg.pixels[y * width + x] =
colmul(
abs(s) * constrain(1 + random(0.16) - random(0.16),0,1),
lerpColor(#5185DA, #223668, r*_maxr)
);
}
}
//pg.filter(BLUR, 4);
pg.updatePixels();
}
void draw() {
//draw_bg();
image(pg, 0, 0);
int i;
float wh = width * 0.5;
float hh = height * 0.5;
translate(wh, hh);
i = 0;
for (float y = 0 ; y < hh ; y = y + S ) {
if (i++%N == 0) stroke(222,89);
else stroke(222,23);
myline(wh,+y,-wh,+y);
if (i > 1) myline(wh,-y,-wh,-y);
}
i = 0;
for (float x = 0 ; x < wh ; x = x + S ) {
if (i++%N == 0) stroke(222,89);
else stroke(222,23);
myline(+x,hh,+x,-hh);
if (i > 1) myline(-x,hh,-x,-hh);
}
}
color colmul(float f, color c) {
return color(
f * red(c),
f * green(c),
f * blue(c)
);
}
void myline(float x1, float y1, float x2, float y2) {
float n,m, d, _x, _y;
float ox = x1;
float oy = y1;
float mx = mouseX - wh;
float my = mouseY - hh;
for(float i = 0 ; i < 1 ; i = i + 0.005) {
_x = lerp(x1, x2, i);
_y = lerp(y1, y2, i);
d = dist(_x, _y, mx, my);
n = noise(_x/wh, _y/hh, frameCount*0.01);
m = n * M;
if(d < m) {
m = (1 - d/m) + n;
_x = mx + (_x - mx) * 1.1 * m + random(9);
_y = my + (_y - my) * 1.1 * m + random(9);
}
line(ox, oy, _x, _y);
ox = _x; oy = _y;
}
line(ox, oy, x2, y2);
}
@dodo
Copy link
Author

dodo commented Jun 14, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment