local size = 100 local offsetH, offsetW = love.graphics.getHeight() / 2 - 250, love.graphics.getWidth() / 2 - 250 local grid = { {false, false, false, false, false}, {false, false, false, false, false}, {false, false, false, false, false}, {false, false, false, false, false}, {false, false, false, false, false}, } function flip(x, y) if grid[y] ~= nil and grid[y][x] ~= nil then grid[y][x] = not grid[y][x] end end function toggle(x, y) flip(x, y + 1, grid) flip(x + 1, y, grid) flip(x, y, grid) flip(x - 1, y, grid) flip(x, y - 1, grid) end function love.load() math.randomseed(os.time()) for i = 1, 20 do toggle(math.random(1, 5), math.random(1, 5)) end end function love.draw() for y = 1, 5 do for x = 1, 5 do if grid[y][x] then love.graphics.rectangle("fill", (x - 1) * size + offsetW, (y - 1) * size + offsetH, size, size) else love.graphics.rectangle("line", (x - 1) * size + offsetW, (y - 1) * size + offsetH, size, size) end end end end function love.mousepressed(x, y, button) local gridx = math.floor((x - offsetW) / size) + 1 local gridy = math.floor((y - offsetH) / size) + 1 toggle(gridx, gridy) end