a11 wrote:
> I am looking for explanations on how to draw a flowchart of tree with
> side say 40 and angle 40 and level 2
>
> I would like to understand how to draw the tree in terms of a
> flowchart
Oh, that's a bigger problem, depending on how complex your tree is.
You might try this in aUCBLogo as a first guess:
to testflowchart
draw_proc "testProcedure
end
to testProcedure x
print 5
if lessP x 1 [stop]
ifelse greaterP x 10
[ print "x>10
][ print "x<=10
]
testProcedure x-1
end
to testProcedure2 x
print 5
if x < 1 [stop]
ifelse x > 10
[ ifelse x > 10
[ print "x>10
][ print "x<=10
]
][ print "x<=10
]
testProcedure2 x-1
end
to draw_proc procname
local [tree startPos s]
; tree=butFirst makeTreeFromBody Text procname
tree=
[ [print 5]
[if [:x < 1][stop]]
[ifelse [:x > 10][print "x>10][print "x<=10]]
[testProcedure [- :x 1]]
]
clearText
show :tree
clearScreen
WindowMode
hideTurtle
enableTextureFont
PenUp
setXY 0 300
s=draw_start
startPos=Pos-(list s.1/2 -s.2/2)
draw_arrowxy Pos (list xCor yCor-30)
draw_flowChart :tree
; draw_end
end
to draw_flowChart x
local [s]
foreach x
[ case ?.1
[ [[if] [draw_if ?]]
[[ifelse] [draw_ifelse ?]]
[procname [ draw_arrowxy Pos (list xCor-300 yCor+20)
draw_arrowyx Pos startPos stop]]
[[stop output] [s=draw_text ? setY yCor-20 stop]]
[else [s=draw_text ?]]
]
draw_arrowxy Pos (list xCor yCor-20)
]
end
to draw_start
output draw_text "Start
end
to draw_end
output draw_text "End
end
to draw_if x
local [s p1 p2]
s=draw_diamond_text first butFirst x
p1=Pos
p1.1=p1.1+s.1/2
p1.2=p1.2+s.2/2
draw_yes
draw_flowChart butFirst butFirst x
p2=Pos
PenUp
setPos p1
draw_no
draw_arrowyx Pos p2
end
to draw_ifelse x
local [s p1 p2]
s=draw_diamond_text first butFirst x
p1=Pos
p1.1=p1.1+s.1/2
p1.2=p1.2+s.2/2
draw_yes
draw_flowChart butLast butFirst butFirst x
p2=Pos
PenUp
setPos p1
draw_no
draw_flowChart butFirst butFirst butFirst x
draw_arrowyx Pos p2
end
to draw_yes
local [p s]
s=(LabelSize "Yes)/4
p=Pos
relXY s.1 -s.2/2
Label "Yes
setPos p
draw_arrowxy Pos (List xCor yCor-20)
end
to draw_no
local [p s]
s=(LabelSize "No)/4
p=Pos
relXY s.1/3 s.2/2
Label "No
setPos p
draw_arrowxy Pos (List xCor+150 yCor-20)
end
to draw_text txt
local [s w h]
s=(LabelSize txt)/3
w=s.1
h=s.2
setY yCor-h/2-5
draw_rect w h
setHeading 90
Label txt
setY yCor-h/2
output s
end
to draw_diamond_text txt
local [s w h]
s=(LabelSize txt)/2
w=s.1
h=s.2
setY yCor-h/2-5
draw_diamond w h
setHeading 90
Label txt
setY yCor-h/2
output s
end
to draw_rect width height
PenUp
setXY xCor-width/2 yCor-height/2
PenDown
setX xCor+width
setY yCor+height
setX xCor-width
setY yCor-height
PenUp
setXY xCor+width/2 yCor+height/2
end
to draw_diamond width height
PenUp
setY yCor+height/2
PenDown
setXY xCor-width/2 yCor-height/2
setXY xCor+width/2 yCor-height/2
setXY xCor+width/2 yCor+height/2
setXY xCor-width/2 yCor+height/2
PenUp
setY yCor-height/2
end
to draw_arrowxy s d
local [x y]
y=(signum d.2-s.2)*10
x=5
PenUp
setPos s
PenDown
setX d.1
setY d.2
relXY -x -y
relXY x y
relXY x -y
relXY -x y
PenUp
end
to draw_arrowyx s d
local [x y]
x=(signum d.2-s.2)*10
y=5
PenUp
setPos s
PenDown
setY d.2
setX d.1
relXY -x y
relXY x -y
relXY -x -y
relXY x y
PenUp
end
to relXY x y
setXY xCor+x yCor+y
end
For other procedures, just uncomment the line:
; tree=butFirst makeTreeFromBody Text procname
and delete the other definiton of tree.
(I only wrote the second definition,
because it looks nicer on graphics screen without the tabs.
You could also improve it
using "replace" with the tab character on the tree.)
If you need to draw loops,
you can implement them similar as draw_if.
Or ask again in the group.
Cheers,
Andreas


|