tweening colours over time

BlitzMax Forums/BlitzMax Programming/tweening colours over time

Robert Cummings(Posted 2006) [#1]
Hi all,

Say I have 2 sets of random colours -

I would like to be able to tween the colours to the other set of colours using time t (0..1) but without actually making the colours go crazy if you know what I mean?

Because if I calculate it seperately it seems to go through other colours along the way...

Any ideas?


Dreamora(Posted 2006) [#2]
Tween the color difference in the 3 components with the actual value of [0..1]

for example
c1: 200,20,50
c2: 100,200,160

=> dif: -100,180,110
act color = c1 + tween * dif


EOF(Posted 2006) [#3]
' color range

Const sw=640,sh=480

SetGraphicsDriver GLMax2DDriver()
Graphics sw,sh,0
SetClsColor 120,120,120
Cls

Global r1%=100 , g1%=220 , b1%=100
Global r2%=28 , g2%=55 , b2%=240

Global t#=0 , ypos%=40

While t<1.0
	SetColor rpos(r1,r2,t) , rpos(g1,g2,t) , rpos(b1,b2,t)
	DrawLine 10,ypos,sw-20,ypos
	t:+0.0024
	ypos:+1
Wend

Flip
WaitKey
End

Function rpos%(c1%,c2%,p#)
	If c2<c1 p=-p
	Return c1+(Abs(c2-c1)*p)
End Function



Robert Cummings(Posted 2006) [#4]
thanks all :)


Booticus(Posted 2006) [#5]
Damn Jim! Thats nifty keen! I was looking for the code to do this exact thing a couple months back! I just dont know why the hell I didn't ask how to do it like One Eyed Jack did?!? Thanks everybody!


TartanTangerine (was Indiepath)(Posted 2006) [#6]
You are using RGB there, the results are not correct. You need to be looking at HSB for smooth transitions.


Robert Cummings(Posted 2006) [#7]
Thats what I was talking about, but I didn't really want to push the issue. HSB is probably slower too.


Robert Cummings(Posted 2006) [#8]
Well assuming it's a nonsical few instructions more, how would I go about achieving HSB transitions ?


EOF(Posted 2006) [#9]
Here are 2 functions I've converted from the archives:



Robert Cummings(Posted 2006) [#10]
Thank you very much! most kind...