Net6 and format (#8)

This commit is contained in:
Patrick Stevens
2022-12-31 15:46:24 +00:00
committed by GitHub
parent 1bd62ade9b
commit f0ee86819b
36 changed files with 1742 additions and 613 deletions

View File

@@ -22,36 +22,42 @@ module Colour =
Green = 0uy
Blue = 0uy
}
let White =
{
Red = 255uy
Green = 255uy
Blue = 255uy
}
let Red =
{
Red = 255uy
Green = 0uy
Blue = 0uy
}
let Green =
{
Red = 0uy
Green = 255uy
Blue = 0uy
}
let Blue =
{
Red = 0uy
Green = 0uy
Blue = 255uy
}
let Yellow =
{
Red = 255uy
Green = 255uy
Blue = 0uy
}
let HotPink =
{
Red = 205uy
@@ -62,6 +68,7 @@ module Colour =
let random (rand : Random) =
let buffer = Array.zeroCreate<byte> 3
rand.NextBytes buffer
{
Red = buffer.[0]
Green = buffer.[1]
@@ -79,7 +86,13 @@ type PixelStats =
[<RequireQualifiedAccess>]
module PixelStats =
let empty () = { Count = 0 ; SumRed = 0 ; SumGreen = 0 ; SumBlue = 0 }
let empty () =
{
Count = 0
SumRed = 0
SumGreen = 0
SumBlue = 0
}
let add (p : Pixel) (stats : PixelStats) : unit =
stats.Count <- stats.Count + 1
@@ -98,17 +111,22 @@ module PixelStats =
module Pixel =
let difference (p1 : Pixel) (p2 : Pixel) : int =
abs (int p1.Red - int p2.Red) + abs (int p1.Green - int p2.Green) + abs (int p1.Blue - int p2.Blue)
abs (int p1.Red - int p2.Red)
+ abs (int p1.Green - int p2.Green)
+ abs (int p1.Blue - int p2.Blue)
let average (s : Pixel []) : Pixel =
let average (s : Pixel[]) : Pixel =
let mutable r = s.[0].Red |> float
let mutable g = s.[0].Green |> float
let mutable b = s.[0].Blue |> float
for i in 1..s.Length - 1 do
for i in 1 .. s.Length - 1 do
r <- r + float s.[i].Red
g <- g + float s.[i].Green
b <- b + float s.[i].Blue
let count = s.Length |> float
{
Red = byte (Math.Round (r / count))
Green = byte (Math.Round (g / count))
@@ -125,8 +143,9 @@ module Pixel =
/// albedo should be between 0 and 1.
let darken (albedo : float<albedo>) (p : Pixel) : Pixel =
let albedo = albedo / 1.0<albedo>
{
Red = (float p.Red) * albedo |> Math.Round |> byte
Green = (float p.Green) * albedo |> Math.Round |> byte
Blue = (float p.Blue) * albedo |> Math.Round |> byte
}
}