runnable fragment

Antialiased Circle

ericjang-glsl-playground generative glsl runnable fragment MIT
code snippet
precision mediump float;
float circle_transparency(vec2 uv, vec2 center, float radius) {
    float d = length(uv - center) - radius; // if d positive, then is outside circle
    return clamp(d,0.0,1.0); // if d between 0 and 1, blend for anti-aliasing.
}

void main(void) {
    vec2 uv = gl_FragCoord.xy;
    vec2 center = iResolution.xy * 0.5;
    float radius = 0.25 * iResolution.y;

    vec3 background = vec3(.2);
    vec3 foreground = vec3(1,0,0);
    float alpha = circle_transparency(uv, center, radius);
runnable fragment

Clock

ericjang-glsl-playground generative glsl runnable fragment MIT
code snippet
precision mediump float;
// Created by inigo quilez - iq/2013
// License Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.

uniform vec3 iResolution; // viewport resolution (in pixels)
uniform float iGlobalTime; // shader playback time (in seconds)
uniform vec4 iMouse; // mouse pixel coords. xy: current pixel coords. zw = click pixel
uniform vec4 iDate; // (year, month, day, time in seconds)

float sdSegment( in vec2 p, in vec2 a, in vec2 b )
{
	vec2 pa = p-a, ba = b-a;
	float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );
	return length( pa - ba*h );