Skip to content

Commit

Permalink
automatic connections between steps
Browse files Browse the repository at this point in the history
  • Loading branch information
PiotrJustyna committed Feb 27, 2024
1 parent 6886389 commit c12c5ff
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 31 deletions.
42 changes: 42 additions & 0 deletions HelloWorld.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{-# LANGUAGE NoMonomorphismRestriction #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE TypeFamilies #-}

import Diagrams.Prelude
import Diagrams.Backend.SVG.CmdLine

data Step = Step {
originCoordinates :: Point V2 Double,
name :: Double }

stepName :: Step -> Double
stepName Step { originCoordinates = x, name = y } = y

stepShape :: Double -> Diagram B
stepShape x = fromOffsets
[V2 0 0,
V2 0 0.5,
V2 0.75 0,
V2 0 (-0.5),
V2 (-0.75) 0]
# showOrigin
# named x

steps :: [Step]
steps = [
Step {
originCoordinates = p2 (x, y),
name = x * 10 + y }
| x <- [0 .. 1],
y <- [0 .. 2]]

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 [] = []

main = mainWith $
position [(x, (stepShape y)) | Step { originCoordinates = x, name = y } <- steps]
# applyAll (connections steps)
# lw veryThin
28 changes: 0 additions & 28 deletions HelloWorld.lhs

This file was deleted.

3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@
* `cabal install --lib diagrams-lib`
* `cabal install --lib diagrams-svg`
* `cabal install --lib base`
* `ghc HelloWorld.lhs`
* `ghc HelloWorld.hs`
* `./HelloWorld -o hello-world.svg -w 400`

![hello-world](./hello-world.svg)

## resources

* [literate programming](https://wiki.haskell.org/Literate_programming)
* [drakon](https://drakonhub.com/read/docs)
* [diagrams](https://archives.haskell.org/projects.haskell.org/diagrams/doc/quickstart.html#introduction)
Loading

0 comments on commit c12c5ff

Please sign in to comment.