Here’s what it does:
-
Enter an algorithm in RLIP.
-
Each time you call
symb
it adds a circle to a list of circles to draw. The first two arguments are the X-Y position, the next argument is the circle radius (same units as the position), and the next four arguments are red-green-blue-alpha in linear values in the 0 to 1 range. -
The program just draws from that list of circles.
As with all my projects it depends on rouziclib for all the heavy lifting so it needs to be in your include path.
The interface is zoomable as explained here. Basically by clicking the middle mouse button you enter the zoom-scroll mode so you can zoom (using the scroll wheel) and adjust the selection with more precision. You exit that mode by clicking the middle mouse button again or better yet reset the view by holding the middle mouse button for at least half a second.
This one creates a 3D sphere with bokeh with two coloured areas. Adjust the knob for variable k0
for how the dots spin up the sphere, angle
to make it rotate and k1
to adjust camera focus.
d i = 0
i_loop:
expr d north = (i-0.5)/2
expr d west = (i * k0 + 0.25)%1
expr d westr = (west - angle)%1
expr d p.x = cos_tr_d2(westr) * cos_tr_d2(north)
expr d p.y = cos_tr_d2(north-0.25)
expr d p.z = cos_tr_d2(westr-0.25) * cos_tr_d2(north)
expr d rad = abs(p.z-k1) * 0.02
expr d m = .00003/sq(rad)
expr m = m*erfr(p.z*3)
// Colours
expr d spot_a = 8*exp(-sqadd((north-0.1)*40, (west-0.3)*20))
expr d spot_b = exp(-sqadd((north+0.05)*20, (west-0.5)*20))
expr d red = 0.13*m + spot_a*m + spot_b*4*m
expr d grn = (0.13 + spot_a)*m (1 - spot_b)^20 + spot_b*.04*m
expr d blu = (0.5 + spot_b)*m (1 - spot_b)^20 + spot_b*.04*m
// Draw symbol
d v = symb p.x p.y rad red grn blu 1
i = add i .0008
i i_cond = cmp i <= 1
if i_cond goto i_loop
return 0
Adapted from this tweet. Use k0
to make time move forward (hold the Alt key to make it happen smoothly).
d num_curves = 512
d iter = 400
d t = k0
d alpha = 1
d radm = 0.004
d r = 2pi/235
d tr = 1/(2pi)
d i = 0
i_loop:
d p.x = 0
d p.y = 0
d j = 0
j_loop:
// Position
expr d a = i*r + t + p.x
expr d b = i + t + p.y
expr p.x = cos_tr_d2(a*tr-0.25) + cos_tr_d2(b*tr-0.25)
expr p.y = cos_tr_d2(a*tr) + cos_tr_d2(b*tr)*0.1
// Radius
expr d rad = radm * (1 - (j / iter))
// Colour
expr d red = sq(i / num_curves)
expr d grn = sq(0.5+0.5*cos_tr_d2(j/200+0.25))
expr d blu = sq(1-(i/num_curves+j/iter)/2)
// Draw symbol
d v = symb p.x p.y rad red grn blu alpha
j_end:
inc1 j
i j_cond = cmp j < iter
if j_cond goto j_loop
i = add i 3.86
i i_cond = cmp i < num_curves
if i_cond goto i_loop
return 0
Naturally you can simply loop through a variable x
, calculate a y
from it, and for each iteration of x
draw a circle at (x
, y
).
// Circle colour
d m = 0.1
d rb = mul m 0.1
d g = mul m 0.8
d x = -40
loop_x:
d y = 0
// Loop through frequencies and sum them to y
d freq = 0
loop_freq:
expr y = y + cos_tr_d2(x*freq)*erfr(freq*k0-k1)
freq = add freq 0.01
i c_freq = cmp freq < 0.5
if c_freq goto loop_freq
// Control vertical scale
y = mul y 0.5
// Draw the circle
d v = symb x y .04 rb g rb 1
x = add x 0.005
i c_x = cmp x < 40
if c_x goto loop_x
return 0
I needed to create a 256-colour palette for some data visualisation so I experimented with colouring a grid of circles until I was happy with the formula.
d i = 0
i_loop:
expr d t = (255-i)*0.2
expr d m = sqrt(i/255)
// Colours
expr d red = (1-abs(cos_tr_d2(0.16 * t-0.25))) * m
expr d grn = (1-abs(cos_tr_d2(0.02 * t -0.25))) * (i/255)
expr d blu = (1-abs(cos_tr_d2(0.15 * t-0.25))) * m
// Draw palette
expr d p.x = i%16
expr d p.y = floor(i/16)
d v = symb p.x p.y 0.46 red grn blu 1
// Draw side graph
p.x = mad red 8 16.5
p.y = mad blu 8 3
v = symb p.x p.y 0.08 red grn blu 1
i = add i 1
i i_cond = cmp i < 256
if i_cond goto i_loop
return 0