Advertisement
Guest User

Untitled

a guest
Jun 21st, 2021
541
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.23 KB | None | 0 0
  1. function love.load()
  2. --Object = require "classic"
  3. require "cjrcle"
  4. windowwidth = 1000
  5. windowheight = 1000
  6. love.graphics.setBackgroundColor(0, 0, 0)
  7. sucess = love.window.setMode(windowwidth, windowheight)
  8.  
  9. ctheta = math.pi/2
  10. x = 0
  11. y = 0
  12. b = math.pi/ctheta
  13.  
  14. sinxloc = 0
  15. startposX = 0
  16. discr = 50
  17. hr = 10
  18.  
  19. speed = 1
  20.  
  21. thrown = false -- a variable to check if the hammer has been let go
  22.  
  23. -- hammer position
  24. hxpos = startposX + discr*math.cos(math.pi/2)/math.pi
  25. hypos = y - discr*math.sin(math.pi/2)
  26. nxpos = hxpos
  27. nypos = hypos
  28. rv = 1 -- rotational velocity
  29.  
  30. --m = -hxpos/math.sqrt(50*50 - hxpos*hxpos)/discr
  31. dYdX = -hxpos/math.sqrt(discr*discr - hxpos*hxpos)/discr
  32. end
  33.  
  34. --[[
  35. equation of tangent line y = -x + 50*math.sqrt(2)
  36. ]]
  37.  
  38. function love.keypressed(key)
  39. if key == "space" then
  40. thrown = true
  41. end
  42. if key == "r" then
  43. b = math.pi/2
  44. end
  45. end
  46.  
  47. function love.update(dt)
  48.  
  49. ctheta = ctheta - rv*math.pi*dt/30 -- change in theta
  50. --ntheta = ctheta -- theta now
  51. if ctheta < ctheta - 2*math.pi then
  52. ctheta = math.pi/2
  53. end
  54.  
  55. if not thrown then
  56. ctheta = ctheta -rv*math.pi*dt/30
  57. hxpos = startposX + discr*math.cos(ctheta) -- this snippet of code calculates the hammer position for the next frame... dX/dY
  58. hypos = y - discr*math.sin(ctheta)
  59. ntheta = ctheta -- keep track of the current value of the change is theta with the current value of theta
  60. end
  61. if thrown == true then
  62. ctheta = ntheta
  63. index = 0
  64. -- trying to get the hammer to go in a straight line from it's current position to 1/cos(ctheta)
  65. if index%2 == 0 then
  66. if hxpos < windowwidth/2 and hypos < windowheight/2 and hxpos > -windowwidth/2 and hypos > windowheight/2 then
  67. hxpos = hxpos + 1
  68. --hypos = hypos - dYdX
  69.  
  70. --if hxpos < discr/math.cos(ctheta) then -- if the x coordinate of the hammer is less than the secant of ctheta
  71. --hxpos = hxpos + math.tan(ntheta)
  72. --hypos = hypos/hxpos
  73. hypos = hypos + dYdX -- hypos will never reach 0 because the cot(ctheta) will never be 0
  74. --hypos = hypos + math.tan(ntheta)
  75. end
  76. end
  77. if index%2 ~= 0 then
  78. --if hxpos < discr/math.sin(ctheta) then -- if the x coordinate of the hammer is less than the cosecant of ctheta
  79. if hxpos < windowwidth/2 or hxpos > -windowwidth/2 then
  80. hxpos = hxpos + 1
  81. hypos = hypos + dYdX
  82. --hypos = hxpos + hypos/hxpos
  83. index = index + 1
  84. -- y never gets to 1 because the tangent is never
  85. end
  86. end
  87.  
  88.  
  89. end
  90.  
  91. local m = math.pow(2, dt)
  92. if love.keyboard.isDown("up") then
  93. b = b*m --the period of the sine wave is pi/delthe... i think?
  94. end
  95. if love.keyboard.isDown("down") then
  96. b = b/m
  97. end
  98. end
  99.  
  100.  
  101. function arccirc(r, x, y, delthe)
  102. arcang = math.atan(y + r/x + r)
  103. for theta = 0, arcang, delthe do
  104. love.graphics.line(discr*math.cos(theta) + x, discr*math.sin(theta) + y, discr*math.cos(theta + delthe) + x, discr*math.sin(theta + delthe) + y)
  105. end
  106. end
  107.  
  108. function love.draw()
  109.  
  110. love.graphics.translate(windowwidth/2, windowheight/2)
  111. love.graphics.setColor(1, 1, 0)
  112. love.graphics.print("sine = " .. -hypos/50, -400, -400)
  113. love.graphics.setColor(1, 0, 0)
  114. love.graphics.print("cosine = " .. hxpos/50, -400, -390)
  115. love.graphics.setColor(0, 0, 1)
  116. love.graphics.print("tangent = " .. math.tan(ctheta), -400, -380)
  117. love.graphics.setColor(1,.6,.5)
  118. love.graphics.print("cotangent = " .. 1/math.tan(ctheta),-400, -370)
  119. love.graphics.setColor(0,1,0)
  120. love.graphics.print("secant = " .. 1/math.cos(ctheta), -400, -360)
  121. love.graphics.setColor(1,0,1)
  122. love.graphics.print("cosecant = " .. 1/math.sin(ctheta) , -400, -350)
  123. love.graphics.setColor(1,1,1)
  124. love.graphics.print("b: " .. b, -400, -340)
  125. love.graphics.print("Ø: ".. ctheta .. " radians, or ", -400, -330 )
  126. love.graphics.print("which is also " .. ctheta*180/math.pi .. " degrees!", -400, -300)
  127. love.graphics.print("the derrivative of the quation X^2 + Y^2 = r^2 @ r = 50: ", -400, -280)
  128. love.graphics.print("dY/dX = -x^2/(math.sqrt(50^2 - x) + 2500) = " .. -hxpos*hxpos/(math.sqrt(discr*discr - hxpos) + 2500), -400, -260)
  129. love.graphics.print("tangent line has equation: ", -400, -240)
  130. love.graphics.print("Y = mX + b", -400, -220)
  131.  
  132. love.graphics.print("Y = " .. dYdX .. "*" .. hxpos .. " + B", -400, -200)
  133. love.graphics.print("B = " .. -dYdX, -400, -190)
  134.  
  135.  
  136. love.graphics.print("Tangent line has equation:", -400, -150)
  137. -400, -130)
  138. love.graphics.print("Y = " .. dYdX .. "X + " .. -dYdX, -400, -130)
  139.  
  140. love.graphics.print("The value of thrown is: ", -400, -120)
  141. if thrown then
  142. love.graphics.print("thrown!", -200, -120)
  143. else
  144. love.graphics.print("not thrown:(", -200, -120) -- thrown not being updated:()
  145. end
  146.  
  147.  
  148. -- orange cjrcle
  149.  
  150. love.graphics.setColor(.7, .6, .3)
  151. cjrcle(discr, startposX, 0, 32)
  152.  
  153. -- blue cjrcle for player
  154. love.graphics.setColor(1, 1, 1)
  155. cjrcle(10, hxpos, hypos)
  156.  
  157.  
  158. -- violet tangent and cotantgent lines
  159. --orange cotangent...
  160. love.graphics.setColor(1,.6,.5)
  161. love.graphics.line(50*math.cos(ctheta), -50*math.sin(ctheta), 0, -50/math.sin(ctheta))
  162. -- blue tangent
  163. love.graphics.setColor(0, 0, 1)
  164. love.graphics.line(50*math.cos(ctheta), -50*math.sin(ctheta), 50/math.cos(ctheta), 0)
  165.  
  166. --grey continued gray tangent line
  167. love.graphics.setColor(.5,.5,.5)
  168. love.graphics.line(discr/math.cos(ctheta), 0, windowwidth/2, windowwidth/2*(math.sqrt(discr*discr - hxpos*hxpos))/50)
  169.  
  170. love.graphics.setColor(.8,.8,.8)
  171. love.graphics.line(discr/math.cos(ctheta), 0, windowwidth/2*(math.sqrt(discr*discr - hxpos*hxpos))/discr, windowwidth/2)
  172.  
  173.  
  174.  
  175. -- secant and cosecant
  176. love.graphics.setColor(1, 0, 1)
  177. love.graphics.line(0,0,0,-50/math.sin(ctheta)) --csc
  178. love.graphics.setColor(1, 1, .1)
  179. love.graphics.setColor(0, 1, 0)
  180. love.graphics.line(0,0,50/math.cos(ctheta),0) --sec
  181.  
  182. --different triangle
  183.  
  184. --red horizontal cosine line
  185. love.graphics.setColor(1, 0, 0)
  186. love.graphics.line(0, 0, hxpos, 0)
  187.  
  188. -- yellow vertical sine line
  189. love.graphics.setColor(1, 1, 0)
  190. love.graphics.line(hxpos, hypos, 50*math.cos(ctheta), 0)
  191.  
  192.  
  193. -- radius
  194. love.graphics.setColor(.5, .3, 0)
  195. love.graphics.line(0, 0, hxpos, hypos)
  196.  
  197.  
  198.  
  199.  
  200. --anglethetaprints
  201.  
  202. love.graphics.print("Ø",hxpos/2, hypos)
  203. for thetarc = math.atan2(hypos,hxpos), math.sin(ctheta), -math.pi/60 do
  204.  
  205. love.graphics.setColor(0,1,0)
  206. if hxpos > 0 and hypos > 0 then
  207. if thetarc <= math.pi/2 and thetarc > 0 then
  208. love.graphics.line(10*math.cos(thetarc), 10*math.sin(thetarc), 10*math.cos(thetarc + math.pi/60), 10*math.sin(thetarc + math.pi/60))
  209. thetarc = thetarc + math.pi/60
  210. --love.graphics.print("Ø",hxpos/2, hypos/2)
  211. end
  212. end
  213.  
  214. if hxpos < 0 and hypos > 0 then
  215. if thetarc <= 0 and thetarc > -math.pi/2 then
  216. love.graphics.line(-10*math.cos(thetarc), -10*math.sin(thetarc), -10*math.cos(thetarc + math.pi/60), -10*math.sin(thetarc + math.pi/60))
  217. thetarc = thetarc + math.pi/60
  218. --love.graphics.print("Ø",hxpos/2, hypos/2)
  219. end
  220. end
  221.  
  222. end
  223.  
  224. --sinecurve
  225.  
  226. sinxloc = 50
  227. cosyloc = 50
  228. love.graphics.setColor(1, 0, 0.4)
  229. for theta = -32*math.pi, 32*math.pi, math.pi/180 do
  230. love.graphics.line(25 + sinxloc, -50*math.sin(b*theta), 25 + sinxloc + math.pi/360, -50*math.sin(b*theta + math.pi/360))
  231. sinxloc = sinxloc + 1
  232. cosyloc = cosyloc + 1
  233. end
  234.  
  235.  
  236. love.graphics.setColor(1,0,0)
  237.  
  238.  
  239. love.graphics.print("x: " .. hxpos/50, hxpos - 50, hypos)
  240. love.graphics.print("y: " .. -hypos/50, hxpos - 50, hypos+10)
  241.  
  242. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement