Files
sml-projects/dotscape/fcore/parser/parse-grid.sml

37 lines
1019 B
Standard ML
Raw Normal View History

2025-07-12 02:02:21 +01:00
structure ParseGrid =
struct
fun make (canvasWidth, canvasHeight) =
2025-07-12 02:02:21 +01:00
let
val maxPoints = Int.max (canvasWidth, canvasHeight)
2025-07-12 07:19:34 +01:00
val emptyYAxis = Vector.tabulate (maxPoints, fn _ =>
{r = 0, g = 0, b = 0, a = 0})
2025-07-12 02:02:21 +01:00
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
2025-07-12 07:19:34 +01:00
yAxis
2025-07-12 02:02:21 +01:00
else
2025-07-12 07:19:34 +01:00
let val yAxis = Vector.update (yAxis, y, colour)
in loopY (yAxis, x, ex, y + 1, ey, colour)
2025-07-12 02:02:21 +01:00
end
fun loopX (grid, x, ex, y, ey, colour) =
if x > ex orelse x >= Vector.length grid then
2025-07-12 07:19:34 +01:00
grid
2025-07-12 02:02:21 +01:00
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)
2025-07-12 02:02:21 +01:00
end
end