Sun Spectacular.bas

Inspired by Walter's Forum Graphic at TJP

' sun spectacular.bas for SmallBASIC 0.12.9 (B+=MGA) 2017-08-16

' ==================================================================
' Press spacebar to inject sun with new Plasma
' ==================================================================

def rand(lo, hi) = (rnd * (hi - lo + 1)) \ 1 + lo
def distance(x1, y1, x2, y2) = ( (x1 - x2) ^ 2 + (y1 - y2) ^ 2) ^ .5

sub
midInk(r1, g1, b1, r2, g2, b2, fr)
color rgb(r1+(r2-r1)*fr, g1+(g2-g1)*fr, b1+(b2-b1)*fr)
end

sub
resetPlasma() 'all globals
plasmaR = rnd ^ 2 : plasmaG = rnd ^ 2 : plasmaB = rnd ^ 2 : plasmaN = 0
end

sub
setPlasma() 'all globals
plasmaN += .5
color rgb(127+127*sin(plasmaR*plasmaN),127+127*sin(plasmaG*plasmaN),127+127*sin(plasmaB*plasmaN))
end

definekey 32, resetPlasma
horizon = rand(ymax-200, ymax-100)
sunx = xmax/2
ray = distance(0, 0, sunx, horizon)
resetPlasma
while 1
for i= 0 to horizon
midInk 0, 0, 128, 40, 200, 255, i/horizon
line 0, i, xmax, i
next
for i = horizon to ymax
midInk 40, 200, 100, 100, 64, 30, (i-horizon)/(ymax-horizon)
line 0, i, xmax, i
next
for r = pi to 2*pi step pi/200
setPlasma
line sunx, horizon, sunx + ray*cos(r), horizon + ray*sin(r)
next
showpage
delay 20
wend

With solid filled triangles:

' sun spec 2.bas for SmallBASIC 0.12.9 (B+=MGA) 2017-08-16

' ==================================================================
' Press spacebar to inject sun with new Plasma
' ==================================================================

def rand(lo, hi) = (rnd * (hi - lo + 1)) \ 1 + lo
def distance(x1, y1, x2, y2) = ( (x1 - x2) ^ 2 + (y1 - y2) ^ 2) ^ .5

sub
midInk(r1, g1, b1, r2, g2, b2, fr)
color rgb(r1+(r2-r1)*fr, g1+(g2-g1)*fr, b1+(b2-b1)*fr)
end

sub
resetPlasma() 'all globals
plasmaR = rnd ^ 2 : plasmaG = rnd ^ 2 : plasmaB = rnd ^ 2 : plasmaN = 0
end

sub
setPlasma() 'all globals
plasmaN += .5
color rgb(127+127*sin(plasmaR*plasmaN),127+127*sin(plasmaG*plasmaN),127+127*sin(plasmaB*plasmaN))
end

definekey 32, resetPlasma
horizon = rand(ymax-200, ymax-100)
sunx = xmax/2
ray = distance(0, 0, sunx, horizon)
resetPlasma
while 1
for i= 0 to horizon
midInk 0, 0, 128, 40, 200, 255, i/horizon
line 0, i, xmax, i
next
for i = horizon to ymax
midInk 40, 200, 100, 100, 64, 30, (i-horizon)/(ymax-horizon)
line 0, i, xmax, i
next
for r = pi to 2*pi+pi/400 step pi/400
if r = pi then
p1x = sunx + ray*cos(r) : p1y = horizon + ray*sin(r)
else
p2x = sunx + ray*cos(r) : p2y = horizon + ray*sin(r)
dim t()
t << sunx : t << horizon
t << p1x : t << p1y
t << p2x : t << p2y
t << sunx : t << horizon
setPlasma
drawpoly t filled
p1x = p2x : p1y = p2y
fi
next
showpage
delay 20
wend

1 + 2 = 3

' sun spec 3.bas for SmallBASIC 0.12.9 (B+=MGA) 2017-08-16

' ==================================================================
' Press spacebar to inject sun with new Plasma
' ==================================================================

def rand(lo, hi) = (rnd * (hi - lo + 1)) \ 1 + lo
def distance(x1, y1, x2, y2) = ( (x1 - x2) ^ 2 + (y1 - y2) ^ 2) ^ .5

sub
midInk(r1, g1, b1, r2, g2, b2, fr)
color rgb(r1+(r2-r1)*fr, g1+(g2-g1)*fr, b1+(b2-b1)*fr)
end

sub
resetPlasma() 'all globals
plasmaR = rnd ^ 2 : plasmaG = rnd ^ 2 : plasmaB = rnd ^ 2 : plasmaN = 0
end

sub
setPlasma() 'all globals
plasmaN += .5
color rgb(127+127*sin(plasmaR*plasmaN),127+127*sin(plasmaG*plasmaN),127+127*sin(plasmaB*plasmaN))
end

definekey 32, resetPlasma
horizon = rand(ymax-200, ymax-100)
sunx = xmax/2
ray = distance(0, 0, sunx, horizon)
resetPlasma
while 1
for i= 0 to horizon
midInk 0, 0, 128, 40, 200, 255, i/horizon
line 0, i, xmax, i
next
for i = horizon to ymax
midInk 40, 200, 100, 100, 64, 30, (i-horizon)/(ymax-horizon)
line 0, i, xmax, i
next
for r = pi to 2*pi+pi/200 step pi/200
if r = pi then
p1x = sunx + .1*ray*cos(r) : p1y = horizon + .1*ray*sin(r)
else
p2x = sunx + .1*ray*cos(r) : p2y = horizon + .1*ray*sin(r)
dim t()
t << sunx : t << horizon
t << p1x : t << p1y
t << p2x : t << p2y
t << sunx : t << horizon
setPlasma
drawpoly t filled
p1x = p2x : p1y = p2y
fi
if r <= 2 * pi then
line sunx, horizon, sunx + ray*cos(r), horizon + ray*sin(r)
fi
next
showpage
delay 20
wend

That's awesome. It's actually more mesmerising with a longer delay between refreshes. You could add some code to calculate the desired frames/second. Also when running with no delay, on my machine there's a "tearing" effect that I need to fix (in the SDL code). This will make a good test case :)