Advertisement
Guest User

Untitled

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