📄 binarytree.pl
字号:
/********************************************************************
Constraint-based Graphical Programming in B-Prolog
%
draw a binary tree
*********************************************************************/
go:-
binaryTree(Os),
cgJava(binaryTree,Os).
binaryTree([Root|Os]):-
createNode(Root),
binaryTree(4,Root,Os).
createNode(Root):-
cgCircle(Root),
Root^width #= 20,
Root^color #= red.
binaryTree(N,Root,Os):-N=:=0,!,Os=[].
binaryTree(N,Root,Os):-
Os=[C1,C2,L1,L2|Os12],
createNode(C1),
createNode(C2),
cgLine(L1),
cgLine(L2),
connect(Root,C1,C2,L1,L2),
N1 is N-1,
binaryTree(N1,C1,Os1),
binaryTree(N1,C2,Os2),
cgLeft(Os1,Os2),
append(Os1,Os2,Os12).
connect(Root,C1,C2,L1,L2):-
Root^centerX #= (C1^centerX+C2^centerX)//2,
cgLeft(C1,C2),
Root^centerY #= C1^centerY-50,
C1^centerY #= C2^centerY,
connect(L1,Root,C1),
connect(L2,Root,C2).
connect(L,N1,N2):-
L^point1 #= N1^centerPoint,
L^point2 #= N2^centerPoint.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -