Quantcast

A community for students. Sign up today!

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

jmeloc

  • 2 years ago

I'm stuck on the tetrominoes. I didn't understand this piece of code 'Shape.__init__(self, coords, "blue")' because it isn't being assigned to any attribute. For example, in the Block class, I've assigned the Rectangle object to the 'it' attribute, which allowed me to further set the color of the block. "self.it = Rectangle(self, p1, p2) self.it.setFill(self, color)" But how can I set its color initializing with 'Rectangle.__init__(self, p1, p2, color)'?

  • This Question is Closed
  1. snark
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    you define a class class X: def __init__(self, color): # this allows you to set the self.color = color # color when you create an X object now, when you create a member of the class, you can set it's color at the same time: bob = X(red) #: create a red X object called bob the def __init__(self,color) allows you to set the color with X(red) rather than: bob = X() # without the def __init__ bob.color = 'red' # you would do this

  2. Screech
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Block IS A Rectangle and as part of the Block __init__ you need to calculate the corner points, invoke the Rectangle __init__ and then fill with the specified color. On the other hand, Shape HAS one or more Blocks. You won't explicitly create a Shape object. It will serve as a parent to a child object of a particular shape (I_shape for example) which will specify the list of coordinates (relative to the center) and the color.

  3. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Ask a Question
Find more explanations on OpenStudy

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.