Question: PYTHON PROGRAM: Implement a class Moth that models a moth flying randomly in straight lines. The moth has a position and can either move or
PYTHON PROGRAM:
Implement a class Moth that models a moth flying randomly in straight lines. The moth has a position and can either move or move towards a light source. When the moth move towards the light source it moves twice as fast. If the moth touches the light source, it dies. To accomplish this, define a class LightSource with small radius around the light source that if the moth enters it dies. (Continues on next page).
You must supply the following methods, as well as any other methods you think are necessary: a constructor init (self, initialPosition)
a method move(self, newPosition)
a method moveToLight(self, lightPosition)
a method getPosition(self)
Create a simulation using the Turtle module that constructs two light sources anywhere on the screen and a few moths that move at random. Your simulation decides at random if a moth moves in any direction or towards the light source, as well as how far away the moth will move
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
