Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Part 1: The Drawable Class In this week's lecture we discussed how we can used object oriented programming concepts to make graphics applications more organized

Part 1: 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.

Part 2: 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.

Part 3: The Snowflake Class

Now switch roles!

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)=>(x+5,y)
  • Line2: (x,y-5)=>(x,y+5)
  • Line3: (x-5,y-5)=>(x+5,y+5)
  • Line4: (x-5,y+5)=>(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)

And in its draw method you draw a 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.

Part 4: The Main Application

Switch roles again!

Here's the main application:

  • Draw a"ground plane". Presumably a green rectangle
  • Draw a"sky plane". Presumably a blue rectangle
  • Every iteration of your graphics loop
    • Loop through all your drawable objects and draw them.
    • If the current drawable is of type Snowflake (hint: use the isinstance function) increment the y coordinate of that Snowflake
    • Spawn a new Snowflake instance (adding it to your list of drawables) at a random x location (with y initially set to 0).

programming language is python

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning C# 2005 Databases

Authors: Karli Watson

1st Edition

0470044063, 978-0470044063

More Books

Students also viewed these Databases questions

Question

3. Is there opportunity to improve current circumstances? How so?

Answered: 1 week ago