| Register | FAQ | Calendar | Search | Today's Posts | Mark Forums Read |
|
#1
| |||
| |||
| The message below is being cross-posted from the LogoForum. Please reply here at comp.lang.logo and it will be crossposted back to the LogoForum. The original author of this message is "Dale Reed" <dale-reed@worldnet.nospam.att.net>. to aaa :totdots ; LogoForum, Tue Nov 2, 2004 3:52 pm ; Message 10143 ; For just one run try: erns aaa 10000 ; For many runs try: main 1000 10 cs ht pu setlabelfont[ [Courier New] -24 0 0 800 0 0 0 177 3 2 1 57] rt 90 setxy -120 300 setpc [0 0 0] label [Monte Carlo Method to approximate PI] setpensize [3 3] repeat 300[setxy -300+repcount -450+3.14159*100 setpc [0 0 0] pd fd 400 pu] setxy -430 -120 label "3.14159 make "radius 250 make "M 0 make "pie 0 make "N 0 make "runtime 0 make "start timemilli dotting timer (print "PI "= ie " " "time "= :runtime)setxy -170 -40 label "PI= setxy 0 -40 label "counts= setxy 310 -40 label "seconds setactivearea [-250 -100 450 300] ;gifsave "MonteCarlo.gif end to counter localmake "display.step modulo :N 50 timer if :display.step = 0 [ ;Count the calculated PI setxy -120 -40 rubout setpc [0 0 0] label ie; Count the Total Runtime setxy 105 -40 rubout setpc [0 0 0] label :N setxy 210 -40 label :runtime ] end to dot ifelse (distance [0 0]) > :radius [ setpixel [0 0 255]] [setpixel [255 0 0] make "M :M+1] make "pie 4 * :M / :N end to dotting repeat :totdots[setxy random :radius+1 random :radius+1 make "N repcount dot counter plot ] end to main :totdots :number.of.runs repeat :number.of.runs[aaa :totdots wait 100] end to plot setpc [0 155 0] setpensize [2 2] setxy -300+:N/10 -450+100*( ie)pd fd 1 pu end to rubout pd setpc [25 255 255] setpensize [40 40] bk 80 fd 400 bk 320 pu end to timer make "runtime (timemilli - :start)/1000 end --- $ dale-reed@worldnet.att.net Seattle, Washington $ |
![]() |
| Thread Tools | |
| Display Modes | |
In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.