Showing posts with label Chapter 12. Show all posts
Showing posts with label Chapter 12. Show all posts

Wednesday, March 14, 2012

Listing 12.4

In Listing 12.4 the signature for the _draw method in line 19 should include a parameter to reference a turtle, since the turtle is in fact needed by the child classes.

def _draw(self, someTurtle):
   print("error:…")

Monday, August 24, 2009

Chapter 12 -- Listing 12.8

There is a typo in Listing 12.8. In the init method the instance variable is visibleObjects. The b is missing in the text. In addition, the calls to up() and tracer should be added to the drawAll() method as they are in listing 12.4

Here is a complete, corrected version of Listing 12.8


class Canvas:

def __init__(self,w,h):
self.width = w
self.height = h
self.visibleObjects = []
self.turtle = cTurtle.Turtle()
self.turtle.setup(width=self.width,height=self.height)
self.turtle.hideturtle()

def drawAll(self):
self.turtle.reset()
self.turtle.tracer(0)
for shape in self.visibleObjects:
shape._draw(self.turtle)
self.turtle.tracer(1)
self.turtle.hideturtle()

def addShape(self,shape):
self.visibleObjects.append(shape)

def draw(self,gObject):
gObject.setCanvas(self)
gObject.setVisible(True)
self.turtle.up()
self.turtle.tracer(0)
gObject._draw(self.turtle)
self.turtle.tracer(1)
self.addShape(gObject)


Friday, May 8, 2009

Listing 12.1

Lines 4, 6, and 16 incorrectly call a method named fillColor. the name of the method should be setFill. For example line 4 should read house.setFill('blue')