Galton box animation: Difference between revisions

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 a new ballballs isare added at the top center
;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 a new ballballs to the live balls
(make-st (consappend (make-list (random 4) (make-pos 0 0)) live)
;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}}==
Anonymous user