mirror of
https://github.com/Smaug123/ray-tracing-fsharp
synced 2025-10-08 21:38:42 +00:00
45 lines
1.2 KiB
Forth
45 lines
1.2 KiB
Forth
namespace RayTracing
|
|
|
|
open RayTracing
|
|
|
|
[<Measure>]
|
|
type progress
|
|
|
|
type Image =
|
|
private
|
|
{
|
|
Rows : Pixel Async [] seq
|
|
RowCount : int
|
|
ColCount : int
|
|
}
|
|
|
|
[<RequireQualifiedAccess>]
|
|
module Image =
|
|
let rowCount i : int = i.RowCount
|
|
|
|
let colCount i = i.ColCount
|
|
|
|
let render (i : Image) : (Pixel * Async<unit>) [] seq =
|
|
i.Rows
|
|
|> Seq.map (fun imageRow ->
|
|
if imageRow.Length <> i.ColCount then
|
|
failwithf "Thought the image had %i columns, got a pixel array with %i columns" i.ColCount imageRow.Length
|
|
let outputRow = Array.zeroCreate<Pixel * Async<unit>> i.ColCount
|
|
let doIt =
|
|
imageRow
|
|
|> Array.mapi (fun i p -> async {
|
|
let! pixel = p
|
|
let _, a = outputRow.[i]
|
|
outputRow.[i] <- pixel, a
|
|
})
|
|
for k in 0..i.ColCount - 1 do
|
|
outputRow.[k] <- Unchecked.defaultof<_>, doIt.[k]
|
|
outputRow
|
|
)
|
|
|
|
let make (rowCount : int) (colCount : int) (pixels : Async<Pixel>[] seq) : Image =
|
|
{
|
|
RowCount = rowCount
|
|
ColCount = colCount
|
|
Rows = pixels
|
|
} |