29.11.2012 Views

MetaFun - Pragma ADE

MetaFun - Pragma ADE

MetaFun - Pragma ADE

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

A different approach is to use a two dimensional array. In doing so, we can access the variables<br />

more easily using loops. If we omit the labels, and angle macro, the previously defined macro can<br />

be reduced considerably.<br />

def draw_problem (expr n, p, q, r, s) = % number and 4 positions<br />

begingroup ; save x, y ;<br />

z[1][1] = p ; z[2][1] = q ; z[3][1] = r ; z[4][1] = s ;<br />

for i=1 upto 4 :<br />

z[i][1] = (x[i][1],y[i][1]) = z[if i=1: 4 else: i-1 fi][2] ;<br />

z[i][2] = (x[i][2],y[i][2]) ;<br />

z[i][3] = (x[i][2]-y[i][2]+y[i][1], y[i][2]+x[i][2]-x[i][1]) ;<br />

z[i][4] = (x[i][1]-y[i][2]+y[i][1], y[i][1]+x[i][2]-x[i][1]) ;<br />

z[i] = 0.5[z[i][1],z[i][3]] ;<br />

endfor ;<br />

z[0] = whatever[z[1],z[3]] = whatever[z[2],z[4]] ;<br />

pickup pencircle scaled .5pt ;<br />

for i=1 upto 4 :<br />

draw z[i][1]--z[i][2]--z[i][3]--z[i][4]--cycle ;<br />

draw z[i][1]--z[i][3] ; draw z[i][2]--z[i][4] ;<br />

if i

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!