Files
sml-projects/fcore/grid.sml

36 lines
918 B
Standard ML
Raw Normal View History

structure Grid =
struct
type pixel = {r: int, g: int, b: int, a: int}
type t = pixel vector vector
val emptyPixel = {r = 0, g = 0, b = 0, a = 0}
fun isBlank ({a, ...}: pixel) = a = 0
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))
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))
end