Author Topic: Help with a Small Program  (Read 3293 times)

0 Members and 1 Guest are viewing this topic.

Offline Calloway

  • Newbie
  • Posts: 18
  • I still have Laser Disc...
    • View Profile
    • Calloway Sutton
Help with a Small Program
« on: February 03, 2019, 08:56:57 pm »
I have this old code (as in I don't know who made it or where it came from..) which I think I found on either the Wiki or an old post on the .net forum. Anyway, I wanted to just play around with it, so I made it kind of "responsive" like a website, I guess you could say. My question is how can I detect a mouse down over a certain area when the coordinates for that window will always be changing (due to it being re-sizable).
I've put some small text of where I want an Exit button to be, I just can't seem to figure out how to get it to act as a 'button'.


Maybe I'm just having a brain fart idk

Code: Text: [Select]
  1. _TITLE "Graph"
  2.  
  3. SCREEN _NEWIMAGE(1080, 720, 12)
  4. $RESIZE:ON
  5. $CHECKING:OFF
  6.  
  7. ' Origin in Cartesian coordinates. (Changes when mouse is clicked.)
  8. OriginX = -100
  9. OriginY = -100
  10.  
  11. ' Point of interest in Cartesian coordinates. (Changes while mouse moves.)
  12. x = _MOUSEX
  13. y = _MOUSEY
  14. IF x > 0 AND x < screenWidth AND y > 0 AND y < screenHeight THEN
  15.     GOSUB unconvert
  16.     OriginX = x
  17.     OriginY = y
  18. ELSE
  19.     ThePointX = 100
  20.     ThePointY = 100
  21. END IF
  22.  
  23. ' Main loop.
  24. DO: _LIMIT 60
  25.     DO WHILE _MOUSEINPUT
  26.         x = _MOUSEX
  27.         y = _MOUSEY
  28.         IF x > 0 AND x < screenWidth AND y > 0 AND y < screenHeight THEN
  29.  
  30.             GOSUB unconvert
  31.             ThePointX = x
  32.             ThePointY = y
  33.  
  34.             IF _MOUSEBUTTON(1) THEN
  35.                 IF _MOUSEY < -190 AND _MOUSEX < -110 AND _MOUSEX > -120 AND _MOUSEY > -220 THEN
  36.                     SYSTEM
  37.                 END IF
  38.                 x = _MOUSEX
  39.                 y = _MOUSEY
  40.                 GOSUB unconvert
  41.                 OriginX = x
  42.                 OriginY = y
  43.             END IF
  44.  
  45.         END IF
  46.         IF _RESIZE THEN
  47.             SCREEN _NEWIMAGE(_RESIZEWIDTH, _RESIZEHEIGHT, 256)
  48.             screenWidth = _RESIZEWIDTH
  49.             screenHeight = _RESIZEHEIGHT
  50.         END IF
  51.     LOOP
  52.     GOSUB DrawEverything
  53.  
  54. LOOP
  55.  
  56. SYSTEM 0
  57. $CHECKING:ON
  58. DrawEverything:
  59. CLS
  60. ' Make Cartesian grid.
  61. FOR x = OriginX TO screenWidth STEP 10
  62.     LINE (x, 0)-(x, screenHeight), 8
  63. NEXT
  64. FOR x = OriginX TO 0 STEP -10
  65.     LINE (x, 0)-(x, screenHeight), 8
  66. NEXT
  67. FOR y = OriginY TO screenHeight STEP 10
  68.     LINE (0, -y + screenHeight / 2)-(screenWidth, -y + screenHeight / 2), 8
  69. NEXT
  70. FOR y = OriginY TO -(screenHeight / 2) STEP -10
  71.     LINE (0, -y + screenHeight / 2)-(screenWidth, -y + screenHeight / 2), 8
  72. NEXT
  73. x = OriginX
  74. y = OriginY
  75. GOSUB convert
  76. LINE (0, y)-(screenWidth, y), 7
  77. LINE (x, 0)-(x, screenHeight), 7
  78. _PRINTSTRING (screenWidth - 8 * 6, y), "X-axis"
  79. _PRINTSTRING (x, 0), "Y-axis"
  80. _PRINTSTRING (x, y), "Origin"
  81. _PRINTSTRING (0, 0), "Exit"
  82. ' Draw the circle on which the position vector lives.
  83. Radius = SQR((ThePointX - OriginX) ^ 2 + (ThePointY - OriginY) ^ 2)
  84. x = OriginX
  85. y = OriginY
  86. GOSUB convert
  87. CIRCLE (x, y), Radius, 7
  88. ' Draw the vertical component.
  89. x = OriginX
  90. y = OriginY
  91. GOSUB convert
  92. x1 = x
  93. y1 = y
  94. x = ThePointX
  95. y = OriginY
  96. GOSUB convert
  97. x2 = x
  98. y2 = y
  99. LINE (x1, y1)-(x2, y2), 9
  100. LINE (x1, y1 + 1)-(x2, y2 + 1), 9
  101. LINE (x1, y1 - 1)-(x2, y2 - 1), 9
  102. ' Draw the horizontal component.
  103. x = ThePointX
  104. y = OriginY
  105. GOSUB convert
  106. x1 = x
  107. y1 = y
  108. x = ThePointX
  109. y = ThePointY
  110. GOSUB convert
  111. x2 = x
  112. y2 = y
  113. LINE (x1, y1)-(x2, y2), 4
  114. LINE (x1 - 1, y1)-(x2 - 1, y2), 4
  115. LINE (x1 + 1, y1)-(x2 + 1, y2), 4
  116. ' Draw position vector (aka the Hypotenuse).
  117. x = OriginX
  118. y = OriginY
  119. GOSUB convert
  120. x1 = x
  121. y1 = y
  122. x = ThePointX
  123. y = ThePointY
  124. GOSUB convert
  125. x2 = x
  126. y2 = y
  127. LINE (x1, y1)-(x2, y2), 10
  128. LINE (x1 + 1, y1)-(x2 + 1, y2), 10
  129. LINE (x1, y1 + 1)-(x2, y2 + 1), 10
  130. ' Write text.
  131. COLOR 7
  132. _PRINTSTRING (screenWidth - 250, 0), "-------Origin-------"
  133. _PRINTSTRING (screenWidth - 250, 15), "Cartesian/Polar/Qb64:"
  134. _PRINTSTRING (screenWidth - 250, 30), "X=0   , Y=0"
  135. _PRINTSTRING (screenWidth - 250, 45), "R=0   , Ang=undef"
  136. _PRINTSTRING (screenWidth - 250, 60), "x="
  137. _PRINTSTRING (screenWidth - 235, 60), STR$(OriginX + screenWidth / 2) + ", " + "y=" + STR$(-OriginY + screenHeight / 2)
  138. _PRINTSTRING (screenWidth - 250, 80), "-------Cursor-------"
  139. _PRINTSTRING (screenWidth - 250, 95), "Cartesian/Polar/Qb64:"
  140. _PRINTSTRING (screenWidth - 250, 110), "X=" + STR$(ThePointX - OriginX) + ", " + "Y=" + STR$(ThePointY - OriginY)
  141. ' Deal with radius calculation.
  142. Radius = SQR((ThePointX - OriginX) ^ 2 + (ThePointY - OriginY) ^ 2)
  143. IF Radius < .0001 THEN Radius = .0001
  144. _PRINTSTRING (screenWidth - 250, 130), "R=" + STR$(INT(Radius)) + ", " + "Ang=" + STR$(TheAngle)
  145. ' Deal with the anlge calculation.
  146. xdiff = ThePointX - OriginX
  147. ydiff = ThePointY - OriginY
  148. IF xdiff > 0 AND ydiff > 0 THEN ' First quadrant
  149.     TheAngle = INT((180 / 3.14159) * ATN(ydiff / xdiff))
  150. END IF
  151. IF xdiff < 0 AND ydiff > 0 THEN ' Second quadrant
  152.     TheAngle = 180 + INT((180 / 3.14159) * ATN(ydiff / xdiff))
  153. END IF
  154. IF xdiff < 0 AND ydiff < 0 THEN ' Third quadrant
  155.     TheAngle = 180 + INT((180 / 3.14159) * ATN(ydiff / xdiff))
  156. END IF
  157. IF xdiff > 0 AND ydiff < 0 THEN ' Fourth quadrant
  158.     TheAngle = 360 + INT((180 / 3.14159) * ATN(ydiff / xdiff))
  159. END IF
  160. IF SQR(ydiff ^ 2) < .0001 THEN ydiff = .0001
  161. IF SQR(xdiff ^ 2) < .0001 THEN xdiff = .0001
  162. _PRINTSTRING (screenWidth - 250, 145), "x=" + STR$(ThePointX + 320) + ", " + "y=" + STR$(-ThePointY + 240)
  163. _PRINTSTRING (screenWidth - 250, 200), "--------Trig--------"
  164. _PRINTSTRING (screenWidth - 250, 215), "sin(Ang)=" + "Opp" + "/" + "Hyp"
  165. _PRINTSTRING (screenWidth - 250, 230), "        =" + STR$(ydiff / Radius)
  166. _PRINTSTRING (screenWidth - 250, 245), "cos(Ang)=" + "Adj" + "/" + "Hyp"
  167. _PRINTSTRING (screenWidth - 250, 260), "        =" + STR$(xdiff / Radius)
  168. _PRINTSTRING (screenWidth - 250, 275), "tan(Ang)=" + "Opp" + "/" + "Adj"
  169. _PRINTSTRING (screenWidth - 250, 290), "        =" + STR$(ydiff / xdiff)
  170. _DISPLAY
  171. RETURN
  172.  
  173. convert:
  174. ' Converts Cartesian coordinates to QB64 coordinates.
  175. x0 = x: y0 = y
  176. x = x0 + screenWidth / 2
  177. y = -y0 + screenHeight / 2
  178. RETURN
  179.  
  180. unconvert:
  181. ' Converts QB64 coordinates to Cartesian coordinates.
  182. x0 = x: y0 = y
  183. x = x0 - screenWidth / 2
  184. y = -y0 + screenHeight / 2
  185. RETURN
  186.  

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Help with a Small Program
« Reply #1 on: February 03, 2019, 09:08:32 pm »
Like this?
Code: QB64: [Select]
  1. _TITLE "Graph"
  2.  
  3. SCREEN _NEWIMAGE(1080, 720, 12)
  4.  
  5. ' Origin in Cartesian coordinates. (Changes when mouse is clicked.)
  6. OriginX = -100
  7. OriginY = -100
  8.  
  9. ' Point of interest in Cartesian coordinates. (Changes while mouse moves.)
  10. IF x > 0 AND x < screenWidth AND y > 0 AND y < screenHeight THEN
  11.     GOSUB unconvert
  12.     OriginX = x
  13.     OriginY = y
  14.     ThePointX = 100
  15.     ThePointY = 100
  16.  
  17. ' Main loop.
  18.         x = _MOUSEX
  19.         y = _MOUSEY
  20.         mb = _MOUSEBUTTON(1) 'left
  21.         IF x > 0 AND x < 65 AND y > 0 AND y < 17 AND mb THEN '<<<<<<<<<<<<<<<<<<<<<<<<<<< add exit click
  22.             CLS: END
  23.         ELSEIF x > 0 AND x < screenWidth AND y > 0 AND y < screenHeight THEN
  24.  
  25.             GOSUB unconvert
  26.             ThePointX = x
  27.             ThePointY = y
  28.  
  29.             IF _MOUSEBUTTON(1) THEN
  30.                 IF _MOUSEY < -190 AND _MOUSEX < -110 AND _MOUSEX > -120 AND _MOUSEY > -220 THEN
  31.                     SYSTEM
  32.                 END IF
  33.                 x = _MOUSEX
  34.                 y = _MOUSEY
  35.                 GOSUB unconvert
  36.                 OriginX = x
  37.                 OriginY = y
  38.             END IF
  39.  
  40.         END IF
  41.         IF _RESIZE THEN
  42.             SCREEN _NEWIMAGE(_RESIZEWIDTH, _RESIZEHEIGHT, 256)
  43.             screenWidth = _RESIZEWIDTH
  44.             screenHeight = _RESIZEHEIGHT
  45.         END IF
  46.     LOOP
  47.     GOSUB DrawEverything
  48.  
  49.  
  50. DrawEverything:
  51. ' Make Cartesian grid.
  52. FOR x = OriginX TO screenWidth STEP 10
  53.     LINE (x, 0)-(x, screenHeight), 8
  54. FOR x = OriginX TO 0 STEP -10
  55.     LINE (x, 0)-(x, screenHeight), 8
  56. FOR y = OriginY TO screenHeight STEP 10
  57.     LINE (0, -y + screenHeight / 2)-(screenWidth, -y + screenHeight / 2), 8
  58. FOR y = OriginY TO -(screenHeight / 2) STEP -10
  59.     LINE (0, -y + screenHeight / 2)-(screenWidth, -y + screenHeight / 2), 8
  60. x = OriginX
  61. y = OriginY
  62. GOSUB convert
  63. LINE (0, y)-(screenWidth, y), 7
  64. LINE (x, 0)-(x, screenHeight), 7
  65. _PRINTSTRING (screenWidth - 8 * 6, y), "X-axis"
  66. _PRINTSTRING (x, 0), "Y-axis"
  67. _PRINTSTRING (x, y), "Origin"
  68. _PRINTSTRING (0, 0), "Exit"
  69. ' Draw the circle on which the position vector lives.
  70. Radius = SQR((ThePointX - OriginX) ^ 2 + (ThePointY - OriginY) ^ 2)
  71. x = OriginX
  72. y = OriginY
  73. GOSUB convert
  74. CIRCLE (x, y), Radius, 7
  75. ' Draw the vertical component.
  76. x = OriginX
  77. y = OriginY
  78. GOSUB convert
  79. x1 = x
  80. y1 = y
  81. x = ThePointX
  82. y = OriginY
  83. GOSUB convert
  84. x2 = x
  85. y2 = y
  86. LINE (x1, y1)-(x2, y2), 9
  87. LINE (x1, y1 + 1)-(x2, y2 + 1), 9
  88. LINE (x1, y1 - 1)-(x2, y2 - 1), 9
  89. ' Draw the horizontal component.
  90. x = ThePointX
  91. y = OriginY
  92. GOSUB convert
  93. x1 = x
  94. y1 = y
  95. x = ThePointX
  96. y = ThePointY
  97. GOSUB convert
  98. x2 = x
  99. y2 = y
  100. LINE (x1, y1)-(x2, y2), 4
  101. LINE (x1 - 1, y1)-(x2 - 1, y2), 4
  102. LINE (x1 + 1, y1)-(x2 + 1, y2), 4
  103. ' Draw position vector (aka the Hypotenuse).
  104. x = OriginX
  105. y = OriginY
  106. GOSUB convert
  107. x1 = x
  108. y1 = y
  109. x = ThePointX
  110. y = ThePointY
  111. GOSUB convert
  112. x2 = x
  113. y2 = y
  114. LINE (x1, y1)-(x2, y2), 10
  115. LINE (x1 + 1, y1)-(x2 + 1, y2), 10
  116. LINE (x1, y1 + 1)-(x2, y2 + 1), 10
  117. ' Write text.
  118. _PRINTSTRING (screenWidth - 250, 0), "-------Origin-------"
  119. _PRINTSTRING (screenWidth - 250, 15), "Cartesian/Polar/Qb64:"
  120. _PRINTSTRING (screenWidth - 250, 30), "X=0   , Y=0"
  121. _PRINTSTRING (screenWidth - 250, 45), "R=0   , Ang=undef"
  122. _PRINTSTRING (screenWidth - 250, 60), "x="
  123. _PRINTSTRING (screenWidth - 235, 60), STR$(OriginX + screenWidth / 2) + ", " + "y=" + STR$(-OriginY + screenHeight / 2)
  124. _PRINTSTRING (screenWidth - 250, 80), "-------Cursor-------"
  125. _PRINTSTRING (screenWidth - 250, 95), "Cartesian/Polar/Qb64:"
  126. _PRINTSTRING (screenWidth - 250, 110), "X=" + STR$(ThePointX - OriginX) + ", " + "Y=" + STR$(ThePointY - OriginY)
  127. ' Deal with radius calculation.
  128. Radius = SQR((ThePointX - OriginX) ^ 2 + (ThePointY - OriginY) ^ 2)
  129. IF Radius < .0001 THEN Radius = .0001
  130. _PRINTSTRING (screenWidth - 250, 130), "R=" + STR$(INT(Radius)) + ", " + "Ang=" + STR$(TheAngle)
  131. ' Deal with the anlge calculation.
  132. xdiff = ThePointX - OriginX
  133. ydiff = ThePointY - OriginY
  134. IF xdiff > 0 AND ydiff > 0 THEN ' First quadrant
  135.     TheAngle = INT((180 / 3.14159) * ATN(ydiff / xdiff))
  136. IF xdiff < 0 AND ydiff > 0 THEN ' Second quadrant
  137.     TheAngle = 180 + INT((180 / 3.14159) * ATN(ydiff / xdiff))
  138. IF xdiff < 0 AND ydiff < 0 THEN ' Third quadrant
  139.     TheAngle = 180 + INT((180 / 3.14159) * ATN(ydiff / xdiff))
  140. IF xdiff > 0 AND ydiff < 0 THEN ' Fourth quadrant
  141.     TheAngle = 360 + INT((180 / 3.14159) * ATN(ydiff / xdiff))
  142. IF SQR(ydiff ^ 2) < .0001 THEN ydiff = .0001
  143. IF SQR(xdiff ^ 2) < .0001 THEN xdiff = .0001
  144. _PRINTSTRING (screenWidth - 250, 145), "x=" + STR$(ThePointX + 320) + ", " + "y=" + STR$(-ThePointY + 240)
  145. _PRINTSTRING (screenWidth - 250, 200), "--------Trig--------"
  146. _PRINTSTRING (screenWidth - 250, 215), "sin(Ang)=" + "Opp" + "/" + "Hyp"
  147. _PRINTSTRING (screenWidth - 250, 230), "        =" + STR$(ydiff / Radius)
  148. _PRINTSTRING (screenWidth - 250, 245), "cos(Ang)=" + "Adj" + "/" + "Hyp"
  149. _PRINTSTRING (screenWidth - 250, 260), "        =" + STR$(xdiff / Radius)
  150. _PRINTSTRING (screenWidth - 250, 275), "tan(Ang)=" + "Opp" + "/" + "Adj"
  151. _PRINTSTRING (screenWidth - 250, 290), "        =" + STR$(ydiff / xdiff)
  152.  
  153. convert:
  154. ' Converts Cartesian coordinates to QB64 coordinates.
  155. x0 = x: y0 = y
  156. x = x0 + screenWidth / 2
  157. y = -y0 + screenHeight / 2
  158.  
  159. unconvert:
  160. ' Converts QB64 coordinates to Cartesian coordinates.
  161. x0 = x: y0 = y
  162. x = x0 - screenWidth / 2
  163. y = -y0 + screenHeight / 2
  164.  
  165.  

That's cool how you are moving the origin around.
« Last Edit: February 03, 2019, 09:10:14 pm by bplus »

Offline Calloway

  • Newbie
  • Posts: 18
  • I still have Laser Disc...
    • View Profile
    • Calloway Sutton
Re: Help with a Small Program
« Reply #2 on: February 03, 2019, 09:13:36 pm »
Thank you haha you also showed me theres an error in my code, the QB64 coordinates displayed are very off

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Help with a Small Program
« Reply #3 on: February 03, 2019, 10:13:18 pm »
I could give you an ASM solution, or would that be push-ing your buttons?

That's a good looking graph program, Callaway.

Nice job on fixing it, Mark.

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
    • View Profile
Re: Help with a Small Program
« Reply #4 on: February 03, 2019, 10:27:45 pm »
Hi guys.

So this program was originally written by a jerk named STxAxTIC.

My original version has no errors in the coordinate systems, so unless you heavily edited something, it is probably still correct. The whole thing about QBasic and coordinates is that the system it uses is a completely wonkey analog of the Cartesian system, and all it does is hinder a person's understanding of trigonometry, especially if they try to learn it from a program. Anyway, have fun with this code, I don't claim any ownership.

For the sake of history, here's the version I have floating around:
Code: QB64: [Select]
  1.  
  2. ' Origin in Cartesian coordinates. (Changes when mouse is clicked.)
  3. OriginX = -100
  4. OriginY = -100
  5.  
  6. ' Point of interest in Cartesian coordinates. (Changes while mouse moves.)
  7. IF x > 0 AND x < 640 AND y > 0 AND y < 480 THEN
  8.     GOSUB unconvert
  9.     OriginX = x
  10.     OriginY = y
  11.     ThePointX = 100
  12.     ThePointY = 100
  13.  
  14. ' Main loop.
  15.         x = _MOUSEX
  16.         y = _MOUSEY
  17.         IF x > 0 AND x < 640 AND y > 0 AND y < 480 THEN
  18.  
  19.             GOSUB unconvert
  20.             ThePointX = x
  21.             ThePointY = y
  22.  
  23.             IF _MOUSEBUTTON(1) THEN
  24.                 x = _MOUSEX
  25.                 y = _MOUSEY
  26.                 GOSUB unconvert
  27.                 OriginX = x
  28.                 OriginY = y
  29.             END IF
  30.  
  31.         END IF
  32.     LOOP
  33.     GOSUB DrawEverything
  34.  
  35.  
  36.  
  37. DrawEverything:
  38. ' Make Cartesian grid.
  39. FOR x = OriginX TO 640 STEP 10
  40.     LINE (x, 0)-(x, 480), 8
  41. FOR x = OriginX TO 0 STEP -10
  42.     LINE (x, 0)-(x, 480), 8
  43. FOR y = OriginY TO 480 STEP 10
  44.     LINE (0, -y + 240)-(640, -y + 240), 8
  45. FOR y = OriginY TO -240 STEP -10
  46.     LINE (0, -y + 240)-(640, -y + 240), 8
  47. x = OriginX
  48. y = OriginY
  49. GOSUB convert
  50. LINE (0, y)-(640, y), 7
  51. LINE (x, 0)-(x, 480), 7
  52. _PRINTSTRING (640 - 8 * 6, y), "X-axis"
  53. _PRINTSTRING (x, 0), "Y-axis"
  54. _PRINTSTRING (x, y), "Origin"
  55. ' Draw the circle on which the position vector lives.
  56. Radius = SQR((ThePointX - OriginX) ^ 2 + (ThePointY - OriginY) ^ 2)
  57. x = OriginX
  58. y = OriginY
  59. GOSUB convert
  60. CIRCLE (x, y), Radius, 7
  61. ' Draw the vertical component.
  62. x = OriginX
  63. y = OriginY
  64. GOSUB convert
  65. x1 = x
  66. y1 = y
  67. x = ThePointX
  68. y = OriginY
  69. GOSUB convert
  70. x2 = x
  71. y2 = y
  72. LINE (x1, y1)-(x2, y2), 9
  73. LINE (x1, y1 + 1)-(x2, y2 + 1), 9
  74. LINE (x1, y1 - 1)-(x2, y2 - 1), 9
  75. ' Draw the horizontal component.
  76. x = ThePointX
  77. y = OriginY
  78. GOSUB convert
  79. x1 = x
  80. y1 = y
  81. x = ThePointX
  82. y = ThePointY
  83. GOSUB convert
  84. x2 = x
  85. y2 = y
  86. LINE (x1, y1)-(x2, y2), 4
  87. LINE (x1 - 1, y1)-(x2 - 1, y2), 4
  88. LINE (x1 + 1, y1)-(x2 + 1, y2), 4
  89. ' Draw position vector (aka the Hypotenuse).
  90. x = OriginX
  91. y = OriginY
  92. GOSUB convert
  93. x1 = x
  94. y1 = y
  95. x = ThePointX
  96. y = ThePointY
  97. GOSUB convert
  98. x2 = x
  99. y2 = y
  100. LINE (x1, y1)-(x2, y2), 10
  101. LINE (x1 + 1, y1)-(x2 + 1, y2), 10
  102. LINE (x1, y1 + 1)-(x2, y2 + 1), 10
  103. ' Write text.
  104. LOCATE 1, 60: PRINT "-------Origin-------"
  105. LOCATE 2, 60: PRINT "Cartesian/Polar/Qb64:"
  106. LOCATE 3, 61: PRINT "X=0   , Y=0"
  107. LOCATE 4, 61: PRINT "R=0   , Ang=undef"
  108. LOCATE 5, 61: PRINT "x="; OriginX + 320; ", "; "y="; -OriginY + 240
  109. LOCATE 7, 60: PRINT "-------Cursor-------"
  110. LOCATE 8, 60: PRINT "Cartesian/Polar/Qb64:"
  111. LOCATE 9, 61: PRINT "X="; ThePointX - OriginX; ", "; "Y="; ThePointY - OriginY
  112. ' Deal with radius calculation.
  113. Radius = SQR((ThePointX - OriginX) ^ 2 + (ThePointY - OriginY) ^ 2)
  114. IF Radius < .0001 THEN Radius = .0001
  115. LOCATE 10, 61: PRINT "R="; INT(Radius); ", "; "Ang="; TheAngle
  116. ' Deal with the anlge calculation.
  117. xdiff = ThePointX - OriginX
  118. ydiff = ThePointY - OriginY
  119. IF xdiff > 0 AND ydiff > 0 THEN ' First quadrant
  120.     TheAngle = INT((180 / 3.14159) * ATN(ydiff / xdiff))
  121. IF xdiff < 0 AND ydiff > 0 THEN ' Second quadrant
  122.     TheAngle = 180 + INT((180 / 3.14159) * ATN(ydiff / xdiff))
  123. IF xdiff < 0 AND ydiff < 0 THEN ' Third quadrant
  124.     TheAngle = 180 + INT((180 / 3.14159) * ATN(ydiff / xdiff))
  125. IF xdiff > 0 AND ydiff < 0 THEN ' Fourth quadrant
  126.     TheAngle = 360 + INT((180 / 3.14159) * ATN(ydiff / xdiff))
  127. IF SQR(ydiff ^ 2) < .0001 THEN ydiff = .0001
  128. IF SQR(xdiff ^ 2) < .0001 THEN xdiff = .0001
  129. LOCATE 11, 61: PRINT "x="; ThePointX + 320; ", "; "y="; -ThePointY + 240
  130. LOCATE 13, 60: PRINT "--------Trig--------"
  131. LOCATE 14, 61: PRINT "sin(Ang)=";: COLOR 4: PRINT "Opp";: COLOR 7: PRINT "/";: COLOR 10: PRINT "Hyp";: COLOR 7
  132. LOCATE 15, 61: PRINT "        ="; USING "##.###"; ydiff / Radius
  133. LOCATE 16, 61: PRINT "cos(Ang)=";: COLOR 9: PRINT "Adj";: COLOR 7: PRINT "/";: COLOR 10: PRINT "Hyp";: COLOR 7
  134. LOCATE 17, 61: PRINT "        ="; USING "##.###"; xdiff / Radius
  135. LOCATE 18, 61: PRINT "tan(Ang)=";: COLOR 4: PRINT "Opp";: COLOR 7: PRINT "/";: COLOR 9: PRINT "Adj";: COLOR 7
  136. f = ydiff / xdiff
  137. IF f < 9999.99 AND f > -9999.99 THEN
  138.     LOCATE 19, 61: PRINT "        ="; USING "####.###"; f
  139.  
  140. convert:
  141. ' Converts Cartesian coordinates to QB64 coordinates.
  142. x0 = x: y0 = y
  143. x = x0 + 320
  144. y = -y0 + 240
  145.  
  146. unconvert:
  147. ' Converts QB64 coordinates to Cartesian coordinates.
  148. x0 = x: y0 = y
  149. x = x0 - 320
  150. y = -y0 + 240
  151.  
« Last Edit: February 03, 2019, 10:30:16 pm by STxAxTIC »
You're not done when it works, you're done when it's right.