Advertisement
Guest User

Untitled

a guest
Jun 28th, 2021
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.22 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. dYdX = ctheta + math.pi/2
  33. end
  34.  
  35. --[[
  36. equation of tangent line y = -x + 50*math.sqrt(2)
  37. ]]
  38.  
  39. function love.keypressed(key)
  40. if key == "space" then
  41. thrown = true
  42. end
  43. if key == "r" then
  44. b = math.pi/2
  45. end
  46. end
  47.  
  48. function love.update(dt)
  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. if not thrown then
  55. ctheta = ctheta + math.pi/60*dt -- 2?
  56. hxpos = math.sin(ctheta)*discr
  57. hypos = math.cos(ctheta)*discr
  58. else
  59. ctheta = ctheta + math.pi/2
  60. hxpos = hxpos + math.sin(ctheta)
  61. hypos = hypos + math.cos(ctheta)
  62. end
  63. --[[
  64. if not thrown then
  65. ctheta = ctheta -rv*math.pi*dt/30
  66. hxpos = startposX + discr*math.cos(ctheta) -- this snippet of code calculates the hammer position for the next frame... dX/dY
  67. hypos = y - discr*math.sin(ctheta)
  68. ntheta = ctheta -- keep track of the current value of the change is theta with the current value of theta
  69. end
  70. if thrown == true then -- the tangent line is π/2 radians from ctheta
  71. dYdX = ctheta + math.pi/2
  72. ctheta = ntheta
  73. index = 0
  74.  
  75. if index%2 == 0 then
  76. if hxpos < windowwidth/2 and hypos < windowheight/2 and hxpos > -1*windowwidth/2 and hypos > -1*windowheight/2 then
  77. hxpos = hxpos + 1
  78. hypos = hypos + dYdX
  79. end
  80. end
  81. if index%2 ~= 0 then
  82. if hxpos < windowwidth/2 or hxpos > -windowwidth/2 then
  83. hxpos = hxpos + 1
  84. hypos = hypos + dYdX
  85. index = index + 1
  86. end
  87. end
  88. end
  89. ]]
  90. local m = math.pow(2, dt)
  91. if love.keyboard.isDown("up") then
  92. b = b*m
  93. end
  94. if love.keyboard.isDown("down") then
  95. b = b/m
  96. end
  97. end
  98.  
  99.  
  100. function arccirc(r, x, y, delthe)
  101. arcang = math.atan(y + r/x + r)
  102. for theta = 0, arcang, delthe do
  103. 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)
  104. end
  105. end
  106.  
  107. function love.draw()
  108.  
  109. love.graphics.translate(windowwidth/2, windowheight/2)
  110. love.graphics.setColor(1, 1, 0)
  111. love.graphics.print("sine = " .. -hypos/50, -400, -400)
  112. love.graphics.setColor(1, 0, 0)
  113. love.graphics.print("cosine = " .. hxpos/50, -400, -390)
  114. love.graphics.setColor(0, 0, 1)
  115. love.graphics.print("tangent = " .. math.tan(ctheta), -400, -380)
  116. love.graphics.setColor(1,.6,.5)
  117. love.graphics.print("cotangent = " .. 1/math.tan(ctheta),-400, -370)
  118. love.graphics.setColor(0,1,0)
  119. love.graphics.print("secant = " .. 1/math.cos(ctheta), -400, -360)
  120. love.graphics.setColor(1,0,1)
  121. love.graphics.print("cosecant = " .. 1/math.sin(ctheta) , -400, -350)
  122. love.graphics.setColor(1,1,1)
  123. love.graphics.print("b: " .. b, -400, -340)
  124. love.graphics.print("Ø: ".. ctheta .. " radians, or ", -400, -330 )
  125. love.graphics.print("which is also " .. ctheta*180/math.pi .. " degrees!", -400, -300)
  126. love.graphics.print("the derrivative of the quation X^2 + Y^2 = r^2 @ r = 50: ", -400, -280)
  127. love.graphics.print("dY/dX = -x^2/(math.sqrt(50^2 - x) + 2500) = " .. -hxpos*hxpos/(math.sqrt(discr*discr - hxpos) + 2500), -400, -260)
  128. love.graphics.print("tangent line has equation: ", -400, -240)
  129. love.graphics.print("Y = mX + b", -400, -220)
  130. --love.graphics.print("Y = " .. -hxpos/math.sqrt(50*50 - hxpos*hxpos)*50/50 .. "*" .. hxpos .. " + B", -400, -200)
  131. love.graphics.print("Y = " .. dYdX .. "*" .. hxpos .. " + B", -400, -200)
  132. love.graphics.print("B = " .. -dYdX, -400, -190)
  133. --love.graphics.print("B = " .. hxpos/math.sqrt(50*50 - hxpos*hxpos)/50, -400, -190)
  134. --love.graphics.print("slope m = " .. -hxpos/math.sqrt(50*50 - hxpos*hxpos)/50, -400, -170)
  135. love.graphics.print("Tangent line has equation:", -400, -150)
  136. --love.graphics.print("Y = " .. -hxpos*(math.sqrt(50*50 - hxpos*hxpos))/50 .. "X + " .. hxpos*(math.sqrt(50*50 - hxpos*hxpos))/50, -400, -130)
  137. love.graphics.print("Y = " .. dYdX .. "X + " .. -dYdX, -400, -130)
  138.  
  139. love.graphics.print("The value of thrown is: ", -400, -120)
  140. if thrown then
  141. love.graphics.print("thrown!", -200, -120)
  142. else
  143. love.graphics.print("not thrown:(", -200, -120) -- thrown not being updated:()
  144. end
  145. -- orange cjrcle
  146.  
  147. love.graphics.setColor(.7, .6, .3)
  148. cjrcle(discr, startposX, 0, 32)
  149.  
  150. -- blue cjrcle for player
  151. love.graphics.setColor(1, 1, 1)
  152. cjrcle(10, hxpos, hypos)
  153.  
  154. --orange cotangent...
  155. love.graphics.setColor(1,.6,.5)
  156. love.graphics.line(50*math.cos(ctheta), -50*math.sin(ctheta), 0, -50/math.sin(ctheta))
  157. -- blue tangent
  158. love.graphics.setColor(0, 0, 1)
  159. love.graphics.line(50*math.cos(ctheta), -50*math.sin(ctheta), 50/math.cos(ctheta), 0)
  160.  
  161. --grey continued gray tangent line
  162. love.graphics.setColor(.5,.5,.5)
  163. love.graphics.line(discr/math.cos(ctheta), 0, windowwidth/2, windowwidth/2*(math.sqrt(discr*discr - hxpos*hxpos))/50)
  164.  
  165. love.graphics.setColor(.8,.8,.8)
  166. love.graphics.line(discr/math.cos(ctheta), 0, windowwidth/2*(math.sqrt(discr*discr - hxpos*hxpos))/discr, windowwidth/2)
  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. --anglethetaprints
  191.  
  192. love.graphics.print("Ø",hxpos/2, hypos)
  193. for thetarc = math.atan2(hypos,hxpos), math.sin(ctheta), -math.pi/60 do
  194.  
  195. love.graphics.setColor(0,1,0)
  196. if hxpos > 0 and hypos > 0 then
  197. if thetarc <= math.pi/2 and thetarc > 0 then
  198. 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))
  199. thetarc = thetarc + math.pi/60
  200. --love.graphics.print("Ø",hxpos/2, hypos/2)
  201. end
  202. end
  203.  
  204. if hxpos < 0 and hypos > 0 then
  205. if thetarc <= 0 and thetarc > -math.pi/2 then
  206. 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))
  207. thetarc = thetarc + math.pi/60
  208. --love.graphics.print("Ø",hxpos/2, hypos/2)
  209. end
  210. end
  211.  
  212. end
  213.  
  214. --sinecurve
  215.  
  216. sinxloc = 50
  217. cosyloc = 50
  218. love.graphics.setColor(1, 0, 0.4)
  219. for theta = -32*math.pi, 32*math.pi, math.pi/180 do
  220. love.graphics.line(25 + sinxloc, -50*math.sin(b*theta), 25 + sinxloc + math.pi/360, -50*math.sin(b*theta + math.pi/360))
  221. sinxloc = sinxloc + 1
  222. cosyloc = cosyloc + 1
  223. end
  224.  
  225. love.graphics.setColor(1,0,0)
  226. love.graphics.print("x: " .. hxpos/50, hxpos - 50, hypos)
  227. love.graphics.print("y: " .. -hypos/50, hxpos - 50, hypos+10)
  228. end
  229.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement