Spiral colors

Post Reply
User avatar
Dutchman
Posts: 851
Joined: Mon May 06, 2013 9:21 am
My devices: iMac, iPad Air, iPhone
Location: Netherlands
Flag: Netherlands

Spiral colors

Post by Dutchman »

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:

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
''
SpiralColors.PNG
SpiralColors.PNG (245.45 KiB) Viewed 1945 times

User avatar
sarossell
Posts: 195
Joined: Sat Nov 05, 2016 6:31 pm
My devices: iPad Mini 2, iPhone 5, MacBook Air, MacBook Pro
Flag: United States of America
Contact:

Re: Spiral colors

Post by sarossell »

Beautiful. And kind of trippy, man. 8-)
smart BASIC Rocks!

- Scott : San Diego, California

User avatar
rbytes
Posts: 1338
Joined: Sun May 31, 2015 12:11 am
My devices: iPhone 11 Pro Max
iPad Pro 11
MacBook
Dell Inspiron laptop
CHUWI Plus 10 convertible Windows/Android tablet
Location: Calgary, Canada
Flag: Canada
Contact:

Re: Spiral colors

Post by rbytes »

Nice effect. Lots of possible variations.

Your palet function, and now this one for saturated colors, are worth studying by all who want to improve their coding skills. :)
The only thing that gets me down is gravity...

Post Reply