Author Topic: An old, lost tutorial  (Read 4968 times)

0 Members and 1 Guest are viewing this topic.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
An old, lost tutorial
« on: August 08, 2019, 04:03:05 pm »
Searching though my old drives (which I do every so often, looking for something or other, before I get distracted by "What was this??"), I stumbled across this old tutorial which I was working up for folks to help introduce them to various things in QB64. 

Someday soon(tm), now that I've remembered this, I really should get back to it once more, as it's now to the point where it starts addressing actual memory commands and various color modes for our programs.  As it is, it's still a rather long and informative tutorial about various things, which I thought I'd share and see if anybody was interested in adding anything to it, or just felt like offering their thoughts and feedback on the information/format contained within it.

Usage is rather simple:  Download, extract to the QB64 folder (or to its own subfolder for ease of clean up, if you have the "Save EXE with BAS file" option turned on in QB64), and then compile and run it.   Then tell me what you think of it; good or bad.  ;D
* Tutorial.7z (Filesize: 24.03 KB, Downloads: 237)
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: An old, lost tutorial
« Reply #1 on: August 08, 2019, 04:28:01 pm »
Of course very good!

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: An old, lost tutorial
« Reply #2 on: August 08, 2019, 04:45:31 pm »
Because I run with Linux, I had a minor font location issue but other than that, the program ran just fine. I have to go out and will check it out fully when I get back... ;
)
Logic is the beginning of wisdom.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: An old, lost tutorial
« Reply #3 on: August 08, 2019, 04:52:12 pm »
I recall seeing the lesson on Hex somewhere / when before. Hard to tell how helpful it is to someone new to counting in other bases, good intro and the more exposure the better for something like that.

I look forward to checking out the lessons on memory from a master.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: An old, lost tutorial
« Reply #4 on: August 09, 2019, 02:57:43 am »
And while the one above is a general Hex/Memory type tutorial, here's another old one I found, which helps explain a bit about SIN and COS in programming:

Code: QB64: [Select]
  1. ts = _NEWIMAGE(800, 6000, 32)
  2. ws = _NEWIMAGE(800, 600, 32)
  3.  
  4. COLOR _RGB32(255, 255, 0)
  5. CenterText 10, "Steve's Basic SIN/COS Demo/Tutorial for Programming"
  6. LOCATE 3, 1
  7. PRINT "First, let's go over what SIN and COS actually are.  A lot of people are completely mystified by"
  8. PRINT "these two basic math commands."
  9. PRINT "SIN and COS are nothing more than than a RATIO of the sides of a right triangle"
  10. PRINT "For example, take a look at the triangle below"
  11. LINE (200, 150)-(0, 250), _RGB32(255, 0, 0) 'Red
  12. LINE (0, 250)-(200, 250), _RGB32(0, 255, 0) 'Green
  13. LINE (200, 250)-(200, 150), _RGB32(0, 0, 255) 'Blue
  14.  
  15. COLOR _RGB32(255, 0, 0)
  16. LOCATE 11, 40: PRINT "The RED Line is the Hypotenuse"
  17. COLOR _RGB32(0, 255, 0)
  18. LOCATE 13, 40: PRINT "The GREEN Line is Adjacent to our angle"
  19. COLOR _RGB32(0, 0, 255)
  20. LOCATE 15, 40: PRINT "The BLUE Line is Opposite from our angle"
  21.  
  22. LOCATE 18, 1
  23. PRINT "If we look at the triangle above, we want to use the angle from the far left corner to get our SIN"
  24. PRINT "and COS ratios."
  25. PRINT "SINE (SIN) is basically nothing more than the ratio of the length of the side that is opposite that"
  26. PRINT "angle to the length of the longest side of the triangle (the Hypotenuse)."
  27. PRINT "Now, that might sound like a complex mouthful, but it's not as complicated as it seems."
  28. PRINT "Basically, in the image above, if we were to measure the length of the BLUE line and then DIVIDE it"
  29. PRINT "By the length of the RED line, we'd have the SINE value of our angle."
  30. PRINT "Opposite/ Hypotenuse = SINE  (or in this case, length of BLUE / length of RED = SINE)"
  31. PRINT "Now, image taking this triangle and making it bigger or larger.  DON'T change the angle, but expand"
  32. PRINT "the length and height of it in your imagination."
  33. PRINT "No matter how large you scale it, the RATIO of that opposite side and hypotenuse is ALWAYS going to"
  34. PRINT "be the same."
  35. COLOR _RGB32(255, 255, 0)
  36. PRINT "That RATIO of opposite side divided by hypotenuse IS what SINE (SIN) is."
  37. PRINT "And COSINE (COS) is nothing more than the ratio of the ADJACENT side divided by the hypotenuse."
  38. PRINT "Which, in the above triangle would be nothing more than the length of the GREEN line, divied by"
  39. PRINT "the length of the RED line."
  40. COLOR _RGB32(255, 255, 0)
  41. PRINT "That RATIO of adjacent side divided by hypotenuse IS what COSINE (COS) is."
  42. PRINT "No matter how much you scale that triangle, that RATIO between those sides is going to stay the same"
  43. PRINT "for that angle"
  44. PRINT "Now, let's say that my triangle has sides which are 3, 4, and 5 (units) long.  (If you're American,"
  45. PRINT "they can be inches.  Elsewhere, centimeters...)."
  46. PRINT "Now, obviously looking at my (not to scale) triangle above, the Opposite side would have to be the"
  47. PRINT "shortest at a length of 3.  The Adjacent side would have to be a little longer at a length of 4."
  48. PRINT "And the Hypotenuse would be the longest side with the height of 5)"
  49. PRINT "(Red Line = 5, Green Line = 3, Blue Line = 4 on the diagram above)"
  50. COLOR _RGB32(255, 255, 0)
  51. PRINT "So what would our SIN and COS be for the above triangle (with the imaginary figures provided)?"
  52. PRINT "SIN = Opposite / Hypotenuse, so that's 3/5 in this case (.6)"
  53. PRINT "COS = Adjacent / Hypotenuse, so that's 4/5 in this case (.8)"
  54. PRINT "And if we take a protractor (remember those from school?), we can measure the angle (for that"
  55. PRINT "imaginary triangle), and see that it is roughly 36.87 degrees."
  56. PRINT "So, if we use the computer to check our math, this is what it tells us:"
  57. PRINT "SIN = "; SIN(_D2R(36.87))
  58. PRINT "COS = "; COS(_D2R(36.87))
  59. PRINT "As you can see, our numbers aren't an EXACT match, but that's because I didn't use an EXACT figure"
  60. PRINT "for that angle.  The angle formed by a 3-4-5 triangle is actually closer to 36.86989764582773"
  61. PRINT "degrees, but who's counting that close?  (Except for the computer?) :P"
  62. COLOR _RGB32(255, 0, 255)
  63. CenterText 1250, "Press the <<RIGHT ARROW>> to go on to PART II: Using SIN/COS In Triangles"
  64. COLOR _RGB32(255, 255, 0)
  65. CenterText 1320, "PART II: Usine SIN/COS in triangles"
  66. PRINT "To briefly recap:"
  67. PRINT "SIN(angle) = Opposite / Hypotenuse"
  68. PRINT "COS(angle) = Adjacent / Hypotenuse"
  69. PRINT "Which all sounds good and such.  We now know HOW we get sine and cosine from an angle, but how"
  70. PRINT "the heck do we make use of it?"
  71. PRINT "First, let's look at a basic right triangle again.  (A right triangle is defined as having one"
  72. PRINT "side which is 90 degrees, as illustrated again below.)"
  73. LINE (400, 1650)-STEP(-20, -20), _RGB32(185, 185, 0), B
  74. LINE (400, 1550)-(300, 1650)
  75. LINE (300, 1650)-(400, 1650)
  76. LINE (400, 1550)-(400, 1650)
  77. COLOR _RGB32(255, 255, 0)
  78. _PRINTSTRING (396, 1530), "A"
  79. _PRINTSTRING (286, 1642), "B"
  80. _PRINTSTRING (404, 1642), "C"
  81. LOCATE 106, 1
  82. PRINT "As you can see, the angle at Point C is 90 degrees, so this is indeed a right triangle."
  83. PRINT "(I'd hate to work with wrong ones.  Last I heard, they got several years jail time!)"
  84. PRINT "So given two pieces of information for this triangle, can you figure out the rest?"
  85. PRINT "For example, let's pretend that this is a triangle with the longest side (hyptoenuse) being"
  86. PRINT "200 units long, and our angle at point B is 45 degrees."
  87. PRINT "What would the length of the other 2 sides be?"
  88. PRINT "Now, even though we all hate word problems, let's take a look at this one before we give up."
  89. PRINT "First, what's the side opposite of our given angle?"
  90. PRINT "(Looking at the illustration above, it'd be the line from A to C, correct?)"
  91. PRINT "Open up your calculator, and get ready to do some math!  (Or else you'll never learn...)"
  92. PRINT "Remember what we said about what SINE and COSINE was?"
  93. PRINT "SIN(angle) = Opposite / Hypotenuse"
  94. PRINT "COS(angle) = Adjacent / Hypotenuse"
  95. PRINT "So to find that side opposite our given angle, we'd need to multiple both sides by the"
  96. PRINT "Hypotenuse, so that we'd end up with basically the following:"
  97. PRINT "SIN(angle) * Hypotenuse = Opposite"
  98. PRINT "COS(angle) * Hypotenuse = Adjacent"
  99. COLOR _RGB32(125, 125, 125)
  100. PRINT "Remember why this works?  Think of our formula with actual numbers:"
  101. PRINT "6 = x / 2  <-- let's pretend this is our formula."
  102. PRINT "Now, if we multiply each side by 2, we'd end up getting:"
  103. PRINT " 6 * 2 = x / 2 * 2"
  104. PRINT "When you divide by a number and multiply by the same number, you get 1..."
  105. PRINT "Which simplifies down to:    6 * 2 = x (or our answer of 12 in this case)"
  106. PRINT "In this case, we can just plug in the 2 numbers we know and get the last one."
  107. PRINT "Our angle is 45 degrees."
  108. PRINT "Our Hypotenuse is 100 units in length."
  109. PRINT "What would the length of the opposite side be? See if you can figure it out with what we've went"
  110. PRINT "over above."
  111. COLOR _RGB32(125, 125, 125)
  112. PRINT "SIN(angle) * Hypotenuse = Opposite"
  113. PRINT "SIN(45) * 100 = Opposite"
  114. PRINT SIN(_D2R(45)) * 100; " = Opposite"
  115. PRINT "COS(angle) * Hypotenuse = Adjacent"
  116. PRINT "COS(45) * 100 = Adjacent"
  117. PRINT COS(_D2R(45)) * 100; " = Adjacent"
  118. PRINT "Does the numbers you have look similar to the ones above?"
  119. PRINT "Seems simple enough, but think of what we've just did..."
  120. PRINT "We took nothing more than a given angle and a side, and calculated the other sides of our triangle!"
  121. PRINT "CONGRATULATIONS!!  You're well on the way to understanding SIN and COS."
  122. PRINT "It's really not as complicated as some folks like to make it seem.  It's basically just"
  123. PRINT "a relationship between 3 things, and using 2 of those things to figure out the third..."
  124. COLOR _RGB32(255, 0, 255)
  125. CenterText 2770, "Press the <<RIGHT ARROW>> to go on to PART III: Using SIN/COS For Circles and Arcs"
  126. COLOR _RGB32(255, 255, 0)
  127. CenterText 2820, "PART III: Using SIN/COS for Circles and Arcs"
  128. PRINT "Now that we've discussed the basics about how we can use SIN and COS in triangles, just how the heck"
  129. PRINT "do we make them useful for circles?"
  130. CIRCLE (400, 3000), 100, _RGB32(255, 255, 0)
  131. PSET (400, 3000), _RGB32(255, 255, 0)
  132. PRINT "This is a standard QB64 circle."
  133. PRINT "The command to make this is:"
  134. PRINT "CIRCLE (x,y), radius, color"
  135. PRINT "Using the information above, we know a heck of a lot of information about this circle."
  136. PRINT "If you look at the source code for this program, you'll see our circle command is:"
  137. PRINT "CIRCLE (400,3000), 100, _RGB32(255,255,0)"
  138. PRINT "Which breaks down to the center being at the point 400,3000, the radius being 100 pixels, and the"
  139. PRINT "color being yellow."
  140. PRINT "But could we draw this circle manually, using SIN and COS?"
  141. PRINT "Of course!"
  142. PRINT "But how??"
  143. PRINT "Think back on our previous lesson..."
  144. PRINT "We take an angle and a side, and we calculate the length of the other 2 sides."
  145. PRINT "To make a circle, we basically make a 360 degree arc, correct?"
  146. PRINT "So this would give us a nice loop so we can plot a pixel at each degree:"
  147. PRINT "FOR angle = 1 to 360"
  148. PRINT "And we know what our radius would be, correct?  (It was 100, if you remember...)"
  149. PRINT "And using what we learned previously, what would the length of the opposite and adjacent sides"
  150. PRINT "of a triangle be with 45 degrees and a 100 unit hypotenuse??"
  151. COLOR _RGB32(125, 125, 125)
  152. PRINT "SIN(angle) * Hypotenuse = Opposite"
  153. PRINT "COS(angle) * Hypotenuse = Adjacent"
  154. PRINT "And how does this pertain to our CIRCLE, you ask...."
  155. PRINT "As you can see, we have a 45"
  156. PRINT "degree angle in this circle,"
  157. PRINT "as illustrated here."
  158. CIRCLE (400, 3750), 100, _RGB32(255, 255, 255)
  159. LINE (250, 3750)-STEP(300, 0), _RGB32(125, 125, 0)
  160. LINE (400, 3600)-STEP(0, 300), _RGB32(125, 125, 0)
  161. x = SIN(_D2R(45)) * 100
  162. y = -COS(_D2R(45)) * 100
  163. COLOR _RGB32(255, 0, 0)
  164. LINE (400, 3750)-STEP(x, y)
  165. LINE STEP(0, 0)-STEP(0, -y)
  166. LINE STEP(0, 0)-STEP(-x, 0)
  167. _PRINTSTRING (390, 3740), "A"
  168. _PRINTSTRING (420, 3700), "R"
  169. _PRINTSTRING (435, 3752), "x"
  170. _PRINTSTRING (480, 3708), "y"
  171. PRINT "Now, for Angle A, with Radius R"
  172. PRINT "What is the length of the other"
  173. PRINT "two sides?"
  174. COLOR _RGB32(125, 125, 125)
  175. PRINT "SIN(angle) * Hypotenuse = Opposite"
  176. PRINT "COS(angle) * Hypotenuse = Adjacent"
  177. PRINT "So, let's plug in what we know to these 2 sets of equations:"
  178. PRINT "x is ADJACENT to our angle A."
  179. PRINT "y is OPPOSITE to our angle A."
  180. PRINT "Our Hypotenuse is 100 pixels in size.  (R)"
  181. PRINT "The angle A that we're using here is 45 degrees"
  182. PRINT "SIN(45) * 100 = Opposite (or y in this case)"
  183. PRINT "COS(45) * 100 = Adjacent (or x in this case)"
  184. PRINT "X = "; INT(SIN(_D2R(45)) * 100)
  185. PRINT "Y = "; INT(COS(_D2R(45)) * 100)
  186. PRINT "And what does this tell us about this single point on our circle??"
  187. PRINT "That when we have a radius of 100 pixels, the point at 45 degrees is going to be 70 pixels above"
  188. PRINT "and 70 pixels right of the center!"
  189. PRINT "But this just gives us a single point on the circle, for where 45 degrees would be..."
  190. PRINT "But never fear!  We can apply the exact same logic and math to get ANY point on our circle!!"
  191. PRINT "Try it out yourself, in your head.   Change that angle to 30 degrees.  The radius is going to stay"
  192. PRINT "the same, as it's consistent with a circle (or else you don't have a circle), but using the"
  193. PRINT "above method, we can find ANY point on our circle..."
  194. PRINT "So to do a complete circle, we might code the following:"
  195. PRINT "FOR angle = 1 to 360 '1 point on the circle for each degree"
  196. PRINT "    x = SIN(_D2R(angle)) * Radius 'we have to convert degree to radian for computer math, thus _D2R"
  197. PRINT "    y = COS(_D2R(angle)) * Radius"
  198. PRINT "    PSET (x,y)"
  199. PRINT "NEXT"
  200. COLOR _RGB32(255, 0, 0)
  201. PRINT "And we don't make a circle!!"
  202. PRINT "ARGH!!  Why the heck is he teaching us how to NOT make a circle?"
  203. PRINT "WHY didn't that make a circle??"
  204.  
  205. clip$ = "SCREEN 12" + CHR$(10) + "COLOR 4" + CHR$(10) + "Radius = 50" + CHR$(10)
  206. clip$ = clip$ + "FOR angle = 1 TO 360 '1 point on the circle for each degree" + CHR$(10)
  207. clip$ = clip$ + "x = SIN(_D2R(angle)) * Radius 'we have to convert degree to radian for computer math, thus _D2R" + CHR$(10)
  208. clip$ = clip$ + "y = COS(_D2R(angle)) * Radius" + CHR$(10)
  209. clip$ = clip$ + "PSET (x, y)" + CHR$(10)
  210. clip$ = clip$ + "NEXT"
  211. _CLIPBOARD$ = clip$
  212. PRINT "If you're using a Windows machine to run this, open a second version of QB64 and test it out"
  213. PRINT "for yourself."
  214. PRINT "I've made the process as simple as possible:  Just open a new QB64 window, hit Ctrl-V to paste"
  215. PRINT "and then compile and run.  I've already loaded your clipboard with a sample program all set to run!"
  216. PRINT "For you Linux folks (whom clipboard support doesn't work fully for yet with GL), or for those"
  217. PRINT "who don't want to test the results themselves..."
  218. PRINT "The reason this fails is simple:"
  219. PRINT "We just calculated our circle, but forgot to plot it RELATIVE TO THE CENTER!"
  220. PRINT "x and y were how far right and up we had to go from the CENTER to draw our circle (or arc for a"
  221. PRINT "partial segment) -- and we didn't calculate for that."
  222. PRINT "What we'd want to do is change the PSET line to include that center coordinate."
  223. PRINT "Something like this should work:  PSET (Xcenter + x, Ycenter + y)"
  224. PRINT "Then we just set that Xcenter and YCenter to wherever we want the center point of our circle to be"
  225. PRINT "and we can draw it onto our screen!"
  226. PRINT "Now, that wasn't TOO terrible was it?"
  227. PRINT "I feel like I've rushed part of this, and have skipped over several things that would potentially be"
  228. PRINT "very useful to people in the long run (like Opposite ^ 2 + Adjacent ^ 2 = Hypotenuse ^ 2), but I"
  229. PRINT "wanted to toss together the very basics of SIN/COS, what they are, and how we use them for a circle"
  230. PRINT "in our programming."
  231. PRINT "I'm still going to be busy for the next few weeks, but I hope this helps people get a start on"
  232. PRINT "learning what these commands are, and how they relate to our circles for us."
  233. PRINT "Keep an eye open, and once my time frees up once more, I'll expand this even more and try and add"
  234. PRINT "some interactive demostrations for everyone to play around with."
  235. PRINT "Like most projects, I don't know if it'll ever get finished."
  236. PRINT "Look for the next update...."
  237. PRINT "SOON(tm) !!"
  238.  
  239.  
  240. y = 0: Part = 1
  241.  
  242.     _LIMIT 60
  243.     _PUTIMAGE (0, 0)-(800, 600), ts, ws, (0, y)-STEP(800, 600)
  244.     k = _KEYHIT
  245.     Button = MouseClick: MK = 0
  246.     SELECT CASE Button
  247.         CASE 1: k = 19712: MK = -1
  248.         CASE 2: k = 19200: MK = -1
  249.         CASE 4: k = 18432: MK = -1
  250.         CASE 5: k = 20480: MK = -1
  251.     END SELECT
  252.     IF k = 27 THEN SYSTEM
  253.     IF MK THEN Scroll = 25 ELSE Scroll = 10
  254.     SELECT CASE Part
  255.         CASE 1
  256.             SELECT CASE k
  257.                 CASE 18432: y = y - Scroll: IF y < 0 THEN y = 0
  258.                 CASE 20480: y = y + Scroll: IF y > 700 THEN y = 700
  259.                 CASE 19712: Part = 2: y = 1300
  260.             END SELECT
  261.         CASE 2
  262.             SELECT CASE k
  263.                 CASE 18432: y = y - Scroll: IF y < 1300 THEN y = 1300
  264.                 CASE 20480: y = y + Scroll: IF y > 2200 THEN y = 2200
  265.                 CASE 19712: Part = 3: y = 2800
  266.                 CASE 19200: Part = 1: y = 0
  267.             END SELECT
  268.         CASE 3
  269.             SELECT CASE k
  270.                 CASE 18432: y = y - Scroll: IF y < 2800 THEN y = 2800
  271.                 CASE 20480: y = y + Scroll: IF y > 5000 THEN y = 5000
  272.                 CASE 19200: Part = 2: y = 1300
  273.             END SELECT
  274.  
  275.     END SELECT
  276.  
  277.     _DISPLAY
  278.     CLS
  279.  
  280.  
  281.  
  282. SUB CenterText (y, text$)
  283.     l = _PRINTWIDTH(text$)
  284.     w = _WIDTH
  285.     x = (w - l) \ 2
  286.     _PRINTSTRING (x, y), text$
  287.  
  288. FUNCTION MouseClick%
  289.     DO WHILE _MOUSEINPUT 'check mouse status
  290.         scroll% = scroll% + _MOUSEWHEEL ' if scrollwheel changes, watch the change here
  291.         IF _MOUSEBUTTON(1) THEN 'left mouse pushed down
  292.             speedup = 1
  293.         ELSEIF _MOUSEBUTTON(2) THEN 'right mouse pushed down
  294.             speedup = 2
  295.         ELSEIF _MOUSEBUTTON(3) THEN 'middle mouse pushed down
  296.             speedup = 3
  297.         END IF
  298.         IF speedup THEN 'buton was pushed down
  299.             mouseclickxxx1% = _MOUSEX: mouseclickyyy1% = _MOUSEY 'see where button was pushed down at
  300.             DO WHILE _MOUSEBUTTON(speedup) 'while button is down
  301.                 i% = _MOUSEINPUT
  302.             LOOP 'finishes when button is let up
  303.             IF mouseclickxxx1% >= _MOUSEX - 2 AND mouseclickxxx1% <= _MOUSEX + 2 AND mouseclickyyy1% >= _MOUSEY - 2 AND mouseclickyyy1% <= _MOUSEY + 2 THEN 'if mouse hasn't moved (ie  clicked down, dragged somewhere, then released)
  304.                 MouseClick% = speedup
  305.             ELSE
  306.                 MouseClick% = 0
  307.             END IF
  308.         END IF
  309.     LOOP
  310.     IF scroll% < 0 THEN MouseClick% = 4
  311.     IF scroll% > 0 THEN MouseClick% = 5
  312.  
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline OldMoses

  • Seasoned Forum Regular
  • Posts: 469
    • View Profile
Re: An old, lost tutorial
« Reply #5 on: August 09, 2019, 08:13:10 am »
The took some of the mystique out of _MEM for me. Thanks.

Offline euklides

  • Forum Regular
  • Posts: 128
    • View Profile
Re: An old, lost tutorial
« Reply #6 on: August 09, 2019, 10:50:39 am »
The screen scrolling up/down is very nice !
Why not yes ?

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: An old, lost tutorial
« Reply #7 on: August 09, 2019, 11:20:18 am »
Picture best helped me to understand the functions of SIN and COS. I don't know exactly how to write it in English. It's a definition of a unit circle (or one - circle? Or binary - circle definition?), Basically I just had the picture, where it is all explained and after a bit of thinking then came up quite quickly my 3D kitchen, which is here on the forum. https://matematika.cz/jednotkova-kruznice    - slide down to the second picture from above. There you can see what radian is, as defined by SIN and COS. It is important to know that the radius of this circle is 1. When you pull the JK! function from my program you will see exactly how I created motion in 3D space. When you return to the first image, you will see a space divided into 4 quadrants. This is how you calculate the spatial angle (vector), calculate the distance by the pythagorean theorem - and you can move in 3D space. My JK! function calculates this angle.

I am copyed it here. Move mouse to circle circuit.

SELECT CASE Q in this source code is quadrant select.
Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(800, 600, 256)
  2. radius = 200
  3.  
  4.     mx = _MOUSEX
  5.     my = _MOUSEY
  6.     cx = 400
  7.     cy = 300
  8.  
  9.     CLS
  10.     FOR old = 0 TO _PI(2) STEP .001
  11.         oldX = cx + SIN(old) * radius
  12.         oldY = cy + COS(old) * radius
  13.         IF CINT(oldX) = mx AND CINT(oldY) = my THEN
  14.             PRINT "Old method - PI:"; old
  15.  
  16.             a = JK(cx, cy, mx, my, radius)
  17.             PRINT "New - JK method - PI:"; a; "  [Angle:"; _R2D(a); "]"
  18.             EXIT FOR
  19.         END IF
  20.         PSET (oldX, oldY)
  21.     NEXT
  22.     _DISPLAY
  23.  
  24.  
  25.  
  26.  
  27. FUNCTION JK! (cx, cy, px, py, R)
  28.     LenX = cx - px
  29.     LenY = cy - py
  30.     jR = 1 / R
  31.  
  32.     jX = LenX * jR
  33.     jY = LenY * jR
  34.  
  35.     sinusAlfa = jX
  36.     Alfa = ABS(_ASIN(sinusAlfa))
  37.  
  38.     Q = 1
  39.     IF px >= cx AND py <= cy THEN Q = 1 'ok
  40.     IF px >= cx AND py <= cy THEN Q = 2 'ok
  41.  
  42.     IF px < cx AND py <= cy THEN Q = 3
  43.     IF px < cx AND py > cy THEN Q = 4
  44.     SELECT CASE Q
  45.         CASE 1: alfaB = Alfa
  46.         CASE 2: alfaB = _PI / 2 + (_PI / 2 - Alfa)
  47.         CASE 3: alfaB = _PI + Alfa
  48.         CASE 4: alfaB = _PI(1.5) + (_PI / 2 - Alfa)
  49.     END SELECT
  50.     JK! = alfaB
  51.  
« Last Edit: August 09, 2019, 11:34:12 am by Petr »

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: An old, lost tutorial
« Reply #8 on: August 10, 2019, 05:19:55 pm »
Hey Steve I remember this your tutorial...
it starts and goes until the direct reading of color in memory mapping them ! Plenty of tips!

I remember also the Easter Egg in the number convertor among Hexadecimal, Binary and Decimal...
if you type &Onumber it convert an octal to decimal!
Thanks to share
Programming isn't difficult, only it's  consuming time and coffee