Advertisement
Guest User

Untitled

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