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