It is currently Mon Nov 18, 2019 7:13 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Lissajous curve
PostPosted: Thu Oct 04, 2018 8:28 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Thu Apr 30, 2009 5:23 pm
Posts: 306
Location: Côtes d'Azur, France
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:
#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)

_________________
There are 2 methods to program bugless.
But only the third works fine.

Win10, Pb x64 5.70 LTS


Last edited by Fig on Fri Oct 05, 2018 10:36 pm, edited 7 times in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: Lissajous curve
PostPosted: Thu Oct 04, 2018 8:30 am 
Offline
Moderator
Moderator
User avatar

Joined: Thu Dec 31, 2009 11:05 pm
Posts: 1106
Location: Germany::Berlin()
Nice Image

_________________
ImageImageImageImage Image


Top
 Profile  
Reply with quote  
 Post subject: Re: Lissajous curve
PostPosted: Fri Oct 05, 2018 5:56 am 
Offline
Addict
Addict

Joined: Fri Nov 09, 2012 11:04 pm
Posts: 1691
Location: Uttoxeter, UK
@Fig,
Delightful.
Thank you for sharing such nice example. :D

_________________
DE AA EB


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye