From 7147894ec34fb3bf463a03f9f5f70d9314fe29bc Mon Sep 17 00:00:00 2001 From: Piotr Justyna Date: Tue, 5 Mar 2024 13:58:30 +0000 Subject: [PATCH] 3 types of steps supported --- HelloWorld.hs | 32 ++++++++++++++++++++++++++------ hello-world.svg | 2 +- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/HelloWorld.hs b/HelloWorld.hs index 00d210f..4d8d89f 100644 --- a/HelloWorld.hs +++ b/HelloWorld.hs @@ -5,28 +5,48 @@ import Diagrams.Prelude import Diagrams.Backend.SVG.CmdLine +data StepType + = StartType + | RegularStep + | EndType + data Step = Step { originCoordinates :: Point V2 Double, - name :: Double } + name :: Double, + stepType :: StepType } stepName :: Step -> Double -stepName Step { originCoordinates = x, name = y } = y +stepName Step { originCoordinates = x, name = y, stepType = z } = y stepShape :: Double -> Diagram B -stepShape x = rect 0.75 0.5 # showOrigin # named x +stepShape x = rect 0.95 0.4 # showOrigin # named x + +startShape :: Double -> Diagram B +startShape x = roundedRect 0.95 0.4 0.5 # showOrigin # named x + +endShape :: Double -> Diagram B +endShape = startShape uniqueName :: Double -> Double -> Double -uniqueName x y = x * 10 + y +uniqueName x y = x * 10 + (abs y) steps :: [Step] -steps = [ Step { originCoordinates = p2 (x, y), name = uniqueName x y } | x <- [0], y <- [0, -1, -2, -3]] +steps = + Step { originCoordinates = p2 (0, 0), name = uniqueName 0 0, stepType = StartType } + : [Step { originCoordinates = p2 (x, y), name = uniqueName x y, stepType = RegularStep } | x <- [0], y <- [-1, -2, -3]] + ++ [Step { originCoordinates = p2 (0, -4), name = uniqueName 0 4, stepType = EndType }] connections :: [Step] -> [QDiagram B V2 Double Any -> QDiagram B V2 Double Any] connections (x1: x2: xn) = connectOutside (stepName x1) (stepName x2): connections (x2: xn) connections (x1: []) = [] connections [] = [] +correctShape :: StepType -> Double -> Diagram B +correctShape StartType = startShape +correctShape EndType = endShape +correctShape _ = stepShape + main = mainWith $ - position [(x, (stepShape y)) | Step { originCoordinates = x, name = y } <- steps] + position [(x, correctShape z y) | Step { originCoordinates = x, name = y, stepType = z } <- steps] # applyAll (connections steps) # lw veryThin diff --git a/hello-world.svg b/hello-world.svg index df10cb0..e358736 100644 --- a/hello-world.svg +++ b/hello-world.svg @@ -1,3 +1,3 @@ \ No newline at end of file + "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> \ No newline at end of file