Log in to post a comment.
#version 300 es
#define PI 3.1415926
#define THETA 2. * PI
precision highp float;
uniform float iTime;
uniform vec2 iResolution;
uniform vec3 bg_color; //value=0,0,0
uniform vec3 fg_color; //value=1,1,1
uniform int enemies; //value=8, min=2, max=16, step=1
uniform float enemies_rotation_speed; //value=0.5, min=-10, max=10, step=0.001
uniform float level_time; //value=100, min=0, max=1000, step=1
uniform float level_radius; //value=0.6, min=0.1, max=1, step=0.001
vec2 q;
out vec4 fragColor;
bool circ(vec2 p, float r, float t){
return length(q - p) >= r && length(q - p) < r + t;
}
// -1 - inner fill
// 0 - border
// 1 - outer
int circf(vec2 p, float r, float t){
if(length(q - p) < r) return -1;
if(length(q - p) >= r && length(q - p) < r + t) return 0;
return 1;
}
void main() {
// Screen coordinate (from [-aspect, -1] to [aspect, 1])
q = (2. * gl_FragCoord.xy - iResolution) / iResolution.y;
vec3 fill_color = mix(fg_color, bg_color, 0.75);
vec4 col = vec4(bg_color, 1.);
//completion
float r = min(iTime / level_time * level_radius, level_radius);
col = circ(vec2(0., 0.), 0., r) ? vec4(fill_color, 1.) : col;
col = circ(vec2(0., 0.), r, 0.005) ? vec4(fg_color, 1.) : col;
//ring
col = circ(vec2(0., 0.), level_radius, 0.02) ? vec4(fg_color, 1.) : col;
//rings
for(float i = level_radius + mod(iTime / 5., .2); i < 2.2 + mod(iTime / 5., .2); i += .2){
col = circ(vec2(0., 0.), i, 0.01) ? vec4(fg_color, 1.) : col;
}
//outer things
for(float a = -iTime * enemies_rotation_speed; a < THETA + -iTime * enemies_rotation_speed; a += THETA / float(enemies)){
vec2 p = vec2(cos(a), sin(a)) * (level_radius + 0.1 + 0.01);
int c = circf(p, 0.1, 0.01);
if(c == 0) col = vec4(fg_color, 1.);
else if(c == -1) col = vec4(1., 1., 1., 1.);
}
//player
int c = circf(vec2(0., 0.), 0.03, 0.0025);
if(c == 0) col = vec4(fg_color, 1.);
else if(c == -1) col = vec4(1., 1., 1., 1.);
col = circ(vec2(0., 0.), 0.025, 0.005) ? vec4(fg_color, 1.) : col;
// Output
fragColor = col;
}