Radiating Colors

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

Radiating Colors

Post by rbytes » Thu May 09, 2019 2:24 am

This is a spinoff from some of my previous posts showing the use of DRAW DASH and PHASE to draw lines made of colored segments. You can search for DRAW DASH to find some of them. Here is a link to a demo of how such lines are drawn.
http://kibernetik.pro/forum/viewtopic.php?f=20&t=2276

In Radiating Colors, these segmented lines radiate from the screen center. With each loop, all lines are redrawn, with every segment enlarged slightly. This gives the effect of a colored target on which the rings keep growing. After they reach a maximum size, they return to their starting size and the cycle repeats.

Code: Select all

/*
Radiating Colors by rbytes
May, 2019
Simple math draws
segmented lines as string art
*/

'g' 
REFRESH OFF

''
laun$=LAUNCHER$()
set toolbar off
get screen size sw,sh
graphics
graphics clear 0,0,0
draw alpha 1
ds=3
draw size ds
cshift=0
mult=4
mult2=mult*7

loop:
phs+=1
DRAW DASH mult,mult2 PHASE phs
draw color 1,0,0
gosub liner
DRAW DASH mult,mult2 PHASE phs+mult
draw color 1,.5,0
gosub liner
DRAW DASH mult,mult2 PHASE phs+mult*2
draw color .9,.9,0
gosub liner
DRAW DASH mult,mult2 PHASE phs+mult*3
draw color 0,1,0
gosub liner
DRAW DASH mult,mult2 PHASE phs+mult*4
draw color 0,.9,.9
gosub liner
DRAW DASH mult,mult2 PHASE phs+mult*5
draw color .4,.4,1
gosub liner
DRAW DASH mult,mult2 PHASE phs+mult*6
draw color 1,0,1
gosub liner
DRAW DASH mult,mult2 PHASE phs+mult*7
draw color 1,0,.6
gosub liner

' touch (hold) to end

GET TOUCH 0 AS tx,ty
IF tx<>-1 THEN ender
 
mult+=1
mult2=mult*7
if mult>200 then 
  cshift=0
  mult=4
  mult2=mult*7
endif
refresh
goto loop

ender:
  IF laun$="desktop" THEN
    IF FILE_EXISTS("/launch") THEN
      RUN "/-Launch.sb"
    ELSE
      EXIT
    ENDIF
  ENDIF
  END

liner:
for t=0 to sh+2 step sh/50
  draw line sw/2,sh/2 to sw,t
  draw line sw/2,sh/2 to 0,t
  GET TOUCH 0 AS tx,ty ! IF tx<>-1 THEN ender
next t
for t=0 to sw step sw/50
  draw line sw/2,sh/2 to t,0
  draw line sw/2,sh/2 to t,sh
  GET TOUCH 0 AS tx,ty ! IF tx<>-1 THEN ender
next t
return


'r' ===== Combined Palette function based on Henko and Dutchman converters, by rbytes
DEF Pal(Tint,SATURATION,Brighten,Intensity,Gamma)
' ---- adjust parameter-values between zero and 1.
h=tint*360
tint%=1
Sat=ABS(SATURATION)
IF Sat>1 THEN Sat%=1
Intensity=ABS(Intensity) 
IF Intensity>1 THEN Intensity%=1
Brighten=ABS(Brighten)
IF Brighten>1 THEN Brighten%=1
r=0 ! g=0 ! b=0 ! h%=360
IF h<120 OR h>240 THEN r=palsub(ABS(h-360*FLOOR(h/240)),Gamma)
IF h<240 THEN g=palsub(ABS(h-120),Gamma)
IF h>120 THEN b=palsub(ABS(h-240),Gamma)
Sat: ' with constant luminance
' ---- apply Saturation and Brighten
IF Sat<1 THEN
  Y=0.3*R+0.59*G+0.11*B
  U=B-Y ! U*=sat
  V=R-Y ! v*=sat
  W=G-Y ! w*=sat
  R=Y+V ! G=Y+W ! B=Y+U
  IF Brighten<>0 THEN
    Ysup=1-MAX(MAX(R,G),B)' max white to add
    Ysup*=Brighten
    R+=Ysup ! G+=Ysup ! B+=Ysup
  ENDIF
ENDIF
' ---- apply Intensity
IF Intensity<1 THEN
  R*=Intensity
  G*=Intensity
  B*=Intensity
ENDIF
Y=0.3*R+0.59*G+0.11*B
END DEF ' Pal
DEF palsub(e,Gamma)
f=Gamma   ' 0<=f<=1 better balance between primary and secondary colors
IF e<60 THEN c=1 ELSE ! x=(120-e)/60 ! c=x*(1+f-f*x) ! END IF
RETURN c
END DEF


Attachments
6E719140-63D6-45E9-8D42-A2B8B69102EF.png
6E719140-63D6-45E9-8D42-A2B8B69102EF.png (1.73 MiB) Viewed 44 times
####### Living the colorful life #######

Post Reply