Color morphing

Share your advanced PureBasic knowledge/code with the community.
User avatar
Joakim Christiansen
Addict
Addict
Posts: 2452
Joined: Wed Dec 22, 2004 4:12 pm
Location: Norway
Contact:

Color morphing

Post 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
teracode
New User
New User
Posts: 3
Joined: Sat Jan 21, 2006 10:45 pm

Post by teracode »

Uh, where's the trick? This is just simple arithmetic...
"640k should be enough memory for anyone. Now if there are no more questions, I have to go start my new book "The Road Ahead"
Intrigued
Enthusiast
Enthusiast
Posts: 501
Joined: Thu Jun 02, 2005 3:55 am
Location: U.S.A.

Post 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*
Intrigued - Registered PureBasic, lifetime updates user
teracode
New User
New User
Posts: 3
Joined: Sat Jan 21, 2006 10:45 pm

Post by teracode »

Well, if that impresses you, maybe you should ask the mods for a "Newbie Tricks" section or something.
"640k should be enough memory for anyone. Now if there are no more questions, I have to go start my new book "The Road Ahead"
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

Post by Dare2 »

Bad hair day, teracode?
@}--`--,-- A rose by any other name ..
Intrigued
Enthusiast
Enthusiast
Posts: 501
Joined: Thu Jun 02, 2005 3:55 am
Location: U.S.A.

Post 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.
Intrigued - Registered PureBasic, lifetime updates user
Post Reply