Add port bottom of guard. Improve guard icon.

This commit is contained in:
Robbie Gleichman 2016-01-20 22:39:51 -08:00
parent 3fb6890d68
commit 225c8179b1
3 changed files with 23 additions and 32 deletions

View File

@ -136,7 +136,8 @@ branchIcon = circle 0.3 # fc white # lc white
-- GUARD ICON --
guardSize = 0.7
guardTriangle :: Int -> Diagram B
guardTriangle x = ((triangleAndPort ||| (hrule (guardSize * 0.8) # lc white # lwG defaultLineWidth)) # alignR) <> (makePort x) # alignL
guardTriangle x =
((triangleAndPort ||| (hrule (guardSize * 0.8) # lc white # lwG defaultLineWidth)) # alignR) <> makePort x # alignL
where
triangleAndPort = polygon (with & polyType .~ PolySides [90 @@ deg, 45 @@ deg] [guardSize, guardSize])
# rotateBy (1/8)# lc white # lwG defaultLineWidth # alignT # alignR
@ -144,21 +145,22 @@ guardTriangle x = ((triangleAndPort ||| (hrule (guardSize * 0.8) # lc white # lw
guardLBracket :: Int -> Diagram B
guardLBracket x = ell # alignT # alignL <> makePort x
where
-- todo: use a path or trail here so that the corner is rounded correctly
ell = (hrule guardSize # lc orange # lwG defaultLineWidth # alignR) <> (vrule guardSize # lc orange # lwG defaultLineWidth # alignT)
ellShape = fromOffsets $ map r2 [(0, guardSize), (-guardSize,0)]
ell = ellShape # strokeLine # lc orange # lwG defaultLineWidth # lineJoin LineJoinRound
-- | The ports of the guard icon are as follows:
-- Port 0: The top port for the result
-- Ports 1,3,5...: The left ports for the booleans
-- Port 1: Bottom result port
-- Ports 3,5...: The left ports for the booleans
-- Ports 2,4...: The right ports for the values
guardIcon :: Int -> Diagram B
guardIcon n = centerXY $ vcat (take n trianglesAndBrackets # alignT) <> makePort 0
guardIcon n = centerXY $ makePort 1 <> alignB (vcat (take n trianglesAndBrackets # alignT) <> makePort 0)
where
--guardTriangles = vsep 0.4 (take n (map guardTriangle [0,1..]))
trianglesWithPorts = map guardTriangle [2,4..]
lBrackets = map guardLBracket [1,3..]
lBrackets = map guardLBracket [3, 5..]
trianglesAndBrackets =
zipWith zipper trianglesWithPorts lBrackets
zipper tri lBrack = verticalLine === ((lBrack ||| strut (guardSize * 0.4)) # alignR <> (tri # alignL))
zipper tri lBrack = verticalLine === ((lBrack # extrudeRight guardSize) # alignR <> (tri # alignL))
where
verticalLine = vrule 0.4 # lc white # lwG defaultLineWidth

View File

@ -14,16 +14,13 @@ import Data.Maybe (fromMaybe)
import Data.Typeable(Typeable)
import Lib
import Icons(apply0Dia, apply0NDia)
import Icons(apply0Dia, apply0NDia, guardIcon)
import Rendering(toNames, portToPort, iconToPort, iconToIcon,
iconToIconEnds, iconHeadToPort, iconTailToPort, renderDrawing)
import Types(Icon(..), Drawing(..), EdgeEnd(..))
-- TODO Now --
-- todo: add example goal and status drawings for factorial to readme.
-- todo: replace hrule and vrule with strutX and strutY
-- todo: consolidate colors to one place
-- todo: add port to bottom of guard.
-- todo: use constants for icon name strings in Main
-- todo: figure out how to deal with the difference between arrow heads and arrow tails
-- todo: consider moving portToPort etc. to a new file
@ -150,7 +147,7 @@ fact0Icons = toNames
fact0Edges = [
iconToPort "eq0" "eq0Ap" 0,
portToPort "eq0Ap" 2 "g0" 1,
portToPort "eq0Ap" 2 "g0" 3,
iconToPort "-1" "-1Ap" 0,
iconToPort "*" "*Ap" 0,
iconToPort "one" "g0" 2,
@ -193,24 +190,16 @@ fact1Icons = toNames
]
fact1Edges = [
--iconToPort "eq0" "eq0Ap" 0,
--portToPort "eq0Ap" 2 "g0" 1,
--iconToPort "-1" "-1Ap" 0,
iconToIconEnds "arg" EndNone "eq0" EndAp1Arg,
iconTailToPort "eq0" EndAp1Result "g0" 1,
iconToIconEnds "arg" EndNone "-1" EndAp1Arg,
iconTailToPort "-1" EndAp1Result "recurAp" 1,
--iconHeadTo
iconToPort "*" "*Ap" 0,
iconToPort "one" "g0" 2,
portToPort "*Ap" 1 "g0" 4,
portToPort "recurAp" 2 "*Ap" 3,
--iconToPort "arg" "eq0Ap" 1,
--iconToPort "arg" "-1Ap" 1,
iconToPort "arg" "*Ap" 2,
--portToPort "-1Ap" 2 "recurAp" 1,
iconToPort "res" "g0" 0
--iconToIconEnds "-1" Ap1Result "eq0" Ap1Arg
iconToIconEnds "arg" EndNone "eq0" EndAp1Arg,
iconTailToPort "eq0" EndAp1Result "g0" 3,
iconToIconEnds "arg" EndNone "-1" EndAp1Arg,
iconTailToPort "-1" EndAp1Result "recurAp" 1,
iconToPort "*" "*Ap" 0,
iconToPort "one" "g0" 2,
portToPort "*Ap" 1 "g0" 4,
portToPort "recurAp" 2 "*Ap" 3,
iconToPort "arg" "*Ap" 2,
iconToPort "res" "g0" 0
]
fact1Drawing = Drawing fact1Icons fact1Edges []
@ -230,7 +219,7 @@ main1 = do
placedNodes <- renderDrawing factLam1Drawing
mainWith (placedNodes # bgFrame 1 black)
main2 = mainWith (apply0NDia 3 # bgFrame 0.1 black)
main2 = mainWith (guardIcon 3 # bgFrame 0.1 black)
main :: IO ()
main = main1

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 24 KiB

After

Width:  |  Height:  |  Size: 24 KiB