2015-12-21 80 views
0

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

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

回答

2

因此,您已找到collage;在同一页的文档中,您应该能够找到creating a linetracing的功能...

+0

我对如何应用文档感到困惑 – Eliscpe

+0

也许您可以尝试编写一个更简单的独立榆树程序,一条线,然后一旦你明白了,再试一次树? [线演示](http://elm-lang.org/examples/lines)应该有所帮助。 – grumpyjames

+0

是的,我尝试过,但我不知道如何将它实现到我的代码,以便它显示。 – Eliscpe