Skip to content

Instantly share code, notes, and snippets.

@mpersano
Last active March 3, 2016 00:43
Show Gist options
  • Select an option

  • Save mpersano/8f312cd3a29b930b2c9f to your computer and use it in GitHub Desktop.

Select an option

Save mpersano/8f312cd3a29b930b2c9f to your computer and use it in GitHub Desktop.
#version 300 es
precision highp float;
uniform vec2 resolution;
uniform float time;
const float PI = 3.14159265358979323844;
out vec4 color;
float wobble(vec2 pos)
{
return (.5 + .5*sin(3.*time + 3.*length(pos - vec2(.5, .5))));
}
bool inside_triangle(vec2 pos, vec2 center, float r, float s)
{
float w = wobble(center);
float r_inner = r*w;
const float da = 2.*PI/3.;
float a = s*w;
for (int i = 0; i < 3; i++) {
vec2 n = vec2(sin(a), cos(a));
if (dot(n, pos - (center + r_inner*n)) > 0.)
return false;
a += da;
}
return true;
}
bool inside_hexagon(vec2 pos, vec2 center, float r)
{
float r_inner = .5*r;
const float da = 2.*PI/6.;
float a = 0.;
for (int i = 0; i < 6; i++) {
if (inside_triangle(pos, center + r*vec2(sin(a), cos(a)), r_inner, a))
return true;
a += da;
}
return false;
}
bool inside_cluster(vec2 pos)
{
float r_outer = .25;
if (inside_hexagon(pos, vec2(.5, .5), .3*r_outer))
return true;
const float da = 2.*PI/6.;
float a = 0.;
for (int i = 0; i < 6; i++) {
if (inside_hexagon(pos, vec2(.5, .5) + r_outer*vec2(sin(a), cos(a)), .35*r_outer))
return true;
a += da;
}
return false;
}
void main()
{
const float radius = 40.;
vec2 p = gl_FragCoord.xy/resolution;
color = inside_cluster(p) ? vec4(.5, 1., 1., 1.) : vec4(.25, .25, .25, 1.);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment