⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 squareanddiamonds.pl

📁 PRl教学程序 PRl教学程序 PRl教学程序
💻 PL
字号:
/********************************************************************
    Constraint-based Graphical Programming in B-Prolog
    %
    draw nested squares and diamonds
*********************************************************************/
go:-
    cgSquare(S), S^fill #= 0,
    cgPolygon(P), P^fill #= 0, P^n #= 4,
    squareToPolygon(S,P),
    diamondsAndSquares(P,10,Ps),
    cgPack([S,P|Ps]),
    cgJava(squareAndDiamonds,[P|Ps]).

squareToPolygon(S,P):-
    P^point(0) #= S^leftTopPoint,
    P^point(1) #= S^leftBottomPoint,
    P^point(2) #= S^rightBottomPoint,
    P^point(3) #= S^rightTopPoint.

diamondsAndSquares(S,N,Ps):-N=:=0,!,Ps=[].
diamondsAndSquares(S,N,[P|Ps]):-
    cgPolygon(P), P^n #= 4, P^fill #= 0,
    (N mod 2=:=0 -> P^color #= red; true),
    center(P^point(0),S^point(0),S^point(1)),
    center(P^point(1),S^point(1),S^point(2)),
    center(P^point(2),S^point(2),S^point(3)),
    center(P^point(3),S^point(3),S^point(0)),
    N1 is N-1,
    diamondsAndSquares(P,N1,Ps).

center(CP,P1,P2):-
    CP^x #= (P1^x+P2^x)//2,
    CP^y #= (P1^y+P2^y)//2.

    


    

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -