Question: In Python A Winter Wonderland In this lab, we'll use OOP for graphics programming and add some interactivity to the application. Your Classes The Drawable

 In Python A Winter Wonderland In this lab, we'll use OOP

for graphics programming and add some interactivity to the application. Your ClassesThe Drawable Class In this week's lecture we discussed how we can

used object oriented programming concepts to make graphics applications more organized and

In Python

A Winter Wonderland In this lab, we'll use OOP for graphics programming and add some interactivity to the application. Your Classes The Drawable Class In this week's lecture we discussed how we can used object oriented programming concepts to make graphics applications more organized and easier to create. One of the things that we'll leverage is inheritance, polymorphism, and abstract base classes. We have included drawable.py that contains an abstract base class called (shocker) Drawable This class has the following methods: A constructor _init_method where you can set the x and y locations for your object. Accessor and mutator methods for the x and y locations. An abstract method called draw that takes a surface to draw on as a parameter. Rectangle class Now we're going to derive from this class. The first derived class you'll want to make is Rectangle To instantiate the Rectangle class you need: The (x,y) location where the Rectangle is to be drawn It's width and height It's color Then in the class's draw() method you draw a rectangle starting at (x,y) of dimensions (width, height) on the surface in the chosen color. NOTE: For credit you must derive from Drawable and use it's constructor. The Snowflake Class Next up let's create a Snowflake! A Snowflake will be made up of 4 lines. If the Snowflake is to be centered at (x,y) then those four lines are Line1: (x-5, y) to (x + 5,y) Line2: (xy-5) to (x, y + 5) Line3: (x - 5y-5) to (x + 5, y + 5) Line4: (-5, y + 5) to (x + 5, y-5) To instantiate the Snowflake class you need the (x) location where the Snowflake will start (it's y location will always start as 0) Your draw() method draws the four lines as mentioned based on the current (x, y) location in white. NOTE: For credit you must derive from Drawable and use it's constructor. The Main Application Here's the main application: Draw a"ground plane". Presumably a green rectangle Draw a"sky plane". Presumably a blue rectangle In every iteration of your graphics loop o Loop through all your Drawable objects and draw them. o If the current Drawable is of type Snowflake (hint: use the isinstance function) increment the y coordinate of that Snowflake o Spawn a new Snowflake instance (adding it to your list of Drawables) at a random x location (with y initially set to 0). Interactivity Finally, we'll allow the spacebar to toggle the animation. That is, the first time it is hit, all the snowflakes stop falling. The next time, they resume falling. Etc... Extra Credit For extra credit, when a Snowflake is spawned also assign it a maximum y value that is somewhere (randomly) between the start of the ground plane and the bottom of it. Then when a Snowflake hits its maximum y value it no longer animates. This should make it look like the snow is sticking to the ground! Scoring The score for the assignment is determined as follows: 20 points - Correctly implemented Rectangle derived class. 20 points - Correctly implemented Snowflake derived class. 35 points - Create the basic animation correctly. 15 points - Spacebar correctly toggles animation. 10 points - Program style: attribute magling, good variable names, comments. (10 pts EC) - Snow "sticks to the ground plane. . 290468.1641002 LAB ACTIVITY 13.1.1: CS 172 - Lab 5 0/1 Downloadable files Drawable.py Download File is marked as read only Current file: Drawable.py - 1 import pygame 2 from abc import ABC, abstractmethod 3 4 class Drawable(ABC): 5 def __init__(self, x = 0, y = 0): 6 self.__X = X 7 self. y - y def getLoc(self): return (self.__x, self.--y) def setLoc(self, p): self.__x - p[O] self.--y = p[1] 10 11 12 13 14 15 16 17 18 19 20 @abstractmethod def draw(self, surface): pass A Winter Wonderland In this lab, we'll use OOP for graphics programming and add some interactivity to the application. Your Classes The Drawable Class In this week's lecture we discussed how we can used object oriented programming concepts to make graphics applications more organized and easier to create. One of the things that we'll leverage is inheritance, polymorphism, and abstract base classes. We have included drawable.py that contains an abstract base class called (shocker) Drawable This class has the following methods: A constructor _init_method where you can set the x and y locations for your object. Accessor and mutator methods for the x and y locations. An abstract method called draw that takes a surface to draw on as a parameter. Rectangle class Now we're going to derive from this class. The first derived class you'll want to make is Rectangle To instantiate the Rectangle class you need: The (x,y) location where the Rectangle is to be drawn It's width and height It's color Then in the class's draw() method you draw a rectangle starting at (x,y) of dimensions (width, height) on the surface in the chosen color. NOTE: For credit you must derive from Drawable and use it's constructor. The Snowflake Class Next up let's create a Snowflake! A Snowflake will be made up of 4 lines. If the Snowflake is to be centered at (x,y) then those four lines are Line1: (x-5, y) to (x + 5,y) Line2: (xy-5) to (x, y + 5) Line3: (x - 5y-5) to (x + 5, y + 5) Line4: (-5, y + 5) to (x + 5, y-5) To instantiate the Snowflake class you need the (x) location where the Snowflake will start (it's y location will always start as 0) Your draw() method draws the four lines as mentioned based on the current (x, y) location in white. NOTE: For credit you must derive from Drawable and use it's constructor. The Main Application Here's the main application: Draw a"ground plane". Presumably a green rectangle Draw a"sky plane". Presumably a blue rectangle In every iteration of your graphics loop o Loop through all your Drawable objects and draw them. o If the current Drawable is of type Snowflake (hint: use the isinstance function) increment the y coordinate of that Snowflake o Spawn a new Snowflake instance (adding it to your list of Drawables) at a random x location (with y initially set to 0). Interactivity Finally, we'll allow the spacebar to toggle the animation. That is, the first time it is hit, all the snowflakes stop falling. The next time, they resume falling. Etc... Extra Credit For extra credit, when a Snowflake is spawned also assign it a maximum y value that is somewhere (randomly) between the start of the ground plane and the bottom of it. Then when a Snowflake hits its maximum y value it no longer animates. This should make it look like the snow is sticking to the ground! Scoring The score for the assignment is determined as follows: 20 points - Correctly implemented Rectangle derived class. 20 points - Correctly implemented Snowflake derived class. 35 points - Create the basic animation correctly. 15 points - Spacebar correctly toggles animation. 10 points - Program style: attribute magling, good variable names, comments. (10 pts EC) - Snow "sticks to the ground plane. . 290468.1641002 LAB ACTIVITY 13.1.1: CS 172 - Lab 5 0/1 Downloadable files Drawable.py Download File is marked as read only Current file: Drawable.py - 1 import pygame 2 from abc import ABC, abstractmethod 3 4 class Drawable(ABC): 5 def __init__(self, x = 0, y = 0): 6 self.__X = X 7 self. y - y def getLoc(self): return (self.__x, self.--y) def setLoc(self, p): self.__x - p[O] self.--y = p[1] 10 11 12 13 14 15 16 17 18 19 20 @abstractmethod def draw(self, surface): pass

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!