Last active
February 24, 2025 03:34
-
-
Save ggorlen/74b9ce8e4855804e0019b00756d28b1d to your computer and use it in GitHub Desktop.
love2d-10print
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local size = 20 | |
local tiles = {} | |
function love.load() | |
local r, g, b = love.math.colorFromBytes(0, 130, 200) | |
love.graphics.setBackgroundColor(r, g, b) | |
love.window.setTitle("10 print") | |
height = love.graphics.getHeight() | |
width = love.graphics.getWidth() | |
math.randomseed(os.time()) | |
end | |
function love.mousepressed(x, y, button) | |
love.event.quit(0) | |
end | |
function love.update(dt) | |
table.insert(tiles, math.random(0, 1)) | |
if #tiles > height / size * width / size then | |
local new_tiles = {} | |
for i = width / size + 1, #tiles do | |
table.insert(new_tiles, tiles[i]) | |
end | |
tiles = new_tiles | |
end | |
end | |
function love.draw() | |
local i = 0 | |
local j = 0 | |
for k, e in ipairs(tiles) do | |
if k % (width / size) == 0 then | |
i = 0 | |
j = j + size | |
end | |
if e == 0 then | |
love.graphics.line(i, j, i + size, j + size) | |
else | |
love.graphics.line(i + size, j, i, j + size) | |
end | |
i = i + size | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment