Monthly Archives: December 2021

Dev Blog: Galton Board 2

The more I thought about this project, the more I realized the need to adjust my plan to fit the requirements of the assignment. Yes, I could add buttons for different peg configurations. Yes, I could pick just the right textures for the spheres so they’re gorgeous chrome. Yes, I could make the bins narrower so they show height accumulations relative to a normal distribution curve superimposed on the front. Yes, I want it to spawn exactly 100 spheres at random locations across the top rather than dump the original sphere-swarm in the center. Yes, I could tweak the pins so I get something closer to a normal distribution (a necessity if I want to use this for a stats demo in one of my classes).

But the assignment was to make a prototype of something that counted something and displayed the count; what I could do was racing far ahead of what I needed to do.

So, since it’s a prototype, the roughed out physical board is sufficient as-is. I just need to get it to count. There’s already a counter, but my concept was that each bin would count separately. Again, for a prototype, I’ll just make the counting script have a separate counter for each with a test for the bin tag before incrementing. I’m absolutely certain there’s a better solution, but this will meet the requirements.

Made a counter for each bin, an if/else if test for the bin tags to add to the count. But going to update the display, I notice that the provided script doesn’t display things the way the Unity Learn lesson taught. The lesson implemented TextMeshPro, while the default script in the project used the old UnityEngine.UI Text. Updated to TMPro after some searching online and seeing basically all the responses saying Text sucks and TMPro is the future.

It took a while to find all the places where the old UI.Text system needed to be updated, but eventually that did seem to be the solution. Note to self: Be consistent in what text renderer you use.

There are still some weird things that I haven’t tracked down yet. For example, when I run the prototype, the label for “Bin A” switches to “BinA” (without the space) but none of the other ones do, even though they are duplicates of the first. Or, in the Console, it produces NullReferenceExceptions for the line in Start() where I set countH to zero…but not for any of the other bin-count variables. But each bin counts separately and the display displays them, which satisfies the assignment.

At this point I’ll turn it in, but keep these notes for what to fix (previous paragraph) and what to do next (first paragraph) for when I come back to this prototype. Perfect? No. Is it what I want it to be? No. But sufficient? Yes.

Leave a Comment

Filed under Uncategorized

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