Dev Blog: Galton Board 1

I’m working my way through Unity’s “Junior Programmer Pathway” lessons and have come upon a project that has enough interest for me that I might have something to say. I’ve also heard that writing a dev blog is useful in the future for job hunting in tech / game dev careers, or as portfolio pieces. So here we go.

The project is to take a pre-written counter script (tied to a box collider in a bin and a count display on a canvas), and a bunch of spheres (with rigidbodies so they obey physics), and use them to make something. The only rule: “your prototype must be counting something, and there must be a UI displaying that count.”

Having just taught a math class introducing students to the concepts of normal distribution and standard deviation, I immediately thought of making a Galton board as a demonstration. Since my lesson had included the ’empirical’ or ‘68-95-99.7‘ rule, I decided to use 8 bins, or 4 standard deviations on either side of the central chute. With 100 spheres spawned at the top, the count results for the 8 bins should roughly come out: 0, 2, 14, 34, 34, 14, 2, 0.

Design document for Galton Board

I started by duplicating the box with the counter and placing them in a row at the bottom, then constructed the physical structure of the board and chute. Statistically, the pegs only need to exist in a triangle, with the top row only having one central peg to shunt left or right, and the last row having 7 (one fewer than the number of bins at the bottom). However, I decided to make 7 rows of 7 just in case some of the spheres got extra bouncy and needed to run into more pegs for extra visual chaos prior to the order of the bell curve.

Roughed out Galton Board with spheres, chute, pegs, and bins

It has occurred to me by this point that I’m not sure what relationship the size of the pegs, or distance between them, has with the final distribution in the bins. To really use this as a classroom demonstration of statistical distribution, I’ll either have to do some research and testing to make sure that part’s right.

To tackle the 8 bin counters, the first thing that occurred to me was simplistically making 8 duplicates of the provided counter script, just adjusting the name and counter variable. But that didn’t seem like a particularly elegant way to approach it, and not the best way to show off what programming I’d learned so far. Instead, I created tags–from ‘A’ to ‘H’–and applied them to the bins in an attempt to be able to track and display the bin counts with a single script. I’m doing this with only a vague idea of how I’m going to associate the count with the bin tag. Maybe some kind of array? Or 8 separate variables that test for tag before incrementing? However, this seems like a good place for a longer break and letting my subconscious sit with the problem while I do other things.

Leave a Comment

Filed under Uncategorized

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.