add functions to add and remove pixels from layer-tree

This commit is contained in:
2025-08-09 09:13:03 +01:00
parent e634bb25d7
commit 34c29bcbba
5 changed files with 35 additions and 14 deletions

View File

@@ -1,12 +1,12 @@
structure Grid =
struct
type square = {r: int, g: int, b: int, a: int}
type pixel = {r: int, g: int, b: int, a: int}
type t = square vector vector
type t = pixel vector vector
val emptyPixel = {r = 0, g = 0, b = 0, a = 0}
fun isBlank ({a, ...}: square) = a = 0
fun isBlank ({a, ...}: pixel) = a = 0
fun changeGridSize maxSide grid =
Vector.tabulate (maxSide, fn i =>
@@ -20,4 +20,16 @@ struct
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