Lissajous curve

Advanced game related topics
User avatar
Fig
Enthusiast
Enthusiast
Posts: 351
Joined: Thu Apr 30, 2009 5:23 pm
Location: Côtes d'Azur, France

Lissajous curve

Post by Fig »

Inspired by this video https://www.youtube.com/watch?v=4CbPksEl51Q&t=

It's hardly "game programming" material, but there is no "Demo" section, so...
Edit: I corrected the code, it's way better now. Modify #Res to make the screen wider and add circles...
Image

Code: Select all

#Res=600
#radius=30
#space=#radius*2+10
#nb=#Res/#space-1
;{ Screen init
If InitSprite() = 0 Or InitKeyboard() = 0 Or InitMouse() = 0:MessageRequester("Error", "Can't open the sprite system", 0):End:EndIf
If OpenWindow(0, 0, 0,#Res, #Res, "Lissajous Curve", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)=0:MessageRequester("Error", "Can't open windowed screen!", 0):EndIf
If OpenWindowedScreen(WindowID(0), 0, 0, #Res, #Res, 0, 0, 0)=0:MessageRequester("Error", "Can't open windowed screen!", 0):EndIf   
;}
Structure angle
    angle.f
    anglestep.f
    x.i
    y.i
    color.i
EndStructure
NewList angle.angle()
For i=1 To #nb
    AddElement(angle())
    angle()\angle=-#PI/2
    angle()\anglestep=0.01*i
    angle()\x=#radius
    angle()\y=#radius
    angle()\color=RGB(Random(255),Random(255),Random(255))
Next i
 
Structure pt
    x.i
    y.i
    color.i
EndStructure
NewList pt.pt()
CreateSprite(0,#Res,#Res)
StartDrawing(SpriteOutput(0))
i=1
ForEach angle()
    Circle(angle()\x+i*#space,angle()\y,#radius,angle()\color)
    Circle(angle()\x+i*#space,angle()\y,#radius-2,#Black)
    Circle(angle()\x,angle()\y+i*#space,#radius,angle()\color)
    Circle(angle()\x,angle()\y+i*#space,#radius-2,#Black)
    i+1
Next
StopDrawing()
CopySprite(0,1)
CopySprite(1,2)
Repeat
    FlipBuffers()
    Repeat
        Event = WindowEvent()
        If event=#PB_Event_CloseWindow:End:EndIf
    Until Event = 0
    ExamineKeyboard()
    DisplaySprite(0,0,0)
    CopySprite(1,0)
    StartDrawing(SpriteOutput(0))
    i=1
    ForEach angle()
        x.f=#radius*Cos(angle()\angle)
        y.f=#radius*Sin(angle()\angle)
        angle()\x=x
        angle()\y=y
        Circle(x+#radius,#radius+y+i*#space,3,#White)
        Circle(#radius+x+i*#space,#radius+y,3,#White)
        LineXY(x+#radius,#radius+y+i*#space,#Res,#radius+y+i*#space,RGB(100,100,100))
        LineXY(#radius+x+i*#space,#radius+y,#radius+x+i*#space,#Res,RGB(100,100,100))
        angle()\angle+angle()\anglestep
        i+1
    Next
    j=1
    ForEach angle()
        x=angle()\x
        Color.i=angle()\color
        PushListPosition(angle())
        i=1
        ForEach angle()
            y=angle()\y          
            AddElement(pt())
            pt()\x=x+#radius+j*#space
            pt()\y=y+#radius+i*#space
            pt()\color=RGB((Red(angle()\color)+Red(color))/2,(Green(angle()\color)+Green(color))/2,(Blue(angle()\color)+Blue(color))/2)
            Circle(pt()\x,pt()\y,3,#White)
            i+1
        Next
        PopListPosition(angle())
        j+1
    Next
    StopDrawing()
    StartDrawing(SpriteOutput(1))
    ForEach(pt())
        ;Plot(pt()\x,pt()\y,pt()\color)
        Circle(pt()\x,pt()\y,1,pt()\color)
    Next
    StopDrawing()
    ClearList(pt())
    FirstElement(angle())
    If angle()\angle>2*#PI-#PI/2:angle()\angle=-#PI/2:CopySprite(2,1):EndIf
Until KeyboardPushed(#PB_Key_Escape)
Last edited by Fig on Fri Oct 05, 2018 10:36 pm, edited 7 times in total.
There are 2 methods to program bugless.
But only the third works fine.

Win10, Pb x64 5.71 LTS
User avatar
RSBasic
Moderator
Moderator
Posts: 1218
Joined: Thu Dec 31, 2009 11:05 pm
Location: Gernsbach (Germany)
Contact:

Re: Lissajous curve

Post by RSBasic »

Nice Image
Image
Image
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: Lissajous curve

Post by davido »

@Fig,
Delightful.
Thank you for sharing such nice example. :D
DE AA EB
Post Reply