add functionality to draw in different colours

This commit is contained in:
2025-07-11 16:39:39 +01:00
parent 040fc67c80
commit 7028391298
5 changed files with 35 additions and 29 deletions

BIN
dotscape

Binary file not shown.

View File

@@ -24,7 +24,7 @@ struct
val maxPoints = Int.max (canvasWidth, canvasHeight)
val squares = Vector.tabulate (maxPoints, fn _ =>
Vector.tabulate (maxPoints, fn _ => 0))
Vector.tabulate (maxPoints, fn _ => {r = 0, g = 0, b = 0, a = 0}))
in
{ mode = AppType.NORMAL_MODE
, squares = squares
@@ -43,10 +43,10 @@ struct
, openFilePath = ""
, fileBrowser = Vector.fromList []
, fileBrowserIdx = 0
, r = 0.0
, g = 0.0
, b = 0.0
, a = 1.0
, r = 0
, g = 0
, b = 0
, a = 1
, modalNum = 0
}
end

View File

@@ -4,9 +4,11 @@ struct
datatype file_browser_item = IS_FILE of string | IS_FOLDER of string
type square = {r: int, g: int, b: int, a: int}
type app_type =
{ mode: app_mode
, squares: int vector vector
, squares: square vector vector
, canvasWidth: int
, canvasHeight: int
, windowWidth: int
@@ -27,10 +29,10 @@ struct
, openFilePath: string
, fileBrowser: file_browser_item vector
, fileBrowserIdx: int
, r: Real32.real
, g: Real32.real
, b: Real32.real
, a: Real32.real
, r: int
, g: int
, b: int
, a: int
, modalNum: int
}
end

View File

@@ -33,7 +33,10 @@ struct
Vector.mapi
(fn (idx, el) =>
if idx = newX then
Vector.mapi (fn (iidx, iel) => if iidx = newY then 1 else iel) el
Vector.mapi
(fn (iidx, iel) =>
if iidx = newY then {r = r, g = g, b = b, a = a} else iel)
el
else
el) squares
in
@@ -534,8 +537,6 @@ struct
}
end
fun modalNumToFloat num = Real32.fromInt num / 255.0
fun r (app: app_type) : app_type =
let
val
@@ -563,7 +564,7 @@ struct
, modalNum
} = app
val r = modalNumToFloat modalNum
val r = modalNum
in
{ mode = mode
, mouseX = mouseX
@@ -586,7 +587,7 @@ struct
, g = g
, b = b
, a = a
, modalNum = modalNum
, modalNum = 0
}
end
@@ -617,7 +618,7 @@ struct
, modalNum
} = app
val g = modalNumToFloat modalNum
val g = modalNum
in
{ mode = mode
, mouseX = mouseX
@@ -640,7 +641,7 @@ struct
, g = g
, b = b
, a = a
, modalNum = modalNum
, modalNum = 0
}
end
@@ -671,7 +672,7 @@ struct
, modalNum
} = app
val b = modalNumToFloat modalNum
val b = modalNum
in
{ mode = mode
, mouseX = mouseX
@@ -694,7 +695,7 @@ struct
, g = g
, b = b
, a = a
, modalNum = modalNum
, modalNum = 0
}
end
@@ -725,7 +726,7 @@ struct
, modalNum
} = app
val a = modalNumToFloat modalNum
val a = modalNum
in
{ mode = mode
, mouseX = mouseX
@@ -748,7 +749,7 @@ struct
, g = g
, b = b
, a = a
, modalNum = modalNum
, modalNum = 0
}
end

View File

@@ -99,10 +99,7 @@ end
structure CollisionTree =
struct
(* ignoreData = any data we find in grid but which doesn't concern us
* so we omit from tree, to reduce number of items in tree,
* and therefore decrease the constant in O(n) *)
val ignoreData = 0
fun shouldIgnoreData {a, r = _, g = _, b = _} = a = 0
local
fun loopYAxis (x, y, eX, eY, yAxis, col) =
@@ -147,7 +144,7 @@ struct
val yAxis = Vector.sub (grid, x)
val data = Vector.sub (yAxis, y)
in
if data = ignoreData then
if shouldIgnoreData data then
bintree
else
let
@@ -218,8 +215,14 @@ struct
val endX = Ndc.fromPixelX (ex, windowWidth, windowHeight)
val startY = Ndc.fromPixelY (y, windowWidth, windowHeight)
val endY = Ndc.fromPixelY (ey, windowWidth, windowHeight)
val {r, g, b, a} = data
val r = Real32.fromInt r / 255.0
val g = Real32.fromInt g / 255.0
val b = Real32.fromInt b / 255.0
val a = Real32.fromInt a / 255.0
in
Ndc.ltrbToVertexRgb (startX, startY, endX, endY, 0.0, 0.0, 0.0) :: acc
Ndc.ltrbToVertexRgb (startX, startY, endX, endY, r, g, b) :: acc
end
fun toTriangles
@@ -250,7 +253,7 @@ struct
(* building and querying quad tree, plus compression *)
datatype quad_tree =
LEAF of {x: int, y: int, ex: int, ey: int, data: int}
LEAF of {x: int, y: int, ex: int, ey: int, data: AppType.square}
| NODE of {tl: quad_tree, tr: quad_tree, bl: quad_tree, br: quad_tree}
| EMPTY
@@ -278,7 +281,7 @@ struct
val yAxis = Vector.sub (grid, x)
val data = Vector.sub (yAxis, y)
in
if data = ignoreData then
if shouldIgnoreData data then
EMPTY
else
let