Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function love.load()
- require "cjrcle"
- windowwidth = 1000
- windowheight = 1000
- love.graphics.setBackgroundColor(0, 0, 0)
- sucess = love.window.setMode(windowwidth, windowheight) -- what does this line do? ... will work but the circle is offset
- ctheta = math.pi/2
- x = 0
- y = 0
- b = math.pi/ctheta
- sinxloc = 0
- startposX = 0
- discr = 50
- hr = 10
- speed = 1
- thrown = false -- a variable to check if the hammer has been let go
- -- hammer position
- hxpos = startposX + discr*math.cos(math.pi/2)/math.pi
- hypos = y - discr*math.sin(math.pi/2)
- rv = 1 -- rotational velocity
- end
- function love.update(dt)
- -- smaller angle = slower rotspeed
- ctheta = ctheta - rv*math.pi*dt/3
- if ctheta < math.pi/2 - 2*math.pi then
- ctheta = math.pi/2
- end
- --if speed < 10 then
- --speed = speed*1.01
- --startposX = startposX + speed
- --end
- hxpos = startposX + discr*math.cos(ctheta)
- hypos = y - discr*math.sin(ctheta)
- local m = math.pow(2, dt)
- if love.keyboard.isDown("up") then
- b = b*m --the period of the sine wave is pi/delthe... i think?
- end
- if love.keyboard.isDown("down") then
- b = b/m
- end
- end
- function love.keypressed(key)
- if key == "space" and startposX < 0 then
- thrown = true
- end
- if key == "r" then
- b = math.pi/2
- end
- end
- function arccirc(r, x, y, delthe)
- arcang = math.atan(y + r/x + r)
- for theta = 0, arcang, delthe do
- 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)
- end
- end
- function love.draw()
- --love.graphics.push()
- love.graphics.translate(windowwidth/2, windowheight/2)
- love.graphics.setColor(0, 1, 0)
- love.graphics.print("sine = " .. -hypos/50, -400, -400)
- love.graphics.setColor(1, 0, 0)
- love.graphics.print("cosine = " .. hxpos/50, -400, -390)
- love.graphics.setColor(.6, 0, .6)
- love.graphics.print("tangent = " .. math.tan(ctheta), -400, -380)
- love.graphics.setColor(.9, 0, .9)
- love.graphics.print("cotangent = " .. 1/math.tan(ctheta),-400, -370)
- love.graphics.setColor(.7,1,.7)
- love.graphics.print("secant = " .. 1/math.cos(ctheta), -400, -360)
- love.graphics.setColor(0,1,0)
- love.graphics.print("cosecant = " .. 1/math.sin(ctheta) , -400, -350)
- love.graphics.print("b: " .. b, -400, -340)
- love.graphics.print("Ø: ".. ctheta .. " radians, or ", -400, -330 )
- love.graphics.print("which is also " .. ctheta*180/math.pi .. " degrees!", -400, -320)
- -- orange cjrcle
- --
- love.graphics.setColor(.7, .6, .3)
- cjrcle(discr, startposX, 0, 32)
- --cjrcle(discr, startposX, 0, )
- -- blue cjrcle for player
- love.graphics.setColor(0, 0, 1)
- cjrcle(10, hxpos, hypos)
- -- violet tangent and cotantgent lines
- love.graphics.setColor(.6,0,.6)
- love.graphics.line(50*math.cos(ctheta), -50*math.sin(ctheta), 0, -50/math.sin(ctheta))
- love.graphics.setColor(0,.9,.9)
- love.graphics.line(50*math.cos(ctheta), -50*math.sin(ctheta), 50/math.cos(ctheta), 0)
- -- secant and cosecant
- love.graphics.setColor(0, 1, 0)
- love.graphics.line(0,0,0,-50/math.sin(ctheta)) --csc
- love.graphics.setColor(0, 1, 1)
- love.graphics.line(0,0,50/math.cos(ctheta),0) --sec
- --different triangle
- --red horizontal cosine line
- love.graphics.setColor(1, 0, 0)
- love.graphics.line(0, 0, hxpos, 0)
- -- yellow vertical sine line
- love.graphics.setColor(0, 1, 0)
- love.graphics.line(hxpos, hypos, 50*math.cos(ctheta), 0)
- -- radius
- love.graphics.setColor(.5, .3, 0)
- love.graphics.line(0, 0, hxpos, hypos)
- for thetarc = math.atan(hypos/hxpos), math.sin(ctheta), -math.pi/60 do -- arctan is both plus and minus?
- love.graphics.setColor(0,1,0)
- 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))
- thetarc = thetarc + math.pi/60
- end
- -- sincurve
- sinxloc = 50
- cosyloc = 50
- love.graphics.setColor(1, 0, 0.4)
- for theta = -32*math.pi, 32*math.pi, math.pi/180 do
- love.graphics.line(25 + sinxloc, -50*math.sin(b*theta), 25 +sinxloc + math.pi/360, -50*math.sin(b*theta + math.pi/360))
- sinxloc = sinxloc + 1
- end
- --[[
- N.B!
- theta = arctan sin/cos
- the period of the sine wave is pi/delthe... i think?
- if theta is < arctan
- ]]
- love.graphics.setColor(1,0,0)
- love.graphics.print("x: " .. hxpos/50, hxpos, hypos)
- love.graphics.print("y: " .. -hypos/50, hxpos, hypos+10)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement