diff --git a/DeathSocket/1000x1000.png b/DeathSocket/1000x1000.png new file mode 100644 index 0000000..8a6dd87 Binary files /dev/null and b/DeathSocket/1000x1000.png differ diff --git a/DeathSocket/DeathSocket.fsproj b/DeathSocket/DeathSocket.fsproj index 57a8936..4f6c15d 100644 --- a/DeathSocket/DeathSocket.fsproj +++ b/DeathSocket/DeathSocket.fsproj @@ -5,10 +5,12 @@ + + diff --git a/DeathSocket/GridPainter.fs b/DeathSocket/GridPainter.fs index 6cb95ae..e1c2b8d 100644 --- a/DeathSocket/GridPainter.fs +++ b/DeathSocket/GridPainter.fs @@ -3,7 +3,9 @@ namespace DeathSocket module GridPainter = open Validation + open ImageServices let applyGridToImage spec = validateFilePath |> ignore + drawGrid spec 0 \ No newline at end of file diff --git a/DeathSocket/ImageServices.fs b/DeathSocket/ImageServices.fs new file mode 100644 index 0000000..bfb6cfd --- /dev/null +++ b/DeathSocket/ImageServices.fs @@ -0,0 +1,27 @@ +module internal ImageServices + +open System.Drawing +open DeathSocket.Domain + + let createHorizontalLines width height columns = + let interval = width / columns + [| for point in 1 .. columns -> + [|Point (0, (interval * point)) + Point (height, (interval * point) )|]|] + + let createVerticalLines width height columns = + let interval = height / columns + [| for point in 1 .. columns -> + [| Point ((interval * point), 0) + Point ((interval * point), height)|]|] + + let drawGrid spec = + let img = Bitmap.FromFile spec.filePath + let graphics = Graphics.FromImage img + let pen = new Pen (spec.colour, width = spec.penWidth) + let horizontalLines = + createHorizontalLines (img.Size.Width) (img.Size.Height) (spec.columns) + let verticalLines = + createVerticalLines (img.Size.Width) (img.Size.Height) (spec.columns) + 0 + diff --git a/DeathSocket/ScratchPad.fsx b/DeathSocket/ScratchPad.fsx index 619843b..9476d89 100644 --- a/DeathSocket/ScratchPad.fsx +++ b/DeathSocket/ScratchPad.fsx @@ -1,11 +1,16 @@ -#load "Validation.fs" +#load "Domain.fs" +#load "Validation.fs" +#load "ImageServices.fs" #load "GridPainter.fs" open System.Drawing open System open System.Drawing.Imaging -open Validation open DeathSocket +open Domain +open Validation +open ImageServices + // INITIAL IDEA =============================================================== @@ -16,11 +21,11 @@ let imgWidth = img.Size.Width let imgHeight = img.Size.Height (* Keeping it simple here. Going to just create a 2x2 grid. In other words, I'm just halving the width and the height. *) -let verticalLine = +let horizontalLine = let midpoint = imgHeight / 2 [|Point (0, midpoint); Point (imgWidth, midpoint)|] -let horizontalLine = +let verticalLine = let midpoint = imgWidth / 2 [| Point (midpoint, 0); Point (midpoint, imgWidth)|] @@ -38,7 +43,13 @@ pen.Dispose // DEATH SOCKET TESTING ======================================================= let desktop = Environment.GetFolderPath (Environment.SpecialFolder.Desktop) -let savePath = desktop + "/test-grid.png" // Change this to suit you. +let savePath = desktop + "/1000x1000.png" // Change this to suit you. + +let testImg = Bitmap.FromFile (__SOURCE_DIRECTORY__ + "/1000x1000.png") // Throws an exception if no file is found. -let validationTest = validateFilePath savePath \ No newline at end of file +let validationTest = validateFilePath savePath +let horizontalLines = + createHorizontalLines (testImg.Size.Width) (testImg.Size.Height) 10 +let verticalLines = + createVerticalLines (testImg.Size.Width) (testImg.Size.Height) 10 \ No newline at end of file