Advertisement
Guest User

Untitled

a guest
May 30th, 2021
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.75 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. end
  31.  
  32. --[[
  33. equation of tangent line y = -x + 50*math.sqrt(2)
  34. ]]
  35.  
  36. function love.keypressed(key)
  37. if key == "space" then
  38. thrown = true
  39. end
  40. if key == "r" then
  41. b = math.pi/2
  42. end
  43. end
  44.  
  45. function love.update(dt)
  46.  
  47. ctheta = ctheta - rv*math.pi*dt/30 -- change in theta
  48. --ntheta = ctheta -- theta now
  49. if ctheta < ctheta - 2*math.pi then -- this line seems to not work
  50. ctheta = math.pi/2
  51. end
  52.  
  53. if not thrown then
  54. ctheta = ctheta -rv*math.pi*dt/30
  55. if ctheta <= math.pi/2 - 2*math.pi then -- never let ctheta sink below -3*π/2
  56. ctheta = math.pi/2
  57. end
  58. hxpos = startposX + discr*math.cos(ctheta) -- this snippet of code calculates the hammer position for the next frame... dX/dY
  59. hypos = y - discr*math.sin(ctheta)
  60. ntheta = ctheta -- keep track of the current value of the change is theta with the current value of theta
  61. end
  62. -- must determine the quadrant and if the tangent or cotantent should be followed
  63. if thrown == true then
  64. ctheta = ctheta
  65. if ntheta <= math.pi/2 and ntheta > 0 then -- follow the tangent
  66. hxpos = hxpos + 50*dt*10*math.cos(ctheta)
  67. hypos = hxpos*hxpos/math.sqrt(50^2 + hxpos*hxpos) - 50*math.cos(ctheta) - hypos-- + hxpos -- hypos is now equal to dx/dy at ntheta
  68. cjrcle(10, hxpos, hypos)
  69. end
  70. if ntheta <= 0 and ntheta > -math.pi/2 then -- follow the cotangent... it does... but with a bit of a hop first?
  71. --hxpos = hxpos + 1/50*dt*10*math.cos(ntheta) -- follow the cotangent
  72. hxpos = hxpos - 50*dt*10*math.cos(ctheta) -- follow the cotangent
  73. --hxpos = hxpos + 50*dt*10*math.sin(ntheta)
  74. hypos = hxpos*hxpos/math.sqrt(50^2 + hxpos*hxpos) + 50*math.cos(ctheta) - hypos-- + hxpos -- hypos is now equal to dx/dy at ntheta
  75. cjrcle(10, hxpos, hypos)
  76. end
  77. end
  78.  
  79. local m = math.pow(2, dt)
  80. if love.keyboard.isDown("up") then
  81. b = b*m --the period of the sine wave is pi/delthe... i think?
  82. end
  83. if love.keyboard.isDown("down") then
  84. b = b/m
  85. end
  86. end
  87.  
  88.  
  89. function arccirc(r, x, y, delthe)
  90. arcang = math.atan(y + r/x + r)
  91. for theta = 0, arcang, delthe do
  92. 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)
  93. end
  94. end
  95.  
  96. function love.draw()
  97.  
  98. love.graphics.translate(windowwidth/2, windowheight/2)
  99. love.graphics.setColor(1, 1, 0)
  100. love.graphics.print("sine = " .. -hypos/50, -400, -400)
  101. love.graphics.setColor(1, 0, 0)
  102. love.graphics.print("cosine = " .. hxpos/50, -400, -390)
  103. love.graphics.setColor(0, 0, 1)
  104. love.graphics.print("tangent = " .. math.tan(ctheta), -400, -380)
  105. love.graphics.setColor(1,.6,.5)
  106. love.graphics.print("cotangent = " .. 1/math.tan(ctheta),-400, -370)
  107. love.graphics.setColor(0,1,0)
  108. love.graphics.print("secant = " .. 1/math.cos(ctheta), -400, -360)
  109. love.graphics.setColor(1,0,1)
  110. love.graphics.print("cosecant = " .. 1/math.sin(ctheta) , -400, -350)
  111. love.graphics.setColor(.5,.5,.5)
  112. love.graphics.print("b: " .. b, -400, -340)
  113. love.graphics.print("Ø: ".. ctheta .. " radians, or ", -400, -330)
  114. love.graphics.print(ctheta/math.pi .."π radians", -100, -330 )
  115. love.graphics.print("which is also " .. ctheta*180/math.pi .. " degrees!", -400, -300)
  116. love.graphics.print("the derrivative of the quation X^2 + Y^2 = r^2 @ r = 50: ", -400, -280)
  117. love.graphics.print("dY/dX = -x^2/(math.sqrt(50^2 - x) + 2500): ", -400, -260)
  118. love.graphics.print("tangent line has equation: ", -400, -240)
  119. love.graphics.print("Y = mX + b", -400, -220)
  120. love.graphics.print("Y = " .. -hxpos/math.sqrt(50*50 - hxpos*hxpos)*50/50 .. "*" .. hxpos .. " + B", -400, -200)
  121. love.graphics.print("B = " .. hxpos/math.sqrt(50*50 - hxpos*hxpos)/50, -400, -190)
  122. love.graphics.print("slope m = " .. -hxpos/math.sqrt(50*50 - hxpos*hxpos)/50, -400, -170)
  123. love.graphics.print("Tangent line has equation:", -400, -150)
  124. love.graphics.print("Y = " .. -hxpos*(math.sqrt(50*50 - hxpos*hxpos))/50 .. "X + " .. hxpos*(math.sqrt(50*50 - hxpos*hxpos))/50, -400, -130)
  125.  
  126. love.graphics.print("The value of thrown is: ", -400, -120)
  127. if thrown then
  128. love.graphics.print("thrown!", -200, -120)
  129. else
  130. love.graphics.print("not thrown:(", -200, -120) -- thrown not being updated:()
  131. end
  132.  
  133.  
  134.  
  135. -- orange cjrcle
  136.  
  137. love.graphics.setColor(.7, .6, .3)
  138. cjrcle(discr, startposX, 0, 32)
  139.  
  140. -- blue cjrcle for player
  141. love.graphics.setColor(1, 1, 1)
  142. cjrcle(10, hxpos, hypos)
  143.  
  144.  
  145. -- tangent and cotantgent lines
  146. love.graphics.setColor(1,.6,.5)
  147. love.graphics.line(50*math.cos(ctheta), -50*math.sin(ctheta), 0, -50/math.sin(ctheta))
  148. love.graphics.setColor(0, 0, 1)
  149. love.graphics.line(50*math.cos(ctheta), -50*math.sin(ctheta), 50/math.cos(ctheta), 0)
  150.  
  151. -- secant and cosecant lines
  152. love.graphics.setColor(1, 0, 1)
  153. love.graphics.line(0,0,0,-50/math.sin(ctheta)) --csc
  154. love.graphics.setColor(1, 1, .1)
  155. love.graphics.setColor(0, 1, 0)
  156. love.graphics.line(0,0,50/math.cos(ctheta),0) --sec
  157.  
  158. --red cosine line
  159. love.graphics.setColor(1, 0, 0)
  160. love.graphics.line(0, 0, hxpos, 0)
  161.  
  162. -- y sine line
  163. love.graphics.setColor(1, 1, 0)
  164. love.graphics.line(hxpos, hypos, 50*math.cos(ctheta), 0)
  165.  
  166.  
  167. -- radius
  168. love.graphics.setColor(.5, .3, 0)
  169. love.graphics.line(0, 0, hxpos, hypos)
  170.  
  171.  
  172. --anglethetaprints
  173.  
  174. love.graphics.print("Ø",hxpos/2, hypos)
  175. for thetarc = math.atan2(hypos,hxpos), math.sin(ctheta), -math.pi/60 do
  176.  
  177. love.graphics.setColor(0,1,0)
  178. if hxpos > 0 and hypos > 0 then
  179. if thetarc <= math.pi/2 and thetarc > 0 then
  180. 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))
  181. thetarc = thetarc + math.pi/60
  182. --love.graphics.print("Ø",hxpos/2, hypos/2)
  183. end
  184. end
  185.  
  186. if hxpos < 0 and hypos > 0 then
  187. --if math.cos(thetarc < 0)
  188. if thetarc <= 0 and thetarc > -math.pi/2 then
  189. 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))
  190. thetarc = thetarc + math.pi/60
  191. --love.graphics.print("Ø",hxpos/2, hypos/2)
  192. end
  193. end
  194.  
  195. end
  196.  
  197. --sinecurve
  198.  
  199. sinxloc = 50
  200. cosyloc = 50
  201. love.graphics.setColor(1, 0, 0.4)
  202. for theta = -32*math.pi, 32*math.pi, math.pi/180 do
  203. love.graphics.line(25 + sinxloc, -50*math.sin(b*theta), 25 +sinxloc + math.pi/360, -50*math.sin(b*theta + math.pi/360))
  204. sinxloc = sinxloc + 1
  205. cosyloc = cosyloc + 1
  206. end
  207.  
  208.  
  209. love.graphics.setColor(1,0,0)
  210.  
  211.  
  212. love.graphics.print("x: " .. hxpos/50, hxpos, hypos)
  213. love.graphics.print("y: " .. -hypos/50, hxpos, hypos+10)
  214.  
  215. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement