Galton box animation: Difference between revisions

Updated D entry
(Updated D entry)
Line 467:
void initializeBox() {
// Set ceiling and floor:
box[0][] = (Cell.corner ~ [Cell.floor].replicate(boxW - 2)
~ Cell.corner)[];
box[$ - 1][] = box[0][];
 
// Set walls:
Line 476:
 
// Set pins:
foreach (immutable nPins; 1 .. pinsBaseW + 1)
foreach (pin; 0 .. nPins)
box[boxH - 2 - nPins][centerH + 1 - nPins + pin * 2]
Line 488:
 
void main() {
initializeBox();
Ball[] balls;
 
Line 500:
// Frozen balls are kept in balls array for simplicity.
foreach (ref b; balls)
b.doStep();
}
}</lang>