Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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}}
- function love.load()
- ex, ey = 10, 10
- step = 100
- love.window.setMode(800, 600, {resizable = true})
- end
- --
- function love.update(dt)
- if (love.keyboard.isDown("w")) then
- ey = ey - step * dt
- end
- if (love.keyboard.isDown("s")) then
- ey = ey + step * dt
- end
- if (love.keyboard.isDown("a")) then
- ex = ex - step * dt
- end
- if (love.keyboard.isDown("d")) then
- ex = ex + step * dt
- end
- end
- --
- function rect(t, l, w, h)
- love.graphics.rectangle("fill", l, t, w, h)
- end
- function drawRecursiveRect(s, t, l, w, h, d)
- --create the stencil that draws d rectangles,
- love.graphics.stencil(s, "increment", 1)
- --set the stencil test so that it only draws where all d rectangles overlap.
- love.graphics.setStencilTest("gequal", d)
- --draw an extremely large rectangle. Only the parts in the stencil will be drawn.
- love.graphics.setColor(colors[(d-1) % #colors + 1])
- rect(0, 0, 2000, 2000)
- --end the stencil test.
- love.graphics.setStencilTest()
- if (d < 20) then
- --create the stencil function for the next iteration,
- t2, l2, w2, h2 = t + ey, l + ex, 9*w/10, 9*h/10
- s2 = function()
- s(t, l, w, h)
- rect(t2, l2, w2, h2)
- end
- --draw the next rectangle.
- drawRecursiveRect(s2, t2, l2, w2, h2, d + 1)
- end
- end
- --
- function love.draw()
- ----[[
- t, l, w, h = 0, 0, 800, 600
- s = function()
- rect(t, l, w, h)
- end
- drawRecursiveRect(s, t, l, w, h, 1)
- --]]
- --[[
- --the following works:
- s = function()
- rect(0, 0, 400, 300)
- end
- s2 = function()
- s()
- rect(200, 150, 400, 300)
- end
- love.graphics.stencil(s2, "increment", 1)
- love.graphics.setStencilTest("gequal", 2)
- love.graphics.setColor(1, 1, 1, 1)
- rect(0, 0, 2000, 2000)
- love.graphics.setStencilTest()
- ]]
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement