Skip to content

Instantly share code, notes, and snippets.

@solsarratea
Created June 9, 2020 02:33
Show Gist options
  • Select an option

  • Save solsarratea/135645f2e851b1662c3be6a0ea0f25ea to your computer and use it in GitHub Desktop.

Select an option

Save solsarratea/135645f2e851b1662c3be6a0ea0f25ea to your computer and use it in GitHub Desktop.
FIrst iteration of Koch Curve
// Drawing Koch Curve - first iteration
//i- draw line
//ii- uv symmetrical to y-axis
//ii- fold it
float reflection(inout vec2 pos, float angle){
vec2 normal = vec2(sin(angle),cos(angle));
float d = dot(pos, normal);
pos -= normal*min(0.,d)*2.;
return smoothstep(0.01,0.,abs(d));
}
float line (vec2 pos){
float d = length(pos-vec2(clamp(pos.x,-1.,1.),0.));
return smoothstep(0.01,0.,abs(d));
}
void main() {
vec2 pos = uv();
vec4 color = vec4(0.);
//Symmetrical to y
pos.x = abs(pos.x);
//3 units over the line
pos.x -= .5;
float angle = PI-PI/3.;
float dist = reflection(pos,angle);
//Visualize lines
//color += dist*vec4(0.,1.,0,1.);
color += line(pos);
//color.rb += pos;
gl_FragColor = color;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment