Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function love.load()
- --Object = require "classic"
- require "cjrcle"
- windowwidth = 1000
- windowheight = 1000
- love.graphics.setBackgroundColor(0, 0, 0)
- sucess = love.window.setMode(windowwidth, windowheight)
- 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)
- nxpos = hxpos
- nypos = hypos
- rv = 1 -- rotational velocity
- end
- --[[
- equation of tangent line y = -x + 50*math.sqrt(2)
- ]]
- function love.keypressed(key)
- if key == "space" then
- thrown = true
- end
- if key == "r" then
- b = math.pi/2
- end
- end
- function love.update(dt)
- ctheta = ctheta - rv*math.pi*dt/30 -- change in theta
- --ntheta = ctheta -- theta now
- if ctheta < ctheta - 2*math.pi then -- this line seems to not work
- ctheta = math.pi/2
- end
- if not thrown then
- ctheta = ctheta -rv*math.pi*dt/30
- if ctheta <= math.pi/2 - 2*math.pi then -- never let ctheta sink below -3*π/2
- ctheta = math.pi/2
- end
- hxpos = startposX + discr*math.cos(ctheta) -- this snippet of code calculates the hammer position for the next frame... dX/dY
- hypos = y - discr*math.sin(ctheta)
- ntheta = ctheta -- keep track of the current value of the change is theta with the current value of theta
- end
- -- must determine the quadrant and if the tangent or cotantent should be followed
- if thrown == true then
- ctheta = ctheta
- if ntheta <= math.pi/2 and ntheta > 0 then -- follow the tangent
- hxpos = hxpos + 50*dt*10*math.cos(ctheta)
- hypos = hxpos*hxpos/math.sqrt(50^2 + hxpos*hxpos) - 50*math.cos(ctheta) - hypos-- + hxpos -- hypos is now equal to dx/dy at ntheta
- cjrcle(10, hxpos, hypos)
- end
- if ntheta <= 0 and ntheta > -math.pi/2 then -- follow the cotangent... it does... but with a bit of a hop first?
- --hxpos = hxpos + 1/50*dt*10*math.cos(ntheta) -- follow the cotangent
- hxpos = hxpos - 50*dt*10*math.cos(ctheta) -- follow the cotangent
- --hxpos = hxpos + 50*dt*10*math.sin(ntheta)
- hypos = hxpos*hxpos/math.sqrt(50^2 + hxpos*hxpos) + 50*math.cos(ctheta) - hypos-- + hxpos -- hypos is now equal to dx/dy at ntheta
- cjrcle(10, hxpos, hypos)
- end
- end
- 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 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.translate(windowwidth/2, windowheight/2)
- love.graphics.setColor(1, 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(0, 0, 1)
- love.graphics.print("tangent = " .. math.tan(ctheta), -400, -380)
- love.graphics.setColor(1,.6,.5)
- love.graphics.print("cotangent = " .. 1/math.tan(ctheta),-400, -370)
- love.graphics.setColor(0,1,0)
- love.graphics.print("secant = " .. 1/math.cos(ctheta), -400, -360)
- love.graphics.setColor(1,0,1)
- love.graphics.print("cosecant = " .. 1/math.sin(ctheta) , -400, -350)
- love.graphics.setColor(.5,.5,.5)
- love.graphics.print("b: " .. b, -400, -340)
- love.graphics.print("Ø: ".. ctheta .. " radians, or ", -400, -330)
- love.graphics.print(ctheta/math.pi .."π radians", -100, -330 )
- love.graphics.print("which is also " .. ctheta*180/math.pi .. " degrees!", -400, -300)
- love.graphics.print("the derrivative of the quation X^2 + Y^2 = r^2 @ r = 50: ", -400, -280)
- love.graphics.print("dY/dX = -x^2/(math.sqrt(50^2 - x) + 2500): ", -400, -260)
- love.graphics.print("tangent line has equation: ", -400, -240)
- love.graphics.print("Y = mX + b", -400, -220)
- love.graphics.print("Y = " .. -hxpos/math.sqrt(50*50 - hxpos*hxpos)*50/50 .. "*" .. hxpos .. " + B", -400, -200)
- love.graphics.print("B = " .. hxpos/math.sqrt(50*50 - hxpos*hxpos)/50, -400, -190)
- love.graphics.print("slope m = " .. -hxpos/math.sqrt(50*50 - hxpos*hxpos)/50, -400, -170)
- love.graphics.print("Tangent line has equation:", -400, -150)
- love.graphics.print("Y = " .. -hxpos*(math.sqrt(50*50 - hxpos*hxpos))/50 .. "X + " .. hxpos*(math.sqrt(50*50 - hxpos*hxpos))/50, -400, -130)
- love.graphics.print("The value of thrown is: ", -400, -120)
- if thrown then
- love.graphics.print("thrown!", -200, -120)
- else
- love.graphics.print("not thrown:(", -200, -120) -- thrown not being updated:()
- end
- -- orange cjrcle
- love.graphics.setColor(.7, .6, .3)
- cjrcle(discr, startposX, 0, 32)
- -- blue cjrcle for player
- love.graphics.setColor(1, 1, 1)
- cjrcle(10, hxpos, hypos)
- -- tangent and cotantgent lines
- love.graphics.setColor(1,.6,.5)
- love.graphics.line(50*math.cos(ctheta), -50*math.sin(ctheta), 0, -50/math.sin(ctheta))
- love.graphics.setColor(0, 0, 1)
- love.graphics.line(50*math.cos(ctheta), -50*math.sin(ctheta), 50/math.cos(ctheta), 0)
- -- secant and cosecant lines
- love.graphics.setColor(1, 0, 1)
- love.graphics.line(0,0,0,-50/math.sin(ctheta)) --csc
- love.graphics.setColor(1, 1, .1)
- love.graphics.setColor(0, 1, 0)
- love.graphics.line(0,0,50/math.cos(ctheta),0) --sec
- --red cosine line
- love.graphics.setColor(1, 0, 0)
- love.graphics.line(0, 0, hxpos, 0)
- -- y sine line
- love.graphics.setColor(1, 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)
- --anglethetaprints
- love.graphics.print("Ø",hxpos/2, hypos)
- for thetarc = math.atan2(hypos,hxpos), math.sin(ctheta), -math.pi/60 do
- love.graphics.setColor(0,1,0)
- if hxpos > 0 and hypos > 0 then
- if thetarc <= math.pi/2 and thetarc > 0 then
- 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
- --love.graphics.print("Ø",hxpos/2, hypos/2)
- end
- end
- if hxpos < 0 and hypos > 0 then
- --if math.cos(thetarc < 0)
- if thetarc <= 0 and thetarc > -math.pi/2 then
- 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
- --love.graphics.print("Ø",hxpos/2, hypos/2)
- end
- end
- end
- --sinecurve
- 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
- cosyloc = cosyloc + 1
- end
- 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