In graphics applications, it is often useful to group separate pieces of a drawing

Chapter 11, Problem 17

(choose chapter or problem)

Get Unlimited Answers
QUESTION:

In graphics applications, it is often useful to group separate pieces of a drawing together into a single object. For example, a face might be drawn from individual shapes, but then positioned as a whole group. Create a new class GraphicsGroup that can be used for this purpose. A GraphicsGroup will manage a list of graphics objects and have the following methods: __ init __ ( self , anchor) anchor is a Point. Creates an empty group with the given anchor point. get Anchor ( self ) Returns a clone of the anchor point. addObj ect ( self , gObj ect) gObj ect is a graphics object. Adds gObj ect to the group. move ( self , dx , dy) Moves all of the objects in the group (including the anchor point) . draw(self , win) Draws all the objects in the group into win. The anchor point is not drawn. undraw( self ) Undraws all the objects in the group. Use your new class to write a program that draws some simple picture with multiple components and moves it to wherever the user clicks.

Questions & Answers

QUESTION:

In graphics applications, it is often useful to group separate pieces of a drawing together into a single object. For example, a face might be drawn from individual shapes, but then positioned as a whole group. Create a new class GraphicsGroup that can be used for this purpose. A GraphicsGroup will manage a list of graphics objects and have the following methods: __ init __ ( self , anchor) anchor is a Point. Creates an empty group with the given anchor point. get Anchor ( self ) Returns a clone of the anchor point. addObj ect ( self , gObj ect) gObj ect is a graphics object. Adds gObj ect to the group. move ( self , dx , dy) Moves all of the objects in the group (including the anchor point) . draw(self , win) Draws all the objects in the group into win. The anchor point is not drawn. undraw( self ) Undraws all the objects in the group. Use your new class to write a program that draws some simple picture with multiple components and moves it to wherever the user clicks.

ANSWER:

Step 1 of 3

The __init__() methods acts a constructor of the class. It initializes the anchor. The getAnchor() method is used to get the anchor. The getData() method returns the group of all the elements. The addObject() methods is used to add new element in the group. The move() method moves all the element. The draw() and undraw() functions are used to draw and remove the elements from the window.

Add to cart


Study Tools You Might Need

Not The Solution You Need? Search for Your Answer Here:

×

Login

Login or Sign up for access to all of our study tools and educational content!

Forgot password?
Register Now

×

Register

Sign up for access to all content on our site!

Or login if you already have an account

×

Reset password

If you have an active account we’ll send you an e-mail for password recovery

Or login if you have your password back