Created
June 11, 2022 21:24
-
-
Save akkartik/ce3110a104ca101523b68c4b060a4525 to your computer and use it in GitHub Desktop.
A little number grid for preschool math exercises at home
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
-- To run: | |
-- Download LÖVE from https://love2d.org | |
-- Download this file to a directory and rename it to `main.lua` | |
-- Run the program from that directory. | |
-- * on Linux (using the appimage binary): `chmod +x path/to/love-11.4-x86_64.AppImage; path/to/love-11.4-x86_64.AppImage .` | |
-- * on Mac: `path/to/love.app/Contents/MacOS/love .` | |
local circle = love.graphics.circle | |
local color = love.graphics.setColor | |
local rect = love.graphics.rectangle | |
local keyboard = love.keyboard | |
function love.load() | |
love.window.setMode(1280, 720) | |
love.window.setTitle('Number grid') | |
end | |
function love.update(dt) | |
end | |
function find(table, val) | |
for _, x in ipairs(table) do | |
if x == val then | |
return true | |
end | |
end | |
return false | |
end | |
function love.draw() | |
local x, y = 56, 56 | |
local primes={2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 53, 59, 61, 71, 73, 79, 83, 89, 97} | |
for i=1,100 do | |
if | |
--? false | |
--? i%10 == 1 | |
--? math.floor(math.sqrt(i)) == math.sqrt(i) | |
find(primes, i) | |
then | |
color(0, 0.4, 0) | |
else | |
color(0.5, 0.5, 0.5) | |
end | |
love.graphics.rectangle('fill', x-4, y-4, 52, 44) | |
color(1, 1, 1) | |
love.graphics.print(tostring(i), x, y, 0, 2) | |
if i%10 == 0 then | |
y = y + 56 | |
x = 56 | |
else | |
x = x + 56 | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment