如何在榆树中画线?

时间:2015-12-21 21:36:42

标签: tree draw diagram lines elm

此代码是没有行的树形图。如何在此代码中实现和绘制线条?

main = collage 700 700 ( drawTree exampleTree (0,0) 1)

drawNode name = group 
                  [filled red <| circle 50
                  , text <|fromString name]

type Tree = Node String Tree Tree | Nil

exampleTree = Node "Me" (Node "Mother" 
                             (Node "Grandmother" Nil Nil)
                             (Node "Grandfather" Nil Nil))
                       (Node "Father"
                             (Node "Grandfather" Nil Nil)
                             (Node "Grandmother" Nil Nil))

drawTree : Tree ->(Float, Float) -> Float -> List Form
drawTree tree (x,y) depth = case tree of
                        (Node ss t1 t2 )-> move (x,y) (drawNode ss) :: (List.append (drawTree t1 (x+100+depth,y+100) (depth+50)) (drawTree t2 (x-100-depth,y+100)(depth+50)))
                        Nil -> []

1 个答案:

答案 0 :(得分:2)

所以,你找到了collage;在同一页面的文档中,您应该能够找到creating a linetracing的函数...