Colour Cycling

Archives Forums/BlitzPlus Programming/Colour Cycling

QuickSilva(Posted 2003) [#1]
Can anybody help me create a nice looking colour cycle?
I am trying to create a nice smooth cycle through all the colours of the rainbow and loop it repeatedly.

Any help\ideas would be great.
Jason.


rdodson41(Posted 2003) [#2]
You basically have to make a loop, and continuously change the rgb numbers, and the just draw a rectangle with the current color. Ex:

Red 255,0,0
Red Orange 255,100,0
Yellow Orange 255,200,0
Yellow 255,255,0
Lime Yellow 200,255,0
Yellow Green 100,255,0
Green 0,255,0
Turqouise 0,255,100
Aqua 0,200,200
Greenish Blue 0,100,255
Blue 0,0,255
Blue Violet 100,0,255
Violet 200,0,200
Red Violet 255,0,100
Red 255,0,0

And so on. These aren't the exact colors of the Rainbow, because the rainbow uses Magenta, Cyan and Yellow as the base colors, while the computer uses RGB. So you will have to work out exactly how to do this, but here is a start, hopefully.


ford escort(Posted 2003) [#3]
can you please explain more what kind of colour cycling you wan't to achieve?

is this a one color changing to all the rainbow colors or all the rainbow colors cycling cycling from one to another
red to orange orange to yellow etc... but you still have all the colors onscreen but at different place ?


QuickSilva(Posted 2003) [#4]
I want one colour to slowly change from red to orange, orange to yellow etc... but it must fade between the colours slowly not a sharp full red to full orange effect but a more subtle fading between colours.

Jason.


ford escort(Posted 2003) [#5]
ok this is something like that you probly wan't
format_code('
Graphics 800,600,32,3
Restore colo
Read r1,g1,b1,blah
Read r2,g2,b2,nb
st=0
Repeat
st=st+1
col$=gradient(r1,g1,b1,r2,g2,b2,nb,st)
Color Mid(col$,1,3),Mid(col$,4,3),Mid(col$,7,3)
Rect 0,0,800,600
Flip
If st=nb
r1=r2
g1=g2
b1=b2
st=0
Read r2,g2,b2,nb
If r2=999 And g2=999 And b2=999
Restore colo
Read r2,g2,b2,nb
EndIf
EndIf
Until KeyDown(1)
WaitKey
End
;---------------data--------------
;r,g,b,steps
;---------------------------------
.Colo
Data 255,0,0,100
Data 255,100,0,100
Data 255,200,0,100
Data 255,255,0,100
Data 200,255,0,100
Data 100,255,0,100
Data 0,255,0,100
Data 0,255,100,100
Data 0,200,200,100
Data 0,100,255,100
Data 0,0,255,100
Data 100,0,255,100
Data 200,0,200,100
Data 255,0,100,100
Data 999,999,999,999 ; end of data

;-------------function gradient-----------
; return a string in format rrr,ggg,bbb
;-----------------------------------------
;
;rs#,gs#,bs# :rgb source
;re#,ge#,be# :rgb destination
;stpg steps for the total transition
;cs current step
;
;
Function gradient$(rs#,gs#,bs#,re#,ge#,be#,stpg,cs)
If rs#>re#
vadr#=((rs#-re#)/stpg)*-1.0
Else
vadr#=((re#-rs#)/stpg)*1.0
EndIf
If rs#>re#
vadg#=((gs#-ge#)/stpg)*-1.0
Else
vadg#=((ge#-gs#)/stpg)*1.0
EndIf
If bs#>be#
vadb#=((bs#-be#)/stpg)*-1.0
Else
vadb#=((be#-bs#)/stpg)*1.0
EndIf
rs#=rs#+vadr#*cs
gs#=gs#+vadg#*cs
bs#=bs#+vadb#*cs
Return Mid$("000",1,3-Len(Str$(Int(rs#))))+Str$(Int(rs#))+Mid$("000",1,3-Len(Str$(Int(gs#))))+Str$(Int(gs#))+Mid$("000",1,3-Len(Str$(Int(bs#))))+Str$(Int(bs#))
End Function
')


hope you like :)


QuickSilva(Posted 2003) [#6]
Thanks to all that helped especially ford escort, that function was exactly what I was after, thanks.

Jason.


ford escort(Posted 2003) [#7]
you're welcome :)