Add 'dotscape/' from commit 'f306501a68a51b634e895c5fdac70788ae899d75'

git-subtree-dir: dotscape
git-subtree-mainline: 6b91d64fc3
git-subtree-split: f306501a68
This commit is contained in:
2026-04-24 00:30:08 +01:00
53 changed files with 9187 additions and 0 deletions

45
dotscape/fcore/grid.sml Normal file
View File

@@ -0,0 +1,45 @@
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))
fun flipHorizontally (xAxis: t) =
Vector.mapi
(fn (xIdx, yAxis) =>
let
val flippedXIdx = Vector.length xAxis - 1 - xIdx
val flippedYAxis = Vector.sub (xAxis, flippedXIdx)
in
Vector.mapi (fn (yIdx, _) => Vector.sub (flippedYAxis, yIdx)) yAxis
end) xAxis
end