• Dear Cerberus X User!

    As we prepare to transition the forum ownership from Mike to Phil (TripleHead GmbH), we need your explicit consent to transfer your user data in accordance with our amended Terms and Rules in order to be compliant with data protection laws.

    Important: If you accept the amended Terms and Rules, you agree to the transfer of your user data to the future forum owner!

    Please read the new Terms and Rules below, check the box to agree, and click "Accept" to continue enjoying your Cerberus X Forum experience. The deadline for consent is April 5, 2024.

    Do not accept the amended Terms and Rules if you do not wish your personal data to be transferred to the future forum owner!

    Accepting ensures:

    - Continued access to your account with a short break for the actual transfer.

    - Retention of your data under the same terms.

    Without consent:

    - You don't have further access to your forum user account.

    - Your account and personal data will be deleted after April 5, 2024.

    - Public posts remain, but usernames indicating real identity will be anonymized. If you disagree with a fictitious name you have the option to contact us so we can find a name that is acceptable to you.

    We hope to keep you in our community and see you on the forum soon!

    All the best

    Your Cerberus X Team

Snippet Firepaint Mojo2

Wingnut

Well-known member
3rd Party Module Dev
Tutorial Author
Joined
Jan 2, 2020
Messages
1,414
Converted demo Firepaint into Mojo2 (complete 10x increase of performance in HTML5)

Cerberus:
' Firepaint redux!
'
' Really a multitouch test...

Import mojo2

Function Main()
    New Firepaint
End

Global BigList:=New List<Spark>

Class Firepaint Extends App

    Field canvas:Canvas
    Field sparkImage:Image
    Field sparks:=New List<Spark>
    Field prim
 
    Method OnCreate()
        For Local i = 0 Until 65536*16
'            BigList.AddLast New Spark
        Next
        sparkImage=Image.Load("bluspark.png",0.5,0.5,0)
        canvas = New Canvas()
        SetSwapInterval 1 ; SetUpdateRate 0
    End
 
    Method OnUpdate()
        Local out:=New List<Spark>
        For Local spark:=Eachin sparks
            spark.a=Max(spark.a-.01,0.0)
            If spark.a <= 0 Continue
            spark.yv += 0.05
            spark.x += spark.xv
            spark.y += spark.yv
            out.AddLast spark
        Next

        sparks=out
     
        For Local i = 0 Until 32
            If TouchDown(i)
                For Local j = 1 To 10
                    sparks.AddLast New Spark( TouchX(i),TouchY(i) )
                Next
            Endif
        Next
     
        If KeyHit(KEY_SPACE) Then prim = (prim + 1) Mod 4
     
    End
 
    Method OnRender()
        Local w = DeviceWidth,h = DeviceHeight
        canvas.SetBlendMode BlendMode.Additive ' LightenBlend in Mojo1
        canvas.Clear
        canvas.DrawText "This way UP!",0,0
        canvas.SetColor 1,0,0
        canvas.DrawRect 0,0,w,32
        canvas.SetColor 0,1,0
        canvas.DrawRect w-32,0,32,h
        canvas.SetColor 0,0,1
        canvas.DrawRect 0,h-32,w,32
        canvas.SetColor 0.5,0.5,0.5
        canvas.DrawRect 0,0,32,h
     
        For Local spark:=Eachin sparks
            canvas.SetAlpha spark.a
            Select prim
            Case 0
                canvas.DrawImage sparkImage,spark.x,spark.y
            Case 1
                canvas.DrawRect spark.x-15,spark.y-15,30,30
            Case 2
                canvas.DrawOval spark.x-15,spark.y-15,30,30
            Case 3
                canvas.DrawLine spark.x-15,spark.y-15,spark.x+15,spark.y+15
                canvas.DrawLine spark.x+15,spark.y-15,spark.x-15,spark.y+15
            End
        Next
        canvas.Flush
    End

End

Class Spark

    Field x#,y#,xv#,yv#,a#
 
    Method New( x#,y# )
        Self.x = x
        Self.y = y
        Local an# = Rnd(360),v# = Rnd(3,4)
        Self.xv = Cos(an) * v
        Self.yv = Sin(an) * v
        Self.a = 1
    End
 
End
 

Attachments

  • firepaint.zip
    5.9 KB · Views: 63
  • bluspark.png
    bluspark.png
    4.6 KB · Views: 79
Last edited:
yes, it is great to see how much the performance improves with mojo2.
 
Back
Top Bottom