Anonymous user
Galton box animation: Difference between revisions
→{{header|Racket}}
Line 1,351:
=={{header|Racket}}==
This does not use the default #lang racket. Required is advanced student with teachpacks universe and image.
Multiple balls are added each step, but they do not collide.
<lang Racket>
Line 1,455 ⟶ 1,456:
(+ -1 (* 2 (random 2)) (pos-col p))))
;each step, every ball goes to the next row and
;balls that fall off go into bins
(define (tock height s)
Line 1,465 ⟶ 1,466:
;map col to bin index
[bin-indices (map (λ (p) (quotient (+ (pos-col p) height) 2)) dead)])
;add
(make-st (
;sum dead ball positions into bins
(vector-inc-indices! bin-indices (st-bins s)))))
Line 1,476 ⟶ 1,477:
(to-draw (λ (ps) (draw height ps)))))
</lang>
=={{header|Ruby}}==
|