• 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 Lense effect

Wingnut

Well-known member
3rd Party Module Dev
Tutorial Author
Joined
Jan 2, 2020
Messages
1,414
A lense effect using mojo2.

Code:
Import mojo2

Function Main:Int()
    New Game()
End Function

Class Point

    Field x:Float
    Field y:Float

    Method New(tX:Float,tY:Float)
        x = tX
        y = tY
    End

End

Class Game Extends App

    Field myimage:Image
    Field canvas:Canvas
    Field k:Float = 0.0001
    Field cX:Int
    Field cY:Int
    Field p:Point[][]
    Const WIDTH:Int = 256
    Const HEIGHT:Int = 256
    Const GAP:Int = 2

    Method OnCreate:Int()
        SetSwapInterval 1
        SetUpdateRate 0
        SetDeviceWindow 640,480,4
        canvas=New Canvas
        myimage=Image.Load("monalisa.png",0,0,0)
        p = New Point[WIDTH][]
        For Local i:Int = 0 Until WIDTH
            p[i] = New Point[HEIGHT]
            For Local j:Int = 0 Until HEIGHT
                p[i][j] = New Point(i * GAP,j * GAP)
            Next
        Next
        Return 0           
    End Method

    Method OnUpdate:Int()
        cX = MouseX()
        cY = MouseY()
        Return 0
    End Method

    Method OnRender:Int()
        canvas.Clear 0,0,0
        canvas.SetAlpha 1.0
        canvas.SetColor 1,1,1
        For Local i:Int = 0 Until WIDTH
            For Local j:Int = 0 Until HEIGHT
                Local pX:Float = getRadialX(p[i][j].x,p[i][j].y,cX,cY,k)
                Local pY:Float = getRadialY(p[i][j].x,p[i][j].y,cX,cY,k)       
           '    canvas.DrawPoint pX,pY
                canvas.DrawRect pX,pY,1,1,myimage,i,j,1,1
            Next
        Next
        canvas.Flush
        Return 0       
    End Method

    Method getRadialX:Float(x:Float,y:Float,cx:Float,cy:Float,k:Float)
      Local res:Float = x+((x-cx)*k*((x-cx)*(x-cx)+(y-cy)*(y-cy)));
      Return res;
    End Method

    Method getRadialY:Float(x:Float,y:Float,cx:Float,cy:Float,k:Float)
      Local res:Float = y+((y-cy)*k*((x-cx)*(x-cx)+(y-cy)*(y-cy)));
      Return res
    End Method

End Class

Screenshot 2020-07-11 at 19.01.01.png
 
Last edited:
I would suggest the removal of the image of the Mona Lisa png. That is unless you were physically there and took the picture yourself. Some museums tend to get rather annoyed distributing unauthorised copies. Even though the original picture it's self would be public domain, with the artist being long gone and copyright laws being introduced long after the original work was completed. Any reproduction would be copyright by the person or organisation that had commissioned any such reproduction.
 
Sure I'll throw it away.
 
Batteries not included.
 
This short video shows the concept how it works
 
Back
Top Bottom