# Pages Gautam Mitra’s Home Gautam's CS152 Project 9

Summary:

This project focused on making more complicated physics simulations. It was primarily driven by the usage of the OOP concept inheritance to cut down on code and streamline the process. In particular, we created a pinball-esque physics simulation. In my project, a ball bounces around a "container" which also has a block, triangle, and oval that the ball can bounce off of.

In this task, we create a Floor class inheriting from the Thing class made in lab. The __init__() function calls Thing's __init__ which is how we get a lot of the useful functionality from the Thing class. I used the Zelle Rectangle as the visualization for the floor.

This is nearly identical to the last task except for slightly different visualization as well as using a 'wall' type.

This was also quite similar to the last two. However, since blocks aren't infinite, the visualization and anchor points had to be modified. This used a 'block' type.

Using my newfound knowledge of dictionaries, I added the following to my collision.py:

This task was the most effort of them all. The first function creates all of the obstacles and boundaries and puts them in a list. The second function makes it so that the ball can be launched from a certain position. Then, the main function puts it all together. A pinball-like table is created with a floor, ceiling, two walls, and a block in the middle. A single ball is launched and then bounces around the table.

pinball sim1.mov

For this task, I made a Triangle class in the physics_objects.py file. I put the triangle on top of the center block so that it would look like a little house. Since I didn't want to create a collision detection function for a triangle, I used the 'block' type. Since triangles aren't squares, the collision detection on my triangle is not great, but it is still passable.

Extension 1: More interesting area

I already did this by the time I made the video for task 5. Originally my space was just a ceiling, floor, and two walls. To spice it up a little bit aesthetically, I added cut-off blocks to each corner. This is a subtle change, but I think it looks pretty cool and minimalistic (which synergizes well with the black and white color scheme). I later ruin this aesthetic by changing the ball color and adding an oval.

Extension 2: Sound

Please be warned, if you actually run my program, this extension gets extremely annoying, extremely quickly. I used the os package to play a sound every time the ball hits a block.

Extension 3: Ball color flag

I added a Terminal flag using the sys package so that the following flag can be used: "-C <red value> <green value> <blue value>" The RGB values provided are then sent to a setFill function I made which will set the ball color to the desired RGB value.

Extension 4: Keyboard commands (ball color, re-launch, hyper speed)

I used the win.checkKey() function so that I could interact with the pinball simulation while it is running. Pressing 'r' will cause the ball the launch again. Pressing  'c' will randomly change the color of the ball. Pressing 'e' will put the ball into hyper speed (this really just sets the ball elasticity to 1.5 which quickly spirals out of control).

Extension 5: Oval shape

I added another class. This one is the Oval class. For this, I set it as a 'ball' because ovals are of a relatively similar shape to circles. As a result, the collision detection is not that bad.

Extension 6: Background Picture

I found this pretty silly picture of the Colby CS department sitting around a table on the cs.colby.edu website. I then set it as a background image for my pinball game. Zelle doesn't like JPEGs or JPGs or PNGs or any other normal format, so I used an online converter to change the faculty picture to a GIF file.

What I Learned:

I learned a lot more about inheritance and polymorphism. I also learned more about the Zelle graphics library.

Collaborators:

none

Labels