Drawing a parable

Share your advanced PureBasic knowledge/code with the community.
Bonne_den_kule
Addict
Addict
Posts: 841
Joined: Mon Jun 07, 2004 7:10 pm

Drawing a parable

Post by Bonne_den_kule »

Code updated for 5.20+

Here is a code I made to draw a parable.
I have just learnt what a parable is at school, so there no advance math in this code, only pythagoras (a2+b2=c2).

Made it for fun and for learning.

PS: Can anyone translate my variable names to english?

Code: Select all

#WindowWidth=1024
#WindowHeight=800

Brennpunkt.COORD
Brennpunkt\x=#WindowWidth/2
Brennpunkt\y=#WindowHeight/2

Dim Styrelinje.COORD(1)
Styrelinje(0)\x=0
Styrelinje(0)\y=#WindowWidth/2
Styrelinje(1)\x=#WindowWidth
Styrelinje(1)\y=#WindowWidth/2

If OpenWindow(0, 100, 200, #WindowWidth, #WindowHeight, "Parabel tegning", #PB_Window_SystemMenu)

  If CreateImage(0, #WindowWidth, #WindowHeight)
    If StartDrawing(ImageOutput(0))
      LineXY(Styrelinje(0)\x,Styrelinje(0)\y,Styrelinje(1)\x,Styrelinje(1)\y, RGB(0,0,255))
      Plot(Brennpunkt\x,Brennpunkt\y,RGB(0,0,255))
      For x=1 To #WindowWidth
        For y=Styrelinje(0)\y+1 To 1 Step -1
          If Styrelinje(0)\y-y=Round(Sqr(Pow(Brennpunkt\x-x,2)+Pow(Brennpunkt\y-y,2)),0)
            Plot(x,y,RGB(0,0,255))
            Goto xloop
          EndIf
        Next y
        xloop:
      Next x
      StopDrawing()
    EndIf
  EndIf
  ; 

  ImageGadget(0, 0, 0, 0, 0, ImageID(0))
 
  Repeat
    EventID = WaitWindowEvent()
  Until EventID = #PB_Event_CloseWindow
 
EndIf
Sorry for my bad english