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

View File

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

View File

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

View File

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