add [r, g, b] field to triangle, so we can draw coloured objects (next: add ability to change current colour)

This commit is contained in:
2024-12-29 20:18:29 +00:00
parent cd1cef793e
commit 43eb5f4448
10 changed files with 197 additions and 65 deletions

View File

@@ -38,6 +38,9 @@ struct
, openFilePath = ""
, fileBrowser = Vector.fromList []
, fileBrowserIdx = 0
, r = 0.0
, g = 0.0
, b = 0.0
}
end

View File

@@ -17,6 +17,9 @@ sig
, y1: Real32.real
, y2: Real32.real
, y3: Real32.real
, r: Real32.real
, g: Real32.real
, b: Real32.real
}
type app_type =
@@ -38,6 +41,9 @@ sig
, openFilePath: string
, fileBrowser: file_browser_item vector
, fileBrowserIdx: int
, r: Real32.real
, g: Real32.real
, b: Real32.real
}
end
@@ -49,11 +55,14 @@ struct
type triangle =
{ x1: Real32.real
, y1: Real32.real
, x2: Real32.real
, y2: Real32.real
, x3: Real32.real
, y1: Real32.real
, y2: Real32.real
, y3: Real32.real
, r: Real32.real
, g: Real32.real
, b: Real32.real
}
datatype triangle_stage =
@@ -89,5 +98,8 @@ struct
, openFilePath: string
, fileBrowser: file_browser_item vector
, fileBrowserIdx: int
, r: Real32.real
, g: Real32.real
, b: Real32.real
}
end

View File

@@ -246,7 +246,7 @@ struct
end
| NO_TRIANGLE =>
(case #triangles model of
{x1, y1, x2, y2, x3, y3} :: trianglesTl =>
{x1, y1, x2, y2, x3, y3, r, g, b} :: trianglesTl =>
(* Have to slice off (x3, y3) from triangle head,
* turn (x1, y1, x2, y2) into a triangleStage,
* and redraw both triangle and triangleStage. *)
@@ -309,9 +309,19 @@ struct
| SECOND {x1, y1, x2, y2} =>
(* clear triangle stage, add to trinagle list and redraw triangles *)
let
val {r, g, b, ...} = model
val newTriangleStage = NO_TRIANGLE
val newTriangle =
{x1 = x1, y1 = y1, x2 = x2, y2 = y2, x3 = x, y3 = y}
{ x1 = x1
, y1 = y1
, x2 = x2
, y2 = y2
, x3 = x
, y3 = y
, r = r
, g = g
, b = b
}
val newTriangles = newTriangle :: (#triangles model)
val model =
AppWith.redo (model, newTriangleStage, newTriangles, redoHd)

View File

@@ -90,6 +90,9 @@ struct
, openFilePath
, fileBrowser
, fileBrowserIdx
, r
, g
, b
} = app
val newUndo = newUndoHd :: undo
@@ -112,6 +115,9 @@ struct
, openFilePath = openFilePath
, fileBrowser = fileBrowser
, fileBrowserIdx = fileBrowserIdx
, r = r
, g = g
, b = b
}
end
@@ -138,9 +144,22 @@ struct
, openFilePath
, fileBrowser
, fileBrowserIdx
, r
, g
, b
} = app
val newTriangle = {x1 = x1, y1 = y1, x2 = x2, y2 = y2, x3 = x3, y3 = y3}
val newTriangle =
{ x1 = x1
, y1 = y1
, x2 = x2
, y2 = y2
, x3 = x3
, y3 = y3
, r = r
, g = g
, b = b
}
val newTriangles = newTriangle :: triangles
val newUndo = newUndoHd :: undo
in
@@ -162,6 +181,9 @@ struct
, openFilePath = openFilePath
, fileBrowser = fileBrowser
, fileBrowserIdx = fileBrowserIdx
, r = r
, g = g
, b = b
}
end
@@ -186,6 +208,9 @@ struct
, openFilePath
, fileBrowser
, fileBrowserIdx
, r
, g
, b
} = app
in
{ mode = mode
@@ -206,6 +231,9 @@ struct
, openFilePath = openFilePath
, fileBrowser = fileBrowser
, fileBrowserIdx = fileBrowserIdx
, r = r
, g = g
, b = b
}
end
@@ -230,6 +258,9 @@ struct
, openFilePath
, fileBrowser
, fileBrowserIdx
, r
, g
, b
} = app
in
{ mode = mode
@@ -250,6 +281,9 @@ struct
, openFilePath = openFilePath
, fileBrowser = fileBrowser
, fileBrowserIdx = fileBrowserIdx
, r = r
, g = g
, b = b
}
end
@@ -276,6 +310,9 @@ struct
, openFilePath
, fileBrowser
, fileBrowserIdx
, r
, g
, b
} = app
val xClickPoints = ClickPoints.generate (wStart, wFinish, numClickPoints)
@@ -299,6 +336,9 @@ struct
, openFilePath = openFilePath
, fileBrowser = fileBrowser
, fileBrowserIdx = fileBrowserIdx
, r = r
, g = g
, b = b
}
end
@@ -346,6 +386,9 @@ struct
, openFilePath
, fileBrowser
, fileBrowserIdx
, r
, g
, b
} = app
in
{ mode = mode
@@ -366,6 +409,9 @@ struct
, openFilePath = openFilePath
, fileBrowser = fileBrowser
, fileBrowserIdx = fileBrowserIdx
, r = r
, g = g
, b = b
}
end
@@ -391,6 +437,9 @@ struct
, openFilePath
, fileBrowser
, fileBrowserIdx
, r
, g
, b
} = app
val newUndo =
@@ -418,6 +467,9 @@ struct
, openFilePath = openFilePath
, fileBrowser = fileBrowser
, fileBrowserIdx = fileBrowserIdx
, r = r
, g = g
, b = b
}
end
@@ -443,6 +495,9 @@ struct
, openFilePath
, fileBrowser
, fileBrowserIdx
, r
, g
, b
} = app
val newUndo = newUndoHd :: undo
@@ -469,6 +524,9 @@ struct
, openFilePath = openFilePath
, fileBrowser = fileBrowser
, fileBrowserIdx = fileBrowserIdx
, r = r
, g = g
, b = b
}
end
@@ -493,6 +551,9 @@ struct
, openFilePath
, fileBrowser
, fileBrowserIdx
, r
, g
, b
} = app
in
{ mode = mode
@@ -513,6 +574,9 @@ struct
, openFilePath = openFilePath
, fileBrowser = fileBrowser
, fileBrowserIdx = fileBrowserIdx
, r = r
, g = g
, b = b
}
end
@@ -537,6 +601,9 @@ struct
, openFilePath
, fileBrowser
, fileBrowserIdx
, r
, g
, b
} = app
in
{ mode = newMode
@@ -557,6 +624,9 @@ struct
, openFilePath = openFilePath
, fileBrowser = fileBrowser
, fileBrowserIdx = fileBrowserIdx
, r = r
, g = g
, b = b
}
end
@@ -581,6 +651,9 @@ struct
, openFilePath
, fileBrowser
, fileBrowserIdx
, r
, g
, b
} = app
val triangleStage = NO_TRIANGLE
@@ -603,6 +676,9 @@ struct
, openFilePath = openFilePath
, fileBrowser = fileBrowser
, fileBrowserIdx = fileBrowserIdx
, r = r
, g = g
, b = b
}
end
@@ -627,6 +703,9 @@ struct
, openFilePath = _
, fileBrowser = _
, fileBrowserIdx = _
, r
, g
, b
} = app
in
{ mode = mode
@@ -647,6 +726,9 @@ struct
, openFilePath = path
, fileBrowser = fileBrowser
, fileBrowserIdx = 0
, r = r
, g = g
, b = b
}
end
@@ -671,6 +753,9 @@ struct
, openFilePath = openFilePath
, fileBrowser = fileBrowser
, fileBrowserIdx = _
, r
, g
, b
} = app
in
{ mode = mode
@@ -691,6 +776,9 @@ struct
, openFilePath = openFilePath
, fileBrowser = fileBrowser
, fileBrowserIdx = newFileBrowserIdx
, r = r
, g = g
, b = b
}
end
end

View File

@@ -9,7 +9,7 @@ struct
fun helpToVector (lst, acc, windowWidth, windowHeight, halfWidth, halfHeight) =
case lst of
{x1, y1, x2, y2, x3, y3} :: tl =>
{x1, y1, x2, y2, x3, y3, r, g, b} :: tl =>
let
val x1 = Ndc.centreAlignX (x1, windowWidth, windowHeight, halfWidth)
val x2 = Ndc.centreAlignX (x2, windowWidth, windowHeight, halfWidth)
@@ -22,10 +22,19 @@ struct
val vec =
#[ x1 / halfWidth
, y1 / halfHeight
, r
, g
, b
, x2 / halfWidth
, y2 / halfHeight
, r
, g
, b
, x3 / halfWidth
, y3 / halfHeight
, r
, g
, b
]
val acc = vec :: acc
in