Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ---------------------------------------------------------------------------------
- -- Petit programme dessinant un coeur ou un m grace à l'utilisation de formules
- -- générées par le programme FP2E : https://kroxx.itch.io/from-path-to-equations
- -- fait par un élève de Gamecodeur.fr
- -- Voir son devlog : https://www.gamecodeur.fr/devlogs/62059/
- --
- -- Voir dans le code la ligne "ICI : choisir la forme à dessiner" pour choisir la
- -- forme.
- ---------------------------------------------------------------------------------
- -- Cette ligne permet d'afficher des traces dans la console pendant l'éxécution
- io.stdout:setvbuf('no')
- -- Empèche Love de filtrer les contours des images quand elles sont redimentionnées
- -- Indispensable pour du pixel art
- love.graphics.setDefaultFilter("nearest")
- -- Cette ligne permet de déboguer pas à pas dans ZeroBraneStudio
- if arg[#arg] == "-debug" then require("mobdebug").start() end
- local lstShapes = {}
- local speed = 200
- local lastPoint = 10
- function love.load()
- largeur = love.graphics.getWidth()
- hauteur = love.graphics.getHeight()
- local shape
- -- Initialisation de du tracé paramétrique
- for t = 0, (2 * math.pi), 0.005 do
- -- ICI : choisir la forme à dessiner
- shape = CreateShape(xCoeur(t), yCoeur(t))
- -- shape = CreateShape(xM(t), yM(t))
- table.insert(lstShapes, shape)
- end
- end
- function love.update(dt)
- -- Gestion du tracé progressif
- if lastPoint < #lstShapes then
- lastPoint = lastPoint + speed * dt
- if lastPoint > #lstShapes then
- lastPoint = #lstShapes
- end
- end
- end
- function love.draw()
- -- affichage progressif
- if (#lstShapes ~= 0) then
- for i= 1, lastPoint do
- lstShapes[i].draw()
- end
- end
- -- affichage en totalité
- --if (#lstShapes ~= 0) then
- -- for i, shape in ipairs(lstShapes) do
- -- shape.draw()
- -- end
- --end
- end
- function love.keypressed(key)
- --print(key)
- end
- function xCoeur(t)
- local x = 264+43*cos(1*t)-28*cos(2*t)-41*cos(3*t)+13*cos(4*t)+5*cos(5*t)+6*cos(6*t)-3*cos(7*t)+cos(8*t)+2*cos(10*t)-3*cos(11*t)+cos(13*t)+cos(14*t)
- return x
- end
- function yCoeur(t)
- local y = 199-20*cos(1*t)-51*cos(2*t)+42*cos(3*t)+25*cos(4*t)-4*cos(5*t)+6*cos(6*t)+cos(7*t)+2*cos(9*t)+2*cos(10*t)-cos(11*t)+cos(13*t)+cos(16*t)+cos(17*t)+
- cos(20*t)+cos(27*t)
- return y
- end
- function xM(t)
- local x = 220-96*cos(1*t)+cos(2*t)-9*cos(3*t)+2*cos(4*t)-11*cos(5*t)-6*cos(6*t)-14*cos(7*t)+8*cos(8*t)-3*cos(9*t)+3*cos(10*t)-3*cos(11*t)+3*cos(12*t)-2*cos(13*t)+
- 2*cos(14*t)-cos(15*t)+cos(16*t)-cos(17*t)-cos(19*t)+cos(29*t)
- return x
- end
- function yM(t)
- local y = 183-27*cos(1*t)+13*cos(2*t)-16*cos(3*t)+11*cos(4*t)-16*cos(5*t)-cos(6*t)+32*cos(7*t)+14*cos(8*t)-cos(9*t)+cos(10*t)+3*cos(11*t)-2*cos(12*t)+cos(13*t)+ 3*cos(14*t)+3*cos(15*t)+cos(16*t)+cos(17*t)+2*cos(20*t)+3*cos(21*t)+cos(22*t)+cos(24*t)+cos(27*t)+cos(28*t)+cos(29*t)+cos(34*t)+cos(35*t)+cos(42*t)
- return y
- end
- function cos(pValue)
- -- surtout ne pas arrondir sinon on perd tout le détail du tracé !!
- -- return math.floor(math.cos(pValue))
- return math.cos(pValue)
- end
- --------------------------------------------------------------------------
- function CreateShape(pX, pY)
- local myShape = {}
- myShape.x = pX
- myShape.y = pY
- myShape.update = function(dt)
- end
- myShape.draw = function()
- if myShape ~= nil then
- love.graphics.points(myShape.x, myShape.y )
- end
- end
- return myShape
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement