Spiral colors
Posted: Sun Jan 15, 2017 1:56 pm
For a new program I needed a function to generate colours on a circular space.
One of the possibilities is to use the Archimedean spiral:
One of the possibilities is to use the Archimedean spiral:
Code: Select all
'Spiral colors
'by Dutchman, january 2017
' based on Archimedean spiral
' --- constants
size=3
gain=0.75
' --- GO
GET SCREEN SIZE sw,sh
x0=sw/2 ! y0=sh/2
range=MIN(x0,y0)-size
mid=x0+1i*y0
GRAPHICS
GRAPHICS CLEAR 1,1,0.5
CALL Discrete_spiral(mid,size,gain,range)
END
'r'
DEF Discrete_spiral(center,size,gain,maxrange)
x0=REAL(center) ! y0=IMAG(center)
pipi=2*ARG(-1) '2π
' --- move via Archimedean spiral
a=gain*size/2
b=gain*size/6.28319 'size/2π
sign=(-1)^(RND(2)+1) ' turn left or right
phi=0
DO
phi+=dphi
r=a+b*phi
z=r*EXP(1i*phi*sign)
GOSUB plot
phi+=gain*size/r
pause .wait
UNTIL r>maxrange
RETURN
plot:
CALL Hue(r/maxrange+phi/pipi)
FILL COLOR hue.r,hue.g,hue.b
FILL CIRCLE x0+REAL(z),y0+IMAG(z) SIZE size/2
RETURN ' from plot
END DEF
'
DEF Hue(Tint)
'simplified palet-function
'saturated colours only
tint%=1
' ---- divide in 6 sections
tint*=6 ! section=INT(0.5+tint) ! tint%=1
ON Section GOTO S1,S2,S3,S4,S5,S6
S1: ! B=1 ! R=0 ! G=tint ! RETURN
S2: ! G=1 ! R=0 ! B=1-tint ! RETURN
S3: ! G=1 ! B=0 ! R=tint ! RETURN
S4: ! R=1 ! B=0 ! G=1-tint ! RETURN
S5: ! R=1 ! G=0 ! B=tint ! RETURN
S6: ! B=1 ! G=0 ! R=1-tint
END DEF
''