Removing broken demo
svn: r403
This commit is contained in:
parent
035a2a9448
commit
e6d8266b44
|
@ -1,71 +0,0 @@
|
||||||
#| The program being debugged (a module in the file "montecarlo.ss") runs
|
|
||||||
an infinite loop, binding "x" and "y" to a random number between
|
|
||||||
[-199,199], each iteration.
|
|
||||||
|
|
||||||
This is supposed to represent throwing darts at a circular dartboard.
|
|
||||||
You keep a count of how many darts you have thrown, and a side count
|
|
||||||
for each time the dart is thrown within the circle. The ratio of
|
|
||||||
hits to total tries, multiplied by 4, approaches "pi" with some error,
|
|
||||||
usually closing in around 3.13. The target program does this computation
|
|
||||||
and binds it to the variable "pi".
|
|
||||||
|
|
||||||
This MzTake script visualizes the process, drawing points (darts)
|
|
||||||
that "hit" the circle, a radius of 200 pixels from the center of
|
|
||||||
the window. |#
|
|
||||||
|
|
||||||
|
|
||||||
(require (lib "graphics.ss" "graphics"))
|
|
||||||
#| Needed for open-graphics, open-viewport, and draw-solid-ellipse |#
|
|
||||||
|
|
||||||
|
|
||||||
(open-graphics)
|
|
||||||
(define window (open-viewport "Debugger" 400 400))
|
|
||||||
#| This file doesn't animate a list of objects since the number of
|
|
||||||
objects quickly reaches the thousands (slowing drawing time severly),
|
|
||||||
and the dots are stationary -- so we just keep drawing the circles at
|
|
||||||
the random coordinates that we get from the target program.
|
|
||||||
|
|
||||||
See the doc for more information on this kind of drawing. |#
|
|
||||||
|
|
||||||
|
|
||||||
(define-mztake-process p ("montecarlo.ss" [x/y/pi-trace 13 13 bind '(x y pi)]))
|
|
||||||
#| * Create a process to debug montecarlo.ss
|
|
||||||
|
|
||||||
* Add a tracepoint at line 13, column 13; in the program,
|
|
||||||
this is right after the cond determined that the point *is* within
|
|
||||||
the radius of the circle, before starting the next iteration of the loop.
|
|
||||||
|
|
||||||
* At this tracepoint, define "x/y/pi-trace" to a FrTime eventstream that
|
|
||||||
recieves events containing a list of the latest values of "x" "y" and "pi"
|
|
||||||
in a list, every time the code at line 13, column 18, is reached. |#
|
|
||||||
|
|
||||||
|
|
||||||
(define x/y/pi (hold x/y/pi-trace))
|
|
||||||
#| The local, time-varying variable "x/y/pi" is now is a FrTime behavior that always
|
|
||||||
holds the current (latest) list of values from x/y/pi-trace. |#
|
|
||||||
|
|
||||||
|
|
||||||
(define x (+ 200 (first x/y/pi)))
|
|
||||||
(define y (+ 200 (second x/y/pi)))
|
|
||||||
(define current-pi (third x/y/pi))
|
|
||||||
#| The local, time-varying variables "x" "y" and "current-pi" are bound to
|
|
||||||
their respective values in the list from x/y/pi. |#
|
|
||||||
|
|
||||||
|
|
||||||
(printf-b "total points chosen: ~a" (count-b (changes x)))
|
|
||||||
(printf-b "current computed value of pi: ~a" current-pi)
|
|
||||||
(printf-b "log error: ~a" (log (abs (- current-pi 3.141592653)))) ;; the more negative, the better...
|
|
||||||
|
|
||||||
((draw-viewport window) "wheat")
|
|
||||||
((draw-solid-ellipse window) (make-posn -4 -4) 408 408 "black")
|
|
||||||
((draw-solid-ellipse window) (make-posn 0 0) 400 400 "sienna")
|
|
||||||
#| Draw the dartboard |#
|
|
||||||
|
|
||||||
(map-e (lambda (x/y) ((draw-solid-ellipse window) (make-posn (first x/y) (second x/y))
|
|
||||||
3 3 "black"))
|
|
||||||
(changes (list x y)))
|
|
||||||
#| Every time the list (x y) changes (x and y get a new value), take this latest list value ("==>")
|
|
||||||
and pass it to a function which draws a circle at the x,y coordinates in the list. |#
|
|
||||||
|
|
||||||
|
|
||||||
(start/resume p) #| Start the process for montecarlo.ss |#
|
|
Loading…
Reference in New Issue
Block a user