Wednesday, September 23, 2009

Chapter 11 Listing 11.12

The loop in lines 20 through 27 re-uses the newfish variable rather than a more correctly named newbear. the function still works properly but the variable name is confusing. Here is a corrected version of lines 20 -- 27.


for i in rnage(numberOfBears):
newbear = Bear()
x = random.randrange(myworld.getMaxX())
y = random.randrange(myworld.getMaxY())
while not myworld.emptyLocation(x,y):
x = random.randrange(myworld.getMaxX())
y = random.randrange(myworld.getMaxY())
myworld.addThing(newbear,x,y)

3 comments:

  1. Not to be a pest, but there's a small typo in this posting:

    for i in rnage(numberOfBears):

    should read:

    for i in range(numberOfBears):

    ReplyDelete
  2. Did I miss something? Are the bear, plant, and fish.gif files used in the text example posted somewhere? It would be really helpful if you post the .gif files use in the examples. It is difficult to duplicate the results from the textbook when I'm not exactly sure of the size of the original .gif images.

    ReplyDelete
  3. To Leslie: I was able to work around this problem by grabbing some adequate substitute images off of openclipart.org and rendering them to a size that seemed to work similarly to what was shown on the book -- overlapping if the organisms are at adjacent cells, but large enough to be visually interpretable. That size, given the grid dimensions in the book and the default size of the cTurtle canvas, seems to be 40 pixels wide. The clipart comes in a scalable form (SVG) and so can be converted to a GIF of whatever size works best for you -- as I said, I got results that seemed reasonable with a width of 40 pixels. I did the conversion to GIF form using the Gimp program. I haven't (yet anyhow) grabbed a Plant, but for the Bear and Fish I used http://www.openclipart.org/detail/32533 and http://www.openclipart.org/detail/518

    ReplyDelete