Advertisement
joseleeph

Untitled

Apr 18th, 2021
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.46 KB | None | 0 0
  1.  
  2. function love.load() -- do global variables get declared here?
  3. windowwidth = 1000
  4. windowheight = 1000
  5. sucess = love.window.setMode(windowwidth, windowheight)
  6. x = 30
  7. y = 50
  8. z = math.sin(math.pi/3)
  9. cx = 0
  10. cy = 0
  11. theta = math.pi/60 -- 3 degrees
  12. end
  13.  
  14. function love.update(dt) -- added dt as a parameter ... is dt 1/framerate?
  15. cx = cx + dt
  16. cy = cy + dt
  17. end
  18.  
  19. function love.draw() -- render to window
  20. love.graphics.setColor(200/255, 215/255, 0/255)
  21. --delthe = math.pi/60 -- 3 degrees .... try making delthe into the derrivative of the curve...
  22. theta = math.pi/60 -- 3 degrees
  23. delthe = -4*math.sin(2*theta) -- delthe is now the derrivative of r = 2cos(2ø)
  24.  
  25. love.graphics.setColor(145/255, 12/255, 230/255)
  26. love.graphics.rectangle("line", x, y, 100, 100)
  27. love.graphics.setColor(0/255, 12/255, 230/255)
  28. love.graphics.print("the sin of 60 is: " .. z, 100, 300)
  29. love.graphics.setColor(0/255, 200/255, 230/255)
  30. love.graphics.print("here is a line: ", 100, 400)
  31. love.graphics.setColor(0/255, 200/255, 100/255)
  32. love.graphics.line(100,400, math.cos(100*math.pi/3) + 200, math.sin(100*math.pi/3) + 200)
  33. --theta = 0
  34. --draws a circle
  35. for theta = 0, 2*math.pi, delthe do -- you must specify the incrementation or it will assumed to be 1
  36.  
  37. r = 100
  38. a = 1 -- amplitude of the waves
  39. b = 2
  40. --delthe = math.pi/60 -- 3 degrees... change del the to be based on r to fix holes maybe?
  41. love.graphics.setColor(200/255, 0/255, 100/255)
  42.  
  43. love.graphics.line(r*math.cos(a*theta) + windowwidth/2, r*math.sin(a*theta) + windowwidth/2, r*math.cos(a*theta + a*delthe) + windowwidth/2, r*math.sin(a*theta + a*delthe) + windowwidth/2)
  44. end
  45. -- attempt to draw a clover with equation r = cos(2*theta)
  46. for theta = 0, 2*math.pi, delthe do
  47. r = 2*math.cos(2*theta)
  48. a = 100
  49. b = 2
  50. --delthe = math.pi/60 -- 3 degrees
  51. love.graphics.setColor(100/255, 0/255, 200/255)
  52. love.graphics.line(a*r*math.cos(theta) + windowwidth/2, a*r*math.sin(theta) + windowheight/2, a*r*math.cos(theta + delthe) + windowwidth/2, a*r*math.sin(theta+delthe) + windowheight/2)
  53. end
  54. -- attempt to draw a clover with equation r = cos(2*theta)
  55. for theta = 0, 2*math.pi, delthe do
  56. r = 2*math.sin(3*theta)
  57. a = 100
  58. b = 2
  59. --delthe = math.pi/60 -- 3 degrees
  60. love.graphics.setColor(2/255, 200/255, 50/255)
  61. love.graphics.line(a*r*math.cos(theta) + windowwidth/2, a*r*math.sin(theta) + windowheight/2, a*r*math.cos(theta + delthe) + windowwidth/2, a*r*math.sin(theta+delthe) + windowheight/2)
  62. end
  63. -- a spiral pattern!
  64. for theta = 0, 2*math.pi, delthe do
  65. r = math.sin(1/3*theta)
  66. a = 100
  67. b = 2
  68. --delthe = math.pi/60 -- 3 degrees
  69. love.graphics.setColor(2/255, 200/255, 155/255)
  70. love.graphics.line(a*r*math.cos(theta) + windowwidth/2, a*r*math.sin(theta) + windowheight/2, a*r*math.cos(theta + delthe) + windowwidth/2, a*r*math.sin(theta+delthe) + windowheight/2)
  71. end
  72. -- 8 leaves
  73. for theta = 0, 2*math.pi, delthe do
  74. r = math.sin(4*theta)
  75. a = 100
  76. b = 2
  77. --delthe = math.pi/60 -- 3 degrees
  78. love.graphics.setColor(230/255, 0/255, 50/255)
  79. love.graphics.line(a*r*math.cos(theta) + windowwidth/2, a*r*math.sin(theta) + windowheight/2, a*r*math.cos(theta + delthe) + windowwidth/2, a*r*math.sin(theta+delthe) + windowheight/2)
  80. end
  81.  
  82. love.graphics.print("x: " .. cx .. "y: " .. cy, cx, cy)
  83. love.graphics.circle("fill", cx, cy, 2)
  84. end
  85.  
  86. function love.keypressed(key)
  87. if key == "space" then
  88. x = math.random(100, 500)
  89. y = math.random(100, 500)
  90. end
  91. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement