Page 1 of 1

Color morphing

Posted: Thu Feb 16, 2006 9:35 am
by Joakim Christiansen
Code updated For 5.20+

Code: Select all

;Color morphing example by Joakim L. Christiansen

OpenWindow(0,0,0,320,480,"Color morphing!",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)

Color1 = RGB(Random(255),Random(255),Random(255))
Color2 = RGB(Random(255),Random(255),Random(255))
ColorWas = Color1

Red.f   =   Red(Color1)
Green.f = Green(Color1)
Blue.f  =  Blue(Color1)

X = 80 ;Could be any value
XW = X

Repeat
  X - 1
  
  Red   + (  Red(Color2)-Red(ColorWas)  ) / XW
  Green + (Green(Color2)-Green(ColorWas)) / XW
  Blue  + ( Blue(Color2)-Blue(ColorWas) ) / XW
  Color1 = RGB(Red,Green,Blue)
  
  ;Debug Str(Red(Color1))+"."+Str(Green(Color1))+"."+Str(Blue(Color1))
  
  StartDrawing(WindowOutput(0))
  Box(0,0,160,480,Color1)
  Box(160,0,160,480,Color2)
  StopDrawing()
  
  If WindowEvent()=#PB_Event_CloseWindow
    End
  EndIf
  
  Delay(20)
Until X=0

If Color1 <> Color2
  MessageRequester("ERROR","Not the same!")
EndIf

Delay(1000)
If somebody got other code doing the same thing then feel free to post it here! :D

Posted: Thu Feb 16, 2006 11:07 pm
by teracode
Uh, where's the trick? This is just simple arithmetic...

Posted: Fri Feb 17, 2006 12:09 am
by Intrigued
Some of the best things in life are "simple".

One can use this to build from, transitional effect, swanky.

Thanks for sharing.

*thumbs up*

Posted: Fri Feb 17, 2006 12:19 am
by teracode
Well, if that impresses you, maybe you should ask the mods for a "Newbie Tricks" section or something.

Posted: Fri Feb 17, 2006 12:28 am
by Dare2
Bad hair day, teracode?

Posted: Fri Feb 17, 2006 12:44 am
by Intrigued
@teracode

One should understand that folks are at different levels of learning PB. I am at the so called "newbie, noob, etc." stage.

In that small chunk of code are several lessons that one can learn from, not just the ability to color morph.

But, if you have some code to amaze us, by all means display the source here for us all to gander upon.

Oh and TIA.