Skip to content

Commit

Permalink
3 types of steps supported
Browse files Browse the repository at this point in the history
  • Loading branch information
PiotrJustyna committed Mar 5, 2024
1 parent f239385 commit 7147894
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
32 changes: 26 additions & 6 deletions HelloWorld.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion hello-world.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 7147894

Please sign in to comment.