Advertisement
S3rval

handdraw with Lua

Dec 15th, 2019
356
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.61 KB | None | 0 0
  1. ---------------------------------------------------------------------------------
  2. -- Petit programme dessinant un coeur ou un m grace à l'utilisation de formules
  3. -- générées par le programme FP2E : https://kroxx.itch.io/from-path-to-equations
  4. -- fait par un élève de Gamecodeur.fr
  5. -- Voir son devlog : https://www.gamecodeur.fr/devlogs/62059/
  6. --
  7. -- Voir dans le code la ligne "ICI : choisir la forme à dessiner" pour choisir la
  8. -- forme.
  9. ---------------------------------------------------------------------------------
  10.  
  11. -- Cette ligne permet d'afficher des traces dans la console pendant l'éxécution
  12. io.stdout:setvbuf('no')
  13.  
  14. -- Empèche Love de filtrer les contours des images quand elles sont redimentionnées
  15. -- Indispensable pour du pixel art
  16. love.graphics.setDefaultFilter("nearest")
  17.  
  18. -- Cette ligne permet de déboguer pas à pas dans ZeroBraneStudio
  19. if arg[#arg] == "-debug" then require("mobdebug").start() end
  20.  
  21. local lstShapes = {}
  22.  
  23. local speed = 200
  24. local lastPoint = 10
  25.  
  26. function love.load()
  27.  
  28.   largeur = love.graphics.getWidth()
  29.   hauteur = love.graphics.getHeight()
  30.  
  31.   local shape
  32.  
  33.   -- Initialisation de du tracé paramétrique
  34.   for t = 0, (2 * math.pi), 0.005 do
  35.    
  36.     -- ICI : choisir la forme à dessiner
  37.     shape = CreateShape(xCoeur(t), yCoeur(t))
  38.     -- shape = CreateShape(xM(t), yM(t))
  39.  
  40.     table.insert(lstShapes, shape)
  41.    
  42.   end
  43.  
  44. end
  45.  
  46. function love.update(dt)
  47.  
  48.   -- Gestion du tracé progressif
  49.   if lastPoint < #lstShapes then
  50.     lastPoint = lastPoint + speed * dt
  51.     if lastPoint > #lstShapes then
  52.       lastPoint = #lstShapes
  53.     end
  54.   end
  55.  
  56. end
  57.  
  58. function love.draw()
  59.    
  60.     -- affichage progressif
  61.     if (#lstShapes ~= 0) then
  62.       for i= 1, lastPoint do
  63.         lstShapes[i].draw()
  64.       end
  65.     end
  66.    
  67.     -- affichage en totalité
  68.     --if (#lstShapes ~= 0) then
  69.     --  for i, shape in ipairs(lstShapes) do
  70.     --    shape.draw()
  71.     --  end
  72.     --end
  73. end
  74.  
  75. function love.keypressed(key)
  76.  
  77.   --print(key)
  78.  
  79. end
  80.  
  81. function xCoeur(t)
  82.  
  83.   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)
  84.   return x
  85.  
  86. end
  87.  
  88. function yCoeur(t)
  89.  
  90.   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)+
  91. cos(20*t)+cos(27*t)
  92.   return y
  93.  
  94. end
  95.  
  96.  
  97. function xM(t)
  98.  
  99.   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)+
  100. 2*cos(14*t)-cos(15*t)+cos(16*t)-cos(17*t)-cos(19*t)+cos(29*t)
  101.  
  102.   return x
  103.  
  104. end
  105.  
  106. function yM(t)
  107.  
  108.   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)
  109.  
  110.   return y
  111.  
  112. end
  113.  
  114. function cos(pValue)
  115.  
  116.   -- surtout ne pas arrondir sinon on perd tout le détail du tracé !!
  117.   -- return math.floor(math.cos(pValue))
  118.  
  119.   return math.cos(pValue)
  120.  
  121. end
  122.  
  123. --------------------------------------------------------------------------
  124. function CreateShape(pX, pY)
  125.  
  126.   local myShape = {}
  127.  
  128.   myShape.x = pX
  129.   myShape.y = pY
  130.  
  131.   myShape.update = function(dt)
  132.  
  133.  
  134.   end
  135.  
  136.   myShape.draw = function()
  137.  
  138.     if myShape ~= nil then
  139.       love.graphics.points(myShape.x, myShape.y )
  140.     end
  141.  
  142.   end
  143.  
  144.   return myShape
  145.  
  146. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement