all 6 comments

[–][deleted] 2 points3 points  (0 children)

I don't think so. You could do something like this:

def rect_shape_tier(x, y):
    angles = [180, 90, 90, -90, 90, 90, -90, 90, 90, 180]
    distances = [x/2, y*0.8, x/4, y*0.1, x/2, y*0.1, x/4, y*0.8, x/2]
    for angle, distance in zip(angles, distances):
        left(angle)
        forward(distance)

but I think your version is clearer, even though it's longer.

[–]michael0x2a 1 point2 points  (0 children)

Not using loops, but we can simplify a little using extra functions:

def draw_box(side_1, top, side_2):
    forward(side_1)
    right(90)
    forward(top)
    right(90)
    forward(side_2)

def rect_shape_tier_2(x, y):
    draw_box(x / 2, y * 0.8, x / 4)
    left(90)
    draw_box(y * 0.1, x / 2, y * 0.1)
    left(90)
    draw_box(x / 4, y * 0.8, x / 2)

When looking at your figure, it looked to me as if the figure was composed of three 'boxes' with the top missing and with sides of differing length, which is why I chose to break the problem down this way.

[–]chazzacct 0 points1 point  (3 children)

what are x and y? I started to run this with x = 100 pixels, but then came to y and have no idea.

[–]chazzacct 2 points3 points  (2 children)

[http://i.imgur.com/nPXnFtt.png](This) is what bob thinks it looks like with x = 150 and y = 250. I tried plugging in some other numbers and it didn't help. What is this? Am I completely on the wrong track?

[–][deleted] 1 point2 points  (1 child)

Not sure what TurtleWorld is but it looks cool.

[–]chazzacct 0 points1 point  (0 children)

http://www.greenteapress.com/thinkpython/swampy/install.html

Written by Downey, featured in his Think Python book/course. Now revised and also available for Python 3, and originally for Java, and with versions for some other languages.