[metapost] Drawing a urn

Martin Kaffanke technik at roomandspace.com
Thu Nov 29 13:09:53 CET 2007


Hi there!

I'd like to draw an urn where we have a probability of .57 to get a dark
ball when we choose a random ball.

I have the following:

 u := 5mm;
 s := .05u;
 
 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);

 path c;
 for i=1 upto 10:
   for j=1 upto 10:
     c := fullcircle scaled 1u shifted (j*u-u/2+s,i*u-u/2+s);
     if (i <= 5 ):
        fill c withcolor .7white;
     else:
        fill c withcolor .4white;
     fi;
   endfor;
 endfor;

This looks nice, but it shows a fifty-fifty chance.  How would you go
further to show a chance of .57 instead of .5?

Second: !important! I'd like to have the balls randomized.  In a java
application I do the same by creating 100 boolean values (true = dark,
false = white) something like 

for i=1 upto 100: 
  if i <= .57: 
    values.append(.4white);
  else:
    values.append(.7white);
  fi;
endfor;

mix(values);

How could that be done correctly with metapost?

Thanks,
Martin


-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Dies ist ein digital signierter Nachrichtenteil
Url : http://tug.org/pipermail/metapost/attachments/20071129/1b917411/attachment.bin 


More information about the metapost mailing list