Advertisement
Guest User

Untitled

a guest
May 23rd, 2021
1,179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.75 KB | None | 0 0
  1.  
  2. function love.load()
  3.  
  4. require "cjrcle"
  5. windowwidth = 1000
  6. windowheight = 1000
  7. love.graphics.setBackgroundColor(0, 0, 0)
  8. sucess = love.window.setMode(windowwidth, windowheight) -- what does this line do? ... will work but the circle is offset
  9.  
  10. ctheta = math.pi/2
  11. x = 0
  12. y = 0
  13. b = math.pi/ctheta
  14.  
  15. sinxloc = 0
  16. startposX = 0
  17. discr = 50
  18. hr = 10
  19.  
  20. speed = 1
  21.  
  22. thrown = false -- a variable to check if the hammer has been let go
  23.  
  24. -- hammer position
  25. hxpos = startposX + discr*math.cos(math.pi/2)/math.pi
  26. hypos = y - discr*math.sin(math.pi/2)
  27. rv = 1 -- rotational velocity
  28. end
  29.  
  30. function love.update(dt)
  31. -- smaller angle = slower rotspeed
  32. ctheta = ctheta - rv*math.pi*dt/3
  33. if ctheta < math.pi/2 - 2*math.pi then
  34. ctheta = math.pi/2
  35. end
  36. --if speed < 10 then
  37. --speed = speed*1.01
  38. --startposX = startposX + speed
  39. --end
  40.  
  41.  
  42. hxpos = startposX + discr*math.cos(ctheta)
  43. hypos = y - discr*math.sin(ctheta)
  44. local m = math.pow(2, dt)
  45. if love.keyboard.isDown("up") then
  46. b = b*m --the period of the sine wave is pi/delthe... i think?
  47. end
  48. if love.keyboard.isDown("down") then
  49. b = b/m
  50. end
  51. end
  52.  
  53. function love.keypressed(key)
  54. if key == "space" and startposX < 0 then
  55. thrown = true
  56. end
  57. if key == "r" then
  58. b = math.pi/2
  59. end
  60. end
  61.  
  62. function arccirc(r, x, y, delthe)
  63. arcang = math.atan(y + r/x + r)
  64. for theta = 0, arcang, delthe do
  65. 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)
  66. end
  67. end
  68.  
  69. function love.draw()
  70. --love.graphics.push()
  71. love.graphics.translate(windowwidth/2, windowheight/2)
  72.  
  73. love.graphics.setColor(0, 1, 0)
  74. love.graphics.print("sine = " .. -hypos/50, -400, -400)
  75. love.graphics.setColor(1, 0, 0)
  76. love.graphics.print("cosine = " .. hxpos/50, -400, -390)
  77. love.graphics.setColor(.6, 0, .6)
  78. love.graphics.print("tangent = " .. math.tan(ctheta), -400, -380)
  79. love.graphics.setColor(.9, 0, .9)
  80. love.graphics.print("cotangent = " .. 1/math.tan(ctheta),-400, -370)
  81. love.graphics.setColor(.7,1,.7)
  82. love.graphics.print("secant = " .. 1/math.cos(ctheta), -400, -360)
  83. love.graphics.setColor(0,1,0)
  84. love.graphics.print("cosecant = " .. 1/math.sin(ctheta) , -400, -350)
  85. love.graphics.print("b: " .. b, -400, -340)
  86. love.graphics.print("Ø: ".. ctheta .. " radians, or ", -400, -330 )
  87. love.graphics.print("which is also " .. ctheta*180/math.pi .. " degrees!", -400, -320)
  88.  
  89. -- orange cjrcle
  90. --
  91. love.graphics.setColor(.7, .6, .3)
  92. cjrcle(discr, startposX, 0, 32)
  93. --cjrcle(discr, startposX, 0, )
  94.  
  95. -- blue cjrcle for player
  96. love.graphics.setColor(0, 0, 1)
  97. cjrcle(10, hxpos, hypos)
  98.  
  99.  
  100. -- violet tangent and cotantgent lines
  101. love.graphics.setColor(.6,0,.6)
  102. love.graphics.line(50*math.cos(ctheta), -50*math.sin(ctheta), 0, -50/math.sin(ctheta))
  103. love.graphics.setColor(0,.9,.9)
  104. love.graphics.line(50*math.cos(ctheta), -50*math.sin(ctheta), 50/math.cos(ctheta), 0)
  105.  
  106. -- secant and cosecant
  107. love.graphics.setColor(0, 1, 0)
  108. love.graphics.line(0,0,0,-50/math.sin(ctheta)) --csc
  109. love.graphics.setColor(0, 1, 1)
  110. love.graphics.line(0,0,50/math.cos(ctheta),0) --sec
  111.  
  112. --different triangle
  113.  
  114. --red horizontal cosine line
  115. love.graphics.setColor(1, 0, 0)
  116. love.graphics.line(0, 0, hxpos, 0)
  117.  
  118. -- yellow vertical sine line
  119. love.graphics.setColor(0, 1, 0)
  120. love.graphics.line(hxpos, hypos, 50*math.cos(ctheta), 0)
  121.  
  122.  
  123. -- radius
  124. love.graphics.setColor(.5, .3, 0)
  125. love.graphics.line(0, 0, hxpos, hypos)
  126.  
  127.  
  128.  
  129.  
  130. for thetarc = math.atan(hypos/hxpos), math.sin(ctheta), -math.pi/60 do -- arctan is both plus and minus?
  131. love.graphics.setColor(0,1,0)
  132. 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))
  133. thetarc = thetarc + math.pi/60
  134. end
  135.  
  136. -- sincurve
  137. sinxloc = 50
  138. cosyloc = 50
  139. love.graphics.setColor(1, 0, 0.4)
  140. for theta = -32*math.pi, 32*math.pi, math.pi/180 do
  141. love.graphics.line(25 + sinxloc, -50*math.sin(b*theta), 25 +sinxloc + math.pi/360, -50*math.sin(b*theta + math.pi/360))
  142.  
  143. sinxloc = sinxloc + 1
  144.  
  145. end
  146.  
  147. --[[
  148. N.B!
  149. theta = arctan sin/cos
  150. the period of the sine wave is pi/delthe... i think?
  151. if theta is < arctan
  152. ]]
  153.  
  154. love.graphics.setColor(1,0,0)
  155. love.graphics.print("x: " .. hxpos/50, hxpos, hypos)
  156. love.graphics.print("y: " .. -hypos/50, hxpos, hypos+10)
  157.  
  158. end
  159.  
  160.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement