mirror of
https://github.com/Smaug123/ray-tracing-fsharp
synced 2025-10-17 01:28:39 +00:00
Net6 and format (#8)
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user