当前位置: > 贝斯特国际娱乐城 >

MetaPost言语?宏练习(三)贝斯特老虎机

2017-09-07 18:00字体:
分享到:

%这是做象棋的图。先定义棋盘。

path mark, mark=(.1,.25)--(.1,.1)--(.25,.1);

boardUnit:=1cm;

def markAround(expr s, t) =

draw mark scaled s shifted t;

draw mark rotated 90 scaled s shifted t;

draw mark rotated (-90) scaled s shifted t;

draw mark rotated 180 scaled s shifted t;

enddef;

def markLeft (expr s, t) =

draw mark scaled s shifted t;

draw mark rotated (-90) scaled s shifted t;

enddef;

def markRight(expr s,t)=

draw mark rotated 90 scaled s shifted t;

draw mark rotated 180 scaled s shifted t;

enddef;

def cBoard(expr t)=

for i=1 upto 8:

draw ((0,0)--(0,4t)) shifted (i*t,0);

draw ((0,5t)--(0,9t)) shifted (i*t,0);

endfor

for i=1 upto 9:

draw ((0,0)--(8t,0)) shifted (0,t);

endfor

markAround(t, (t,2t));

markAround(t, (t,7t));

markAround(t, (7t,2t));

markAround(t, (7t,7t));

markAround(t, (2t,3t));

markAround(t, (4t,3t));

markAround(t, (6t,3t));

markAround(t, (2t,6t));

markAround(t, (4t,6t));

markAround(t, (6t,6t));

markLeft(t, (0,3t));

markLeft(t, (0,6t));

markRight(t, (8t,3t));

markRight(t, (8t,6t));

draw (3t,0)--(5t,2t);

draw (3t,2t)--(5t,0);

draw (3t,7t)--(5t,9t);

draw (3t,9t)--(5t,7t);

draw (0,0)--(0,9t)--(8t,9t)--(8t,0)--cycle;

draw (-.1t,-.1t)--(8.1t,-.1t)--(8.1t,9.1t)--(-.1t,9.1t)--cycle withpen pencircle scaled 1.2;

enddef;

def drawcBoard = cBoard(boardUnit) enddef;

%现在要考虑棋子要怎样处置了。棋子红、黑各有七种棋子,为了简化轮入棋子程式码,我界说黑棋是1到7号,红棋是11?17号。而轮入则用putChess1(x,y)的方法将棋子画在棋盘下面,所以要用到vardef来做这项任务。先搜寻一下,将(5c09)、士(58eb)、象(8c61)、车(8eca)、马(99ac)、包(5305)、卒(5352)、帅(5e25)、仕(4ed5)、相(76f8)、?(4fe5)、?(508c)、炮(70ae)、兵(5175)等字的unicode码,然后再开始处理棋子的成绩。既然要应用vardef来处理,所以棋子的局部必须要能处理@所代表的值跟传入的二个数值。

def getChar(expr $) =

begingroup

save p, q, pa, m, n; picture p, q; path pa[];

if $=1:

p:=glyph 7 of "asong5c";

m:=0;

n:=t/(ypart (urcorner p) - ypart (lrcorner p));

for i within p:

pa[m]=pathpart i shifted -(center p) scaled m;

m:=m+1;

endfor

%show m;%重要检查字有几多个path

q:=image(

fill fullcircle scaled .7t;

for i=0 utpo 3:

unfill pa[i] scaled .5;

endfor

undraw fullcircle scaled .6t;

);

elseif $=2:

p:=glyph 235 of "asong58";

m:=0;

n:=boardUnit/(ypart ulcorner p - ypart llcorner p);

for i within p:

pa[m]:=pathpart i shifted -(center p) scaled n;

m:=m+1;

endfor

%show m;

q:=image(

fill fullcircle scaled .7boardUnit;

unfill pa[0] scaled .45;

undraw fullcircle scaled .6boardUnit;

);

q

endgroup

enddef;

vardef putChess[](expr a,b)= draw getChar(@) shifted (boardUnit*(a, b)) enddef;

beginfig(1);

boardUnit:=1.5cm;

drawBoard;

putChess11(4,0);

putChess12(3,0);

putChess12(5,0);

putChess13(6,0);

putChess13(2,0);

putChess14(0,0);

putChess14(8,0);

putChess15(1,0);

putChess15(7,0);

putChess16(1,2);

putChess16(7,2);

putChess17(0,3);

putChess17(2,3);

putChess17(4,3);

putChess17(6,3);

putChess17(8,3);

putChess1(4,9);

putChess2(3,9);

putChess2(5,9);

putChess3(6,9);

putChess3(2,9);

putChess4(0,9);

putChess4(8,9);

putChess5(1,9);

putChess5(7,9);

putChess6(1,7);

putChess6(7,7);

putChess7(0,6);

putChess7(2,6);

putChess7(4,6);

putChess7(6,6);

putChess7(8,6);

endfig;

下一篇:没有了