Skip to content

Instantly share code, notes, and snippets.

@KrabCode
Created July 26, 2019 10:18
Show Gist options
  • Select an option

  • Save KrabCode/cdb4a97862d4ae5b8113caaa708bf662 to your computer and use it in GitHub Desktop.

Select an option

Save KrabCode/cdb4a97862d4ae5b8113caaa708bf662 to your computer and use it in GitHub Desktop.
float octaves;
void setup() {
size(800, 800, P2D);
smooth(8);
}
void draw() {
background(0);
float t = radians(frameCount*.5);
/*
float lineCount = slider("count", 0, 160, 65);
strokeWeight(slider("weight", 1, 10, 1.5));
float margin = slider("margin", 0, 400);
float yOff = slider("y offset", -100, 100, -50);
float padding = slider("padding", 0, 200, 160);
octaves = slider("octaves", 1, 12, 6);
*/
float lineCount = 65;
strokeWeight(1.5);
float margin = 200;
float yOff = -50;
float padding = 160;
octaves = 3;
for (int i = 0; i < lineCount; i++) {
float iN = map(i, 0, lineCount-1, 0, 1);
float y = map(iN, 0, 1, margin, height-margin);
y -= yOff/2;
float x0 = margin;
float x2 = width-margin;
float x1 = map(fbm(iN*6-t), 0, 1, x0+padding, x2-padding);
beginShape();
noFill();
stroke(0);
vertex(x0, y);
stroke(255);
vertex(x1, y+yOff);
stroke(100);
vertex(x1, y+yOff);
stroke(0);
vertex(x2, y);
endShape();
}
}
float fbm(float x) {
float sum = 0;
float freq = 1;
float amp = 1;
for (int i = 0; i < floor(octaves); i++) {
sum += amp*(sin(x*freq));
freq *= 2;
amp *= .5;
}
return .5+.5*sum;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment