logo Hurry, Grab up to 30% discount on the entire course
Order Now logo

Ask This Question To Be Solved By Our ExpertsGet A+ Grade Solution Guaranteed

expert
Adele AndersonLaw
(5/5)

655 Answers

Hire Me
expert
Joan DomettEngineering
(4/5)

511 Answers

Hire Me
expert
George BlackbridgeBusiness
(5/5)

671 Answers

Hire Me
expert
Trevor RamosEnglish
(5/5)

573 Answers

Hire Me
Python Programming

you draw rectangles, squares, triangles, and hexagons using characters in the terminal. We explore how to draw shapes graphically in your favorite windowing system.

INSTRUCTIONS TO CANDIDATES
ANSWER ALL QUESTIONS

CSCI 141 Computational Problem Solving

you draw rectangles, squares, triangles, and hexagons using characters in the terminal. Next, we explore how to draw shapes graphically in your favorite windowing system. To do this, we will employ the object-oriented principles discussed in lecture including classes, methods, attributes, inheritance, and polymorphism.

Your program should display a 500x500 window on the screen at launch. When the user clicks anywhere in the window, a random shape should appear at that location. A naïve implementation would attempt to contain everything in paintEvent, but this approach quickly becomes unmanageable because of the information needed to draw each shape. A well-structured program will consider individual objects and how they interact. This is the fundamental principle of object-oriented design. What we outline below is a suggested implementation approach.

To begin, define a base class Shape that stores the shape's length, position, and (randomly generated) color. From there, you can inherit these basic properties and further specify additional shapes. At a minimum, your program must support squares, rectangles, triangles, circles, and ellipses. Each shape should define its own class in an inheritance hierarchy based on Shape. Recall that inheritance often spans more than one level, so consider and implement an appropriate inheritance scheme. The classes that define the various shapes should further specify the Shape class by adding additional needed attributes, appropriately invoking parent constructors during initialization, and including a method to draw the shape using a QPainter instance provided as a parameter. Notice that the shape classes fully encapsulate the shape concepts, including the graphical drawing code. By providing an already-in- use QPainter instance to the shapes' draw methods, all of the shape classes should be implemented in a single file called Shapes.py.

Rather than combine the shape implementations with the graphical event-handling code, we can further compartmentalize our solution by using two files. The advantage to this is that the Shapes.py file contains only the code pertinent to creating, maintaining, and drawing the shapes. Everything event-related, such as mouse clicks, belongs in the ShapeDrawer.py control file. We have provided a skeleton file as a starting point for ShapeDrawer.py.

Suggested Approach

When the user clicks somewhere in the window (indicated by a call to mousePressEvent), create a new Shape object at random to be located at the click coordinates and add that Shape to the list of items to draw, which should be an attribute of your class. The Shape object's constructor (in cooperation with its parent constructors) should set all its attributes, including coordinates, color, and size. Feel free to apply reasonable restrictions to shape sizes. Every time the window is drawn

(because something triggered a call to paintEvent), each of the shapes created so far should be drawn. Because they are in a list (see below), you can iterate over them using a loop and draw each shape. The beauty of polymorphism is that you can treat them all as basic Shapes and ask them to draw themselves, because they each implement a draw method that takes a QPainter instance (perhaps the one from paintEvent in ShapeDrawer.py) as a parameter. Note that you must already have activated the painter object by calling its begin method before passing it to a shape's draw method.

The list Data Type

We have seen that for loops iterate over sequential items like strings of characters or elements of a range. Python's list type, which stores a sequence of any objects, generalizes our ability to iterate. A list object can store a collection of items, and a for loop will visit each item in the list. To create a new list, we can (among other ways) use the list constructor, such as my_list = list(). To insert items into the list, we can use the append method, such as my_list.append(shiny_object). Finally, to iterate over the items in the list

Functional Expectations and Point Values

  • 2 points: When the user clicks anywhere in the window, a shape appears somewhere in the

  • 1 point: The upper left corner of shape that appears (or its smallest enclosing rectangle) is located at the click coordinates, or

1.5 points: The center of the shape that appears is located at the click coordinates.

  • 1 point: The shape that appears is randomly selected among Rectangle, Square, Triangle, Ellipse, and

  • 1 point: Shapes are of random size and orientation, or

1.5 points: Shapes are of random size and orientation, but stay within the 500x500 window. Feel free to restrict the maximum size of shapes as you deep appropriate.

  • 2 points: The shapes are defined in individual classes that are fully self- contained (including graphical code). Only the code relevant to each shape is present in the shape classes. Shape classes are imported in py to facilitate drawing. Polymorphism is employed so that the paintEvent never cares what shape it is drawing.

  • 2 points: Quality of your writeup, including its explanation of how classes and inheritance factor into your implementation, references

items you consulted, and a detailed explanation of exactly what happens when a user clicks in the window.

  • 1 point: Dazzle us with something else that you can do with your program that personalizes it without changing the basic functionality described above. Some examples might include shapes taking random walks after they appear, shapes falling downward or floating upward slowly after they appear, shapes disappearing after some time on the screen, more complex and difficult shapes, or events occurring when shapes touch. Your extensions should illustrate your creativity and understanding of object-oriented programming. Some video game aficionados may notice that the classic Atari® game Asteroids is not too far away from this project. Though fully reaching that goal is still a bit difficult, you are closer than you might

Related Questions

. The fundamental operations of create, read, update, and delete (CRUD) in either Python or Java

CS 340 Milestone One Guidelines and Rubric  Overview: For this assignment, you will implement the fundamental operations of create, read, update,

. Develop a program to emulate a purchase transaction at a retail store. This  program will have two classes, a LineItem class and a Transaction class

Retail Transaction Programming Project  Project Requirements:  Develop a program to emulate a purchase transaction at a retail store. This

. The following program contains five errors. Identify the errors and fix them

7COM1028   Secure Systems Programming   Referral Coursework: Secure

. Accepts the following from a user: Item Name Item Quantity Item Price Allows the user to create a file to store the sales receipt contents

Create a GUI program that:Accepts the following from a user:Item NameItem QuantityItem PriceAllows the user to create a file to store the sales receip

. The final project will encompass developing a web service using a software stack and implementing an industry-standard interface. Regardless of whether you choose to pursue application development goals as a pure developer or as a software engineer

CS 340 Final Project Guidelines and Rubric  Overview The final project will encompass developing a web service using a software stack and impleme