From e1b10a320c31cfbcba5a04d344d65599b982e083 Mon Sep 17 00:00:00 2001 From: Craig Oates Date: Tue, 11 Sep 2018 00:59:35 +0100 Subject: [PATCH] add functions to create vertical and horizontal pen points. Include a 1000x1000 image (for testing) and cratch pad scripts for the horizontal and vertical points code, in library. --- DeathSocket/1000x1000.png | Bin 0 -> 6132 bytes DeathSocket/DeathSocket.fsproj | 2 ++ DeathSocket/GridPainter.fs | 2 ++ DeathSocket/ImageServices.fs | 27 +++++++++++++++++++++++++++ DeathSocket/ScratchPad.fsx | 23 +++++++++++++++++------ 5 files changed, 48 insertions(+), 6 deletions(-) create mode 100644 DeathSocket/1000x1000.png create mode 100644 DeathSocket/ImageServices.fs diff --git a/DeathSocket/1000x1000.png b/DeathSocket/1000x1000.png new file mode 100644 index 0000000000000000000000000000000000000000..8a6dd877b15d1a8aadfdbbf31f42b01976be81fc GIT binary patch literal 6132 zcmeAS@N?(olHy`uVBq!ia0y~yV15C@9Be=l-^Ev+04c`eAa^H*b?0PW0y!+{j=qiz z3>*8o|0J>k`J4qFk;M!Qe1}1p@p%4<6b1(IPEQxdkczms*9{pN3WB0J z)_kCb1D1~L3=9nnqvU7^jE2By2#kinXb6mkz-S1JhQMeDjE2By2#kinXb6mkz-S1J vhQMeDjE2By2#kinXb6mk09heWe49N$yWteiS<;GMzK)z4*}Q$iB}7I!mF literal 0 HcmV?d00001 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