Browse Source

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.
master
Craig Oates 6 years ago
parent
commit
e1b10a320c
  1. BIN
      DeathSocket/1000x1000.png
  2. 2
      DeathSocket/DeathSocket.fsproj
  3. 2
      DeathSocket/GridPainter.fs
  4. 27
      DeathSocket/ImageServices.fs
  5. 23
      DeathSocket/ScratchPad.fsx

BIN
DeathSocket/1000x1000.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.0 KiB

2
DeathSocket/DeathSocket.fsproj

@ -5,10 +5,12 @@
</PropertyGroup>
<ItemGroup>
<Content Include="1000x1000.png" />
<Content Include="test-img.jpg" />
<Compile Include="Domain.fs" />
<Compile Include="IO.fs" />
<Compile Include="Validation.fs" />
<Compile Include="ImageServices.fs" />
<Compile Include="GridPainter.fs" />
<None Include="ScratchPad.fsx" />
</ItemGroup>

2
DeathSocket/GridPainter.fs

@ -3,7 +3,9 @@ namespace DeathSocket
module GridPainter =
open Validation
open ImageServices
let applyGridToImage spec =
validateFilePath |> ignore
drawGrid spec
0

27
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

23
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
let validationTest = validateFilePath savePath
let horizontalLines =
createHorizontalLines (testImg.Size.Width) (testImg.Size.Height) 10
let verticalLines =
createVerticalLines (testImg.Size.Width) (testImg.Size.Height) 10
Loading…
Cancel
Save