generated from mwc/lab_iteration
Added a filled square to tile design
I probably will, but I'm still not 100% confident that I know the use-case for a docstring versus a comment. The quick Google search I did was "comments explain how code works, docstrings explain what a piece of code does" but that kind of sounds like the same thing to me? Either way, documentation is super important and while I try to solve a lot of readability by appropriatly naming variables/functions, somethings a note to myself (let alone someone else) is really needed to make the code usable again in a timely manner a year/month/week/day later.
This commit is contained in:
parent
e8b85fd9a2
commit
2938eb065d
Binary file not shown.
Binary file not shown.
25
tile.py
25
tile.py
|
@ -1,27 +1,26 @@
|
||||||
from turtle import *
|
from turtle import *
|
||||||
|
import math
|
||||||
|
|
||||||
def draw_tile(size):
|
def draw_tile(size):
|
||||||
"Draws one tile, which can be repeated to form a pattern."
|
"Draws one tile, which can be repeated to form a pattern."
|
||||||
draw_tile_outline(size)
|
draw_tile_outline(size)
|
||||||
draw_squiggle(size)
|
draw_design(size)
|
||||||
|
|
||||||
def draw_tile_outline(size):
|
def draw_tile_outline(size):
|
||||||
pencolor("#dddddd")
|
pencolor("#dddddd")
|
||||||
square(size)
|
square(size)
|
||||||
|
|
||||||
def draw_squiggle(size):
|
def draw_design(size):
|
||||||
forward(size/4)
|
forward(size/2)
|
||||||
pencolor("black")
|
pencolor("black")
|
||||||
left(90)
|
fillcolor("black")
|
||||||
quarter_arc_right(size/4)
|
left(45)
|
||||||
quarter_arc_left(size/4)
|
begin_fill()
|
||||||
quarter_arc_left(size/4)
|
square(math.sqrt(2 * ((size / 2) ** 2)))
|
||||||
quarter_arc_right(size/4)
|
end_fill()
|
||||||
left(90)
|
left(135)
|
||||||
fly(size/4)
|
fly(size/2)
|
||||||
left(90)
|
left(180)
|
||||||
fly(size)
|
|
||||||
left(90)
|
|
||||||
|
|
||||||
def fly(distance):
|
def fly(distance):
|
||||||
"Moves without drawing."
|
"Moves without drawing."
|
||||||
|
|
|
@ -10,7 +10,12 @@ from tile import fly
|
||||||
def draw_tile_grid(width, height, tile_size, tile_function):
|
def draw_tile_grid(width, height, tile_size, tile_function):
|
||||||
"""Draws a (width x height) grid, with tile_function drawn on each tile.
|
"""Draws a (width x height) grid, with tile_function drawn on each tile.
|
||||||
|
|
||||||
(Your explanation here.)
|
The inner-loop draws each tile to fill out a row, after which the turtle goes
|
||||||
|
back to the beginning of the row and then moves up to begin filling out the
|
||||||
|
next row (the outer-loop controls how many times to shift up in the overall
|
||||||
|
grid), continuing this build-row-then-shift process until the complete
|
||||||
|
grid has been created. The turtle finishes the process back in the lower-left
|
||||||
|
corner of the grid that it created.
|
||||||
"""
|
"""
|
||||||
for y in range(height):
|
for y in range(height):
|
||||||
for x in range(width):
|
for x in range(width):
|
||||||
|
|
Loading…
Reference in New Issue