Monkey: drawing a mosaic

Import mojo
Global sprite:MyApp

Function Main()
    sprite = New MyApp()
End Function

Class TColor
    Field r:Int,g:Int,b:Int
    Method Color()
        SetColor r,g,b
    End Method

    Method Set(rgb$)
        Self.r=255*(rgb[0]-48)/7
        Self.g=255*(rgb[1]-48)/7
        Self.b=255*(rgb[2]-48)/7
    End Method
End Class

Class MyApp Extends App
    Field pixel:Int[256]
    Field palette:TColor[16]

    Method OnCreate()
        SetUpdateRate 50

        For Local col:Int=0 To 15
            palette[col]=New TColor
            palette[col].Set "000333555777300520742764003025247467020040160370"[col*3..col*3+3]
        Next

        For Local t:Int=0 To 255
            pixel[t]=Rnd(16)
        Next
    End Method

    Method OnRender()
        Local i:Int
        For Local y:Int=0 To 15
            For Local x:Int=0 To 15
                palette[pixel[i]].Color
                DrawRect x*16,y*16,16,16
                i=i+1
            Next
        Next
    End Method

    Method OnUpdate()
    End Method
End Class