SHARE
TWEET

Untitled

a guest Feb 18th, 2020 97 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. colors = {{1, 0, 0, 1}, {1, 0.5, 0, 1}, {1, 1, 0, 1}, {0.5, 1, 0, 1}, {0, 1, 0, 1}, {0, 1, 0.5, 1}, {0, 1, 1, 1}, {0, 0.5, 1, 1}, {0, 0, 1, 1}, {0.5, 0, 1, 1}, {1, 0, 1, 1}, {1, 0, 0.5, 1}}
  2.  
  3. function love.load()
  4.     ex, ey = 10, 10
  5.     step = 100
  6.     love.window.setMode(800, 600, {resizable = true})
  7. end
  8. --
  9. function love.update(dt)
  10.     if (love.keyboard.isDown("w")) then
  11.         ey = ey - step * dt
  12.     end
  13.     if (love.keyboard.isDown("s")) then
  14.         ey = ey + step * dt
  15.     end
  16.     if (love.keyboard.isDown("a")) then
  17.         ex = ex - step * dt
  18.     end
  19.     if (love.keyboard.isDown("d")) then
  20.         ex = ex + step * dt
  21.     end
  22. end
  23. --
  24. function rect(t, l, w, h)
  25.     love.graphics.rectangle("fill", l, t, w, h)
  26. end
  27.  
  28. function drawRecursiveRect(s, t, l, w, h, d)
  29.     --create the stencil that draws d rectangles,
  30.     love.graphics.stencil(s, "increment", 1)
  31.     --set the stencil test so that it only draws where all d rectangles overlap.
  32.     love.graphics.setStencilTest("gequal", d)
  33.     --draw an extremely large rectangle. Only the parts in the stencil will be drawn.
  34.     love.graphics.setColor(colors[(d-1) % #colors + 1])
  35.     rect(0, 0, 2000, 2000)
  36.     --end the stencil test.
  37.     love.graphics.setStencilTest()
  38.    
  39.     if (d < 20) then
  40.         --create the stencil function for the next iteration,
  41.         t2, l2, w2, h2 = t + ey, l + ex, 9*w/10, 9*h/10
  42.         s2 = function()
  43.             s(t, l, w, h)
  44.             rect(t2, l2, w2, h2)
  45.         end
  46.         --draw the next rectangle.
  47.         drawRecursiveRect(s2, t2, l2, w2, h2, d + 1)
  48.     end
  49.  
  50. end
  51. --
  52. function love.draw()
  53.  
  54.     ----[[
  55.     t, l, w, h = 0, 0, 800, 600
  56.     s = function()
  57.         rect(t, l, w, h)
  58.     end
  59.     drawRecursiveRect(s, t, l, w, h, 1)
  60.     --]]
  61.  
  62.     --[[
  63.     --the following works:
  64.     s = function()
  65.         rect(0, 0, 400, 300)
  66.     end
  67.     s2 = function()
  68.         s()
  69.         rect(200, 150, 400, 300)
  70.     end
  71.     love.graphics.stencil(s2, "increment", 1)
  72.     love.graphics.setStencilTest("gequal", 2)
  73.     love.graphics.setColor(1, 1, 1, 1)
  74.     rect(0, 0, 2000, 2000)
  75.     love.graphics.setStencilTest()
  76.     ]]
  77.    
  78. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top