For this milestone, you will be creating a simple n by n grid. Each grid cell will be a square, with all of them either filled or unfilled. The grid should completely fill the Turtle window (more about this below.) You will first ask for 3 inputs: Grid size n as an integerPen color as a stringFill color as a string Then using the inputs, produce a grid using these 3 inputs. Here is a sample output: Grid size (n): (input) Pen color: (input) Fill color: (input) Bolded text are inputs and would not appear in the autograder's tests Next are some examples of the grid your program should produce: The fill color and pen color is up to your decision. By the end of this milestone, your program should be able to produce an n by n grid that is either filled or unfilled. For our grids to completely fill the Turtle window, we need to control both the size of the drawing canvas and the size of the window that holds the drawing canvas. We have several methods and properties of the Screen object that will help us do this. Screen.screensize(width, height) - sets the size of the drawing canvas Screen.setup(width, height) - sets the size of the window Screen.screensize() - returns the canvas size as a tuple (width, height) Screen.canvwidth - equal to the canvas width Screen.canvheight - equal to the canvas height # assuming variable s is a screen object size_for_canvas = 500 # window size # needs to be a little larger for window edge chrome s.setup(width=size_for_canvas + 10, height=size_for_canvas + 10) # set the canvas size s.screensize(size_for_canvas, size_for_canvas) NOTES on Turtle: turtle.mainloop() - Keep this while you're testing your program, should be the last line of code. Prevents your program from ending before you can see your turtle drawing. Delete it before you submit for grading, leaving it will prevent your program from terminating and the autograder will timeout. turtle.tracer(False) - turns drawing off, please use to speed up drawing (Turtle code is slow only if window is updated as code runs) turtle.tracer(True) - turns drawing on, where ever this is placed in your code will trigger a window update, so drawing will appear.
For this milestone, you will be creating a simple n by n grid. Each grid cell will be a square, with all of them either filled or unfilled. The grid should completely fill the Turtle window (more about this below.)
You will first ask for 3 inputs:
- Grid size n as an integerPen color as a stringFill color as a string
Then using the inputs, produce a grid using these 3 inputs.
Here is a sample output:
Grid size (n): (input) Pen color: (input) Fill color: (input)
Bolded text are inputs and would not appear in the autograder's tests
Next are some examples of the grid your program should produce:
The fill color and pen color is up to your decision.
By the end of this milestone, your program should be able to produce an n by n grid that is either filled or unfilled.
For our grids to completely fill the Turtle window, we need to control both the size of the drawing canvas and the size of the window that holds the drawing canvas. We have several methods and properties of the Screen object that will help us do this.
- Screen.screensize(width, height) - sets the size of the drawing canvas
- Screen.setup(width, height) - sets the size of the window
- Screen.screensize() - returns the canvas size as a tuple (width, height)
- Screen.canvwidth - equal to the canvas width
- Screen.canvheight - equal to the canvas height
# assuming variable s is a screen object
size_for_canvas = 500
# window size
# needs to be a little larger for window edge chrome
s.setup(width=size_for_canvas + 10, height=size_for_canvas + 10)
# set the canvas size
s.screensize(size_for_canvas, size_for_canvas)
NOTES on Turtle:
turtle.mainloop() - Keep this while you're testing your program, should be the last line of code. Prevents your program from ending before you can see your turtle drawing. Delete it before you submit for grading, leaving it will prevent your program from terminating and the autograder will timeout.
turtle.tracer(False) - turns drawing off, please use to speed up drawing (Turtle code is slow only if window is updated as code runs)
turtle.tracer(True) - turns drawing on, where ever this is placed in your code will trigger a window update, so drawing will appear.
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 4 images
can you used to the basic turtle like t.forward, t.left, t.right used that in the code it has to be draw out