done with parsing logic in functional core
This commit is contained in:
@@ -1,25 +1,26 @@
|
||||
structure ParseGrid =
|
||||
struct
|
||||
fun makeGrid (canvasWidth, canvasHeight) =
|
||||
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})
|
||||
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 then yAxis
|
||||
if y > ey then
|
||||
yAxis
|
||||
else
|
||||
let
|
||||
val yAxis = Vector.update (yAxis, y, colour)
|
||||
in
|
||||
loopY (yAxis, x, ex, y + 1, ey, colour)
|
||||
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 then grid
|
||||
if x > ex then
|
||||
grid
|
||||
else
|
||||
let
|
||||
val yAxis = Vector.sub (grid, x)
|
||||
@@ -29,12 +30,7 @@ struct
|
||||
loopX (grid, x + 1, ex, y, ey, colour)
|
||||
end
|
||||
in
|
||||
fun applyItem (grid, item) =
|
||||
let
|
||||
val {x, y, ex, ey, r, g, b, a} = item
|
||||
val colour = {r = r, g = g, b = b, a = a}
|
||||
in
|
||||
loopX (grid, x, ex, y, ey, colour)
|
||||
end
|
||||
fun applyItem (grid, x, y, ex, ey, colour) =
|
||||
loopX (grid, x, ex, y, ey, colour)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user