Assignment 6 - OOP - Advanced Atoms
We'll continue where we left off from our last assignment.
Use the atom.py
file to edit and create your code.
The playground.py
file provides plotting (do not change the content).
The atom.py
file contains ExampleWorld
class that represents an environment where individual atoms are present
(and your task is to make them of different colors and some should be dragged to the ground by gravity).
At tick intervals, the tick()
method of ExampleWorld
is called.
An atom is represented by three values stored in the tuple (position_x, position_y, radius, color)
.
These quadruples are returned as a tuple in the tick()
method.
Download: advanced_atoms.zip
Task 1: (2 point)
Adapt the random_atom
method of the ExampleWorld
class so that it randomly place atoms around the drawing area.
To do so, use random.randint
function.
Also, pick up a random color from playground.Colors
enum. Use random.choice
function.
You can convert from enum
to list
datatypes by simply calling list
function on the given enum.
Task 2: (3 points)
Create an FallDownAtom
class that will represent atoms that are dragged to the ground by gravity.
The effect of gravity is, of course, not instant, so atoms experience some bouncing.
To effectively implement the FallDownAtom
class, you can extend it from the Atom
class.
In constructor, you have to call the constructor of the Atom
class as: Atom.__init__(...
.
To change the behavior of movement, implement the move
method in the FallDownAtom
class.
Gravity has an effect only on the y
coordinate of the atom's speed.
Every time an atom hits the bottom, the y
value of the speed decreases by a given damping factor.
Use value of 3.0
as gravitational acceleration and value of 0.8
as damping factor.