Strict
Import mojo
Function Main:Int()
New MyApp
Return 0
End
Class MyApp Extends App
Field colfixed:Color
Field colmod:Color
Field colmodhue:Color
Field colmodsat:Color
Field colmodbri:Color
Field color1:Color, color2:Color
Field colorhmix:Color, colorcmix:Color
Method OnCreate:Int()
SetUpdateRate(20)
' define Color by named const
colfixed = New Color( COLOR_AQUAMARINE )
' define Color by hex value
colmod = New Color( $99ffcc )
' define Color via string identifier
colmodhue = New Color( "darkturquoise" )
' define Color by rgb triplet
colmodsat = New Color( 255, 0, 0 )
' define Color by rbg array
colmodbri = New Color( [128,0,255] )
' define Colors to mix by hex value
color1 = New Color( $ff0000 )
color2 = New Color( $00ff00 )
colorhmix = New Color()
colorcmix = New Color()
Return 0
End
Method OnUpdate:Int()
Local at:Float = Millisecs() / 4000.0 * 360.0
' modulate red component
colmod.r = 127.5 + 127.5 * Sin(at)
' modulate hue
colmodhue.hue += 1
' modulate saturation
colmodsat.sat = 0.5 + 0.5*Sin(at)
' modulate brightness
colmodbri.bri = 0.5 + 0.5*Sin(at)
Return 0
End
Method OnRender:Int()
Local val:Float
Cls( COLOR_DARKSLATEGREY )
SetBlend( AlphaBlend )
' fixed color
SetColor( COLOR_WHITE )
DrawText( "fixed color", 0+20, 0+5 )
SetColor( colfixed )
DrawRect( 0+20, 0+20, 280, 50 )
' fixed color
SetColor( COLOR_WHITE )
DrawText( "fixed color 2", 320+20, 0+5 )
SetColor( NamedHtmlColor( "lightsalmon" ) )
DrawRect( 320+20, 0+20, 280, 50 )
' demo: component change
SetColor( COLOR_WHITE )
DrawText( "one component changing color, r="+colmod.r, 0+20, 80+5 )
SetColor( colmod )
DrawRect( 0+20, 80+20, 280, 50 )
' demo: hue change
val = Int(colmodhue.hue * 100)/100.0
SetColor( COLOR_WHITE )
DrawText( "hue changing color, hue="+val, 320+20, 80+5 )
SetColor( colmodhue )
DrawRect( 320+20, 80+20, 280, 50 )
' demo: saturation change
val = Int(colmodsat.sat * 100)/100.0
SetColor( COLOR_WHITE )
DrawText( "saturation changing color, sat="+val, 0+20, 160+5 )
SetColor( colmodsat )
DrawRect( 0+20, 160+20, 280, 50 )
' demo: brightness change
val = Int(colmodbri.bri * 100)/100.0
SetColor( COLOR_WHITE )
DrawText( "brightness changing color, bri="+val, 320+20, 160+5 )
SetColor( colmodbri )
DrawRect( 320+20, 160+20, 280, 50 )
' demo: color mixing
SetColor( COLOR_WHITE )
DrawText( "color mixing in RGB space", 0+20, 320+5 )
DrawText( "color mixing in HSB space", 0+20, 400+5 )
For Local i:Int = 0 To 19
Local mix:Float = i / 19.0
colorcmix.Mix( color1, color2, mix )
colorhmix.MixHsb( color1, color2, mix )
SetColor( colorcmix )
DrawRect( 20+i*30, 340, 30, 50 )
SetColor( colorhmix )
DrawRect( 20+i*30, 420, 30, 50 )
Next
Return 0
End
End