Home
โญ•

Epicycles

This piece renders glowing points running along two joined circles.
Tap on the screen to control the frequencies of the rotations of the inner (x coordinate) and outer (y coordinate) circles.
Toggle shader source Remix this

:: epicycle ( r1 r2 f1 f2 t -- vec2 )
   \ Render a point on r1
   t f1 * cos r1 *
   t f1 * sin r1 * vec2
   
   \ Render a point on r2, centered at r1
   t f2 * cos r2 *
   t f2 * sin r2 * vec2
   +
;

:: freq-1 ( -- freq )
   \ freq of the inner loop based on mouse-x
   mouse resolution / .x 20 * 5 + floor
;

:: freq-2 ( -- freq )
   \ freq of the outer loop based on mouse-y
   mouse resolution / .y 20 * 5 + floor
;

:: dot ( t -- vec3 )
   \ render a single dot in time
   \ past or present
   
   \ epicycle position
   0.5 0.3 freq-1 freq-2 t epicycle
   
   \ delta from uv
   uv - length abs
   \ smooth the edges
   0 0.008 smoothstep
  
   \ invert
   -1 * 1 +
  
   \ limegreen
   0.1 1.0 0.3 vec3 *
;

:: dot-iter ( curr-vec delta -- vec3 delta )
   \ add a dot and time delta to the stack

   \ rewind in time based on the delta
   time delta 200 / -
   dot
   curr-vec +
   
   \ increment the delta
   delta 1 +
; 

: main
  0 0 0 vec3
  0
  \ add 100 dots
  100 [ dot-iter ] times
  \ just leave the color
  drop
  
  1.0 vec4
;