Add 'dotscape/' from commit 'f306501a68a51b634e895c5fdac70788ae899d75'
git-subtree-dir: dotscape git-subtree-mainline:6b91d64fc3git-subtree-split:f306501a68
This commit is contained in:
36
dotscape/fcore/parser/parse-grid.sml
Normal file
36
dotscape/fcore/parser/parse-grid.sml
Normal file
@@ -0,0 +1,36 @@
|
||||
structure ParseGrid =
|
||||
struct
|
||||
fun make (canvasWidth, canvasHeight) =
|
||||
let
|
||||
val maxPoints = Int.max (canvasWidth, canvasHeight)
|
||||
val emptyYAxis = Vector.tabulate (maxPoints, fn _ =>
|
||||
{r = 0, g = 0, b = 0, a = 0})
|
||||
in
|
||||
Vector.tabulate (maxPoints, fn _ => emptyYAxis)
|
||||
end
|
||||
|
||||
local
|
||||
fun loopY (yAxis, x, ex, y, ey, colour) =
|
||||
if y > ey orelse y >= Vector.length yAxis then
|
||||
yAxis
|
||||
else
|
||||
let val yAxis = Vector.update (yAxis, y, colour)
|
||||
in loopY (yAxis, x, ex, y + 1, ey, colour)
|
||||
end
|
||||
|
||||
fun loopX (grid, x, ex, y, ey, colour) =
|
||||
if x > ex orelse x >= Vector.length grid then
|
||||
grid
|
||||
else
|
||||
let
|
||||
val yAxis = Vector.sub (grid, x)
|
||||
val yAxis = loopY (yAxis, x, ex, y, ey, colour)
|
||||
val grid = Vector.update (grid, x, yAxis)
|
||||
in
|
||||
loopX (grid, x + 1, ex, y, ey, colour)
|
||||
end
|
||||
in
|
||||
fun applyItem (grid, x, y, ex, ey, colour) =
|
||||
loopX (grid, x, ex, y, ey, colour)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user