[metapost] Drawing a urn
Troy Henderson
thenders at gmail.com
Thu Nov 29 19:34:37 CET 2007
I was posting my solution as Dan replied. Here's what I did.
Troy
u:=5mm;
s:=0.5*u;
N:=57; % Number of "light" balls out of 100
N:=max(min(N,100),0); % Make sure 0<=N<=100
boolean b,b[];
for n=1 upto N: b[n]:=true; endfor;
for n=N+1 upto 100: b[n]:=false; endfor;
path c;
for n=100 downto 1:
i:=floor((n-1)/10)+1;
j:=n-10*(i-1);
m:=floor(uniformdeviate (n-1))+1;
b:=b[m]; b[m]:=b[n]; b[n]:=b; % Interchange b[m] and b[n]
c:=fullcircle scaled u shifted (j*u-u/2+s,i*u-u/2+s);
fill c withcolor if b: 0.7*white else: 0.4*white fi;
endfor;
draw (0,10u+s)--(0,.5u)..(.15u,.15u)..(.5u,0)
--(9.5u+2s,0)..(9.85u+2s,.15u)..(10u+2s,.5u)--(10u+2s , 10u+s);
More information about the metapost
mailing list