diff --git a/0010-on.draw b/0010-on.draw new file mode 100644 index 0000000..a120a86 --- /dev/null +++ b/0010-on.draw @@ -0,0 +1,9 @@ +on.draw = function() + if Draw == 'problem' then + draw_sum_grid(Problem) + elseif Draw == 'char' then + draw_sum_grid(Char) + else + draw_sum_grid(Solution) + end +end \ No newline at end of file diff --git a/0011-draw_sum_grid b/0011-draw_sum_grid new file mode 100644 index 0000000..d15cacc --- /dev/null +++ b/0011-draw_sum_grid @@ -0,0 +1,23 @@ +draw_sum_grid = function(g) + -- lines + love.graphics.setLineWidth(3) + local x1,y1 = 250,200 + local x2,y2 = 450,400 + love.graphics.line(x1,y1, x2,y1) + love.graphics.line(x1,y2, x2,y2) + love.graphics.line(x1,y1, x1,y2) + love.graphics.line(x2,y1, x2,y2) + local xm,ym = (x1+x2)/2, (y1+y2)/2 + love.graphics.line(x1,ym, x2,ym) + love.graphics.line(xm,y1, xm,y2) + -- data + draw_cell(g.col_totals[1], x1,y1-Square_side) + draw_cell(g.col_totals[2], xm,y1-Square_side) + draw_cell(g.row_totals[1], x1-Square_side, y1) + draw_cell(g.row_totals[2], x1-Square_side, ym) + for x=1,2 do + for y=1,2 do + draw_cell(g.data[y][x], x1+(x-1)*Square_side, y1+(y-1)*Square_side) + end + end +end \ No newline at end of file diff --git a/0012-on.initialize b/0012-on.initialize new file mode 100644 index 0000000..a6e0a96 --- /dev/null +++ b/0012-on.initialize @@ -0,0 +1,5 @@ +on.initialize = function() + Font_size = Square_side*0.8 + Padding = (Square_side-Font_size)/2 + love.graphics.setFont(love.graphics.newFont(Font_size)) +end \ No newline at end of file diff --git a/0013-Square_side b/0013-Square_side new file mode 100644 index 0000000..4570c08 --- /dev/null +++ b/0013-Square_side @@ -0,0 +1 @@ +Square_side = 100 diff --git a/0014-Font_size b/0014-Font_size new file mode 100644 index 0000000..1e8f84c --- /dev/null +++ b/0014-Font_size @@ -0,0 +1 @@ +Font_size = 0 diff --git a/0015-Padding b/0015-Padding new file mode 100644 index 0000000..514ea33 --- /dev/null +++ b/0015-Padding @@ -0,0 +1 @@ +Padding = 0 \ No newline at end of file diff --git a/0016-generate_sum_grid b/0016-generate_sum_grid new file mode 100644 index 0000000..f330c10 --- /dev/null +++ b/0016-generate_sum_grid @@ -0,0 +1,14 @@ +generate_sum_grid = function() + -- a sum grid is fully characterized by 4 numbers + Char = { + data = { + { math.random(1,9), math.random(1,9) }, + { '', ''}, + }, + row_totals = { '', '' }, + } + Char.col_totals = { + math.random(Char.data[1][1]+1,10), + math.random(Char.data[1][2]+1,10) + } +end \ No newline at end of file diff --git a/0017-on.keychord_press b/0017-on.keychord_press new file mode 100644 index 0000000..0a1b66d --- /dev/null +++ b/0017-on.keychord_press @@ -0,0 +1,14 @@ +on.keychord_press = function(chord, key) + if chord == 'C-n' then + generate_sum_grid() + solve() + elseif chord == '`' then + if Draw == 'problem' then + Draw = 'char' + elseif Draw == 'char' then + Draw = 'solution' + elseif Draw == 'solution' then + Draw = 'problem' + end + end +end \ No newline at end of file diff --git a/0018-Char b/0018-Char new file mode 100644 index 0000000..a242a72 --- /dev/null +++ b/0018-Char @@ -0,0 +1,9 @@ +-- a set of numbers that uniquely characterizes a sum-grid instance. +Char = { + row_totals={0, 0}, + col_totals={0, 0}, + data={ + {0, 0}, + {0, 0}, + }, +} \ No newline at end of file diff --git a/0019-Solution b/0019-Solution new file mode 100644 index 0000000..351bf03 --- /dev/null +++ b/0019-Solution @@ -0,0 +1,9 @@ +-- solution for the sum-grid problem defined by Char. +Solution = { + row_totals={0, 0}, + col_totals={0, 0}, + data={ + {0, 0}, + {0, 0}, + }, +} \ No newline at end of file diff --git a/0020-solve b/0020-solve new file mode 100644 index 0000000..38421ce --- /dev/null +++ b/0020-solve @@ -0,0 +1,21 @@ +solve = function() + print('solve') + -- copy the slots we have + local c = Char.col_totals + local d = Char.data + Solution = { + col_totals = {c[1], c[2]}, + data = { + {d[1][1], d[1][2] }, + { }, + } + } + -- fill out the remaining data + Solution.data[2][1] = c[1] - d[1][1] + Solution.data[2][2] = c[2] - d[1][2] + d = Solution.data + Solution.row_totals = { + d[1][1] + d[1][2], + d[2][1] + d[2][2], + } +end \ No newline at end of file diff --git a/0021-Draw b/0021-Draw new file mode 100644 index 0000000..6785551 --- /dev/null +++ b/0021-Draw @@ -0,0 +1 @@ +Draw = 'char' \ No newline at end of file diff --git a/0022-Problem b/0022-Problem new file mode 100644 index 0000000..0279c88 --- /dev/null +++ b/0022-Problem @@ -0,0 +1,8 @@ +Problem = { + row_totals={0, 0}, + col_totals={0, 0}, + data={ + {0, 0}, + {0, 0}, + }, +} \ No newline at end of file diff --git a/0023-draw_cell b/0023-draw_cell new file mode 100644 index 0000000..652656d --- /dev/null +++ b/0023-draw_cell @@ -0,0 +1,6 @@ +draw_cell = function(n, x,y) + local s = tostring(n) + local w = App.width(s) + local px = (Square_side-w)/2 + love.graphics.print(s, x+px, y+Padding) +end \ No newline at end of file diff --git a/main.lua b/main.lua index 1f11c0c..590f432 100644 --- a/main.lua +++ b/main.lua @@ -62,9 +62,8 @@ function App.initialize(arg) - -- TODO: app-specific stuff goes here -- keep a few blank lines around: https://merveilles.town/@akkartik/110084833821965708 - love.window.setTitle('TODO') + love.window.setTitle('Sum Grid')