2025-08-09 08:43:51 +01:00
|
|
|
structure Grid =
|
|
|
|
|
struct
|
2025-08-09 09:13:03 +01:00
|
|
|
type pixel = {r: int, g: int, b: int, a: int}
|
2025-08-09 08:43:51 +01:00
|
|
|
|
2025-08-09 09:13:03 +01:00
|
|
|
type t = pixel vector vector
|
2025-08-09 08:43:51 +01:00
|
|
|
|
|
|
|
|
val emptyPixel = {r = 0, g = 0, b = 0, a = 0}
|
|
|
|
|
|
2025-08-09 09:13:03 +01:00
|
|
|
fun isBlank ({a, ...}: pixel) = a = 0
|
2025-08-09 08:43:51 +01:00
|
|
|
|
|
|
|
|
fun changeGridSize maxSide grid =
|
|
|
|
|
Vector.tabulate (maxSide, fn i =>
|
|
|
|
|
if i < Vector.length grid then
|
|
|
|
|
let
|
|
|
|
|
val yAxis = Vector.sub (grid, i)
|
|
|
|
|
in
|
|
|
|
|
Vector.tabulate (maxSide, fn ii =>
|
|
|
|
|
if ii < Vector.length yAxis then Vector.sub (yAxis, ii)
|
|
|
|
|
else emptyPixel)
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
Vector.tabulate (maxSide, fn _ => emptyPixel))
|
2025-08-09 09:13:03 +01:00
|
|
|
|
|
|
|
|
fun updateGrid (grid, newX, newY, pixel) =
|
|
|
|
|
let
|
|
|
|
|
val yAxis = Vector.sub (grid, newX)
|
|
|
|
|
val yAxis = Vector.update (yAxis, newY, pixel)
|
|
|
|
|
in
|
|
|
|
|
Vector.update (grid, newX, yAxis)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
fun makeEmpty maxSide =
|
|
|
|
|
Vector.tabulate (maxSide, fn _ =>
|
|
|
|
|
Vector.tabulate (maxSide, fn _ => emptyPixel))
|
2025-08-09 08:43:51 +01:00
|
|
|
end
|