Write a function named centeredSquares() that draws a set of squares of different size around a common center point. centeredSquares() takes four parameters. The first parameter is the length of the side of the first square to draw. The second parameter is the number of squares to draw. The third parameter is how much bigger (or smaller) the length of the side of each succeeding square should be. The fourth parameter is a pen object.

so far i have:

def square(side,p):
    for i in range(4):
        p.forward(side)
           p.right(90)

def centSquare(len,num,inc,p):
    for i in range(num):
        ??

Recommended Answers

This should help a little:

import turtle as tu

'''
turtle by default starts at (x=0, y=0) center of a (450x550) window
to pick another center lift the pen up then move
to the right x units and up y units or ...
to the left -x …
Jump to Post

All 2 Replies

This should help a little:

import turtle as tu

'''
turtle by default starts at (x=0, y=0) center of a (450x550) window
to pick another center lift the pen up then move
to the right x units and up y units or ...
to the left -x units and down -y units
now drop the pen down to start drawing
tu.up()
tu.goto(-50, 100)
tu.down()
'''

def square(side):
    for k in range(4):
        tu.forward(side)
        tu.right(90)

def centSquare(len, num, inc):
    for k in range(num):
        tu.up()
        tu.goto(-(len/2), len/2)
        tu.down()
        square(len)
        len += inc

len = 20
num = 4
inc = 10

centSquare(len, num, inc)

# keep showing until window corner x is clicked
tu.done()
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.