POLAR COORDINATE DEMO BY GUY CANIDA
gfcanida@swing.be

Home

Data Validation and Error Trapping
Tipcorner - binary file access
Updating the Open Source Editor
Spotlight on Polar Coordinates
polar1.bas by Nally
atari2.bas by Nally
polar coordinate demo

Thanks for a wonderful polar coordinate demo, Guy!!


Demo to easy understand use of polar coordinates

'
     ' Guy Canida March 31, 2002
     '
     ' Just run it and follow instructions nomainwin
     ' Set up main window
     BackgroundColor$ = "blue"
     WindowWidth = 540
     WindowHeight = 385
     UpperLeftX = 50
     UpperLeftY = 50
     pi=3.141592
     centerx=150:centery=150
     radius=100
     open "Polar Coordinates in Motion" for window_popup as #m
     call message " Just click when told", 4000
 ' box for explanation
 BackgroundColor$ = "white"
     ForegroundColor$ = "blue"
     WindowWidth = 180
     WindowHeight = 330
     UpperLeftX = 390
     UpperLeftY = 75
     graphicbox #t.txt, 0, 0, 250, 350
     open " " for window_popup as #t
     print #t.txt, " fill white ; color yellow ; backcolor yellow ; down ;      size 2"
     print #t.txt, "place 30 210":print #t.txt, "piefilled 90 90      0 -30" ' angle
     print #t.txt, "color black ; place 60 200":print #t.txt, "\a"
     print #t.txt, "color darkcyan ; backcolor white"
     print #t.txt, "line 10 210 170 210" ' x axis
     print #t.txt, "line 30 60 30 240" ' y axis
     print #t.txt, "color red ; line 150 110 150 210" ' Y
     print #t.txt, "place 155 165":print #t.txt, "\Y"
     print #t.txt, "color blue ; line 30 110 150 110" ' X
     print #t.txt, "place 85 225":print #t.txt, "\X"
     print #t.txt, "color black ; line 30 210 150 110" ' R
     print #t.txt, "place 70 165":print #t.txt, "\R"
     print #t.txt, "place 45 245":print #t.txt, "\ 2 2 2"
     print #t.txt, "place 45 256":print #t.txt, "\ X + Y = R"
     print #t.txt, "place 45 276":print #t.txt, "\ X=R*COS(a)"
     print #t.txt, "place 45 296":print #t.txt, "\ Y=R*SIN(a)"
 ' box for animated demo
 BackgroundColor$ = "white"
     ForegroundColor$ = "blue"
     WindowWidth = 310
     WindowHeight = 330
     UpperLeftX = 70
     UpperLeftY = 75
     graphicbox #1.po, 0,0,310,330
     open " " for window_popup as #1
     print #1.po, "fill white ; down ; size 2"
 ' popup message
     print #t.txt, "when leftButtonUp"
     print #1.po, "when leftButtonUp"
     call message "First, 2 axis , X Y coordinates", 3000
     print #1.po, "when leftButtonUp [endit]"
     print #t.txt, "when leftButtonUp [endit]"
 ' loop forever
 while pi=3.141592
 ' go around a full circle from x axis counter clockwise
 for degree=359 to 1 step -1
 if degree=325 then
     print #1.po, "when leftButtonUp"
     print #t.txt, "when leftButtonUp"
     call message " Click to end this", 2000
     print #t.txt, "when leftButtonUp [endit]"
     print #1.po, "when leftButtonUp [endit]"
     end if
 ' LB needs angles expressed in radian in trig functions
 radian=degree*pi/180
 print #1.po, "color darkcyan"
 x=centerx+radius*cos(radian)
     y=centery+radius*sin(radian)
 ' redraw image at angle=degree
 print #1.po, "backcolor white"
     print #1.po, "place ";centerx;" ";centery
     print #1.po, "circle ";radius+2
     print #1.po, "place 297 ";centery+3:print #1.po, "\>"
     print #1.po, "place 297 ";centery+17:print #1.po, "\X"
     print #1.po, "place ";centerx-4;" 18":print #1.po, "\^"
     print #1.po, "place ";centerx-15;" 18":print #1.po, "\Y"
     print #1.po, "line 10 ";centerx;" 300 ";centerx
     print #1.po, "line ";centery;" 10 ";centery;" 300"
 ' check in which quadrant we are to draw the pie that shows the angle
 quadrant=4-int(degree/90)
     select case quadrant
     case 1
     start=(quadrant-1)*90+1:at=degree-360
     case 2
     start=degree:at=180-degree
     case 3
     start=(quadrant-1)*90-1:at=degree-180
     case 4
     start=degree:at=degree*(-1)+3
     end select
 print #1.po, "place ";centerx;" ";centery
     print #1.po, "color yellow ; backcolor yellow; piefilled 90 91 ";start;"      ";at
     print #1.po, "color black ; line ";centerx;" ";centery;"      ";x;" ";" ";y ' radius
     print #1.po, "color red"
     print #1.po, "line ";x;" ";centery;" ";x;"      ";y ' cos(angle)
     print #1.po, "color blue"
     print #1.po, "line ";centerx;" ";y;" ";x;"      ";y ' sin(angle)
     print #1.po, "flush"
 ' for good animation, please adapt
 timer 15, [itHappened]
     wait
     [itHappened]
     timer 0
     print #1.po, "cls"
     next
     wend
     [endit]
 ' reset control and image for next step
 print #t.txt, "cls":print #1.po, "cls"
     print #1, "trapclose"
     print #1.po, "when leftButtonUp"
     print #t.txt, "when leftButtonUp"
     print #1.po, "backcolor white"
     call message "Now let'go polar coordinates", 3500
 ' set explanation of polar coordinates
 print #t.txt, "place 60 150"
     print #t.txt, "color yellow ; backcolor yellow ; piefilled 90 90 2 -30"
     print #t.txt, "color black ; place 80 145":print #t.txt, "\a"
     print #t.txt, "backcolor white ; color darkcyan ; size 1"
     print #t.txt, "line 30 150 150 150" ' X
     t=140
     z=150-80*sin(pi/4)
     print #t.txt, "color red ; size 1 ; line 60 150 ";t;" ";z
     print #t.txt, "place 105 110":print #t.txt, "\R"
     print #t.txt, "color blue ; line ";t;" 150 ";t;"      ";z
     print #t.txt, "place ";t+5;" 125":print #t.txt, "\Y"
     print #t.txt, "color black ; place 45 80":print #t.txt, "\      Y = R * SIN(a)"
     print #t.txt, "place 30 180":print #t.txt, "\Horizontal axis      is angle zero"
     print #t.txt, "place 30 200":print #t.txt, "\R can also be      a function"
     call message "Only one axis x and an angle", 3500
     print #1.po, "cls"
     print #1.po, "backcolor white ; color darkcyan ; size 1 ; line 10 ";centerx;"      300 ";centerx
     print #1.po, "place 297 ";centery+3:print #1.po, "\>"
     print #1.po, "place 297 ";centery+17:print #1.po, "\X"
 ' run polar coordinates demo
 for degree=269 to -90 step -1
     radian=degree*pi/180
     b=radius*cos(pi/4-radian)
     x=centerx+radius*cos(radian)
     y=centery+b*sin(radian)
     print #1.po, "color black ; size 1 ; line ";centerx;" ";centery;"      ";x;" ";" ";y ' radius
     print #1.po, "color red"
     c=(radius+3)*cos(pi/4-radian)
     t=centerx+(radius+3)*cos(radian)
     z=centery+c*sin(radian)
     print #1.po, "size 4 ; set ";t;" ";z
     print #1.po, "color darkcyan ; size 1 ; line 10 ";centerx;"      300 ";centerx
     print #1.po, "flush"
     timer 5, [itHappened2]
     wait
     [itHappened2]
     timer 0
     print #1.po, "color yellow ; line ";centerx;" ";centery;"      ";x;" ";" ";y ' radius
     next
     call message " Click to end it", 3500
     print #1.po, "when leftButtonUp [quit]"
     print #t.txt, "when leftButtonUp [quit]"
     timer 1200, [quit]
     wait
     [quit]
     timer 0
     call message "Guy Canida April 1st, 2002", 5000
     close #1:close #m:close #t
 ' popup message subroutine
 sub message msg$, time
     BackgroundColor$ = "white"
     ForegroundColor$ = "blue"
     UpperLeftX = 250
     UpperLeftY = 150
     WindowWidth = 150
     WindowHeight = 25
     TEXTBOX #0.text, 0, 0, 150, 25
     open " " for window_popup as #0
     print #0.text, "when leftButtonUp [itHappened2]"
     print #0.text, msg$
     timer time, [itHappened2]
     wait
     [itHappened2]
     timer 0
     close #0
     end sub
     end

Home

Data Validation and Error Trapping
Tipcorner - binary file access
Updating the Open Source Editor
Spotlight on Polar Coordinates
polar1.bas by Nally
atari2.bas by Nally
polar coordinate demo