From 2938eb065d77ab91fa1a8844a4a24ffd5603b37e Mon Sep 17 00:00:00 2001 From: Pat Wick Date: Fri, 28 Jul 2023 11:27:00 -0400 Subject: [PATCH] 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. --- __pycache__/tile.cpython-310.pyc | Bin 0 -> 1600 bytes __pycache__/tile_grid.cpython-310.pyc | Bin 0 -> 1237 bytes tile.py | 25 ++++++++++++------------- tile_grid.py | 7 ++++++- 4 files changed, 18 insertions(+), 14 deletions(-) create mode 100644 __pycache__/tile.cpython-310.pyc create mode 100644 __pycache__/tile_grid.cpython-310.pyc diff --git a/__pycache__/tile.cpython-310.pyc b/__pycache__/tile.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..d6e1e655bbbd21346a5128d5057c57630265d5da GIT binary patch literal 1600 zcma)6&2Aev5GHq5E9%d+W4A~f1SJ~xpu(~0TMlVapgy*`G$#XvLhn!#>(#Ezr7Box zPYzJ@Ez+a!eS^LQ(OXY?g&u;=P_iN04U%1uGvtyp-^@3&WvA0*_{4wz1;59P{X>h* zC&I-yII8b(0tP&1FGxl?Kj9EV@`{~AP=gd@40RAF6KFsaWer-;MwvnfwoumL1K36> zAo_uIca~_8b-CwX^fONS`XQa%ev6~p!^yE<*d^!8@s$LQ*Q3R=W2@$sEDJ52$@PJp zk4-j~nJVO|mR3)-avG#7<*>99spM2Sr)_cA??!$H@bZA}4a%9zO`&}&Y=N%KsJP-j zsmwxOFfm(}6)R%9*n0 zk^RHzg>T$=ODHIsMAYWCfy%pL2YxGdMzQx7^(PP>3`IKj9o z=c|~LTo0XZp6Zb)2DEKkbRwB3H%1Q6t@A<`5I*^Mm|y&Fc8HM?M0v40#IO376j$#N(w16t;~7`d^0Ne%IGNr_mV;1tkXRg82%Z+CI88(G3d%>(zK z6EUCSsHh;@0ebQ#&~*zu_5Tg{ZCp?pwkUuI6H331c=6>mR4RCEH^Pd2uWWW8-OLu4 zU21$c#vg$hjoqPrjE4Hy)@f#JmTS_i0yC@bB-rn)O%Bl5AYA?&uU3@O?a1zGO&+f#X& zz61~AE2q8!7npIjWm|~@v$AJAw&U-cZ&vnt5dmxT55D6O@)H;9=D^}5jOH0koN!u^ zkLaC>PMl+h67F*EJ2`f_&jaut-{2v5pKtOAe89IpkR-l@+a#feKE0sE9af719=o;x zB3!?L(Y%96lO;W;N96OPGY?{75t zy-%`LOw6ZMUg!4cSSWFj*v&!W8(-!1NGRlE?kS;LRcBge^GvF8RMuu^BEN~Ooo2EY znUb^hLyOg+Brv{(YJv`_*|hMQ@>H1K4Wx!H44q#PwF3|SdYz8tM5NPMS$s_=`PZ@@ zWymfoBp2yqRve~nUFyTM%D-f#7Rpjc?H92Y2h)YwM(){l3j3qkhAH-A8q&!AwyC-c zsRG;M$}o0eSQYyaXsG{^^g+u$CcCvk-E-FdC#7 zIx&r@!dyXNx-yKBxmD&d1ncZ9%bU!0-$RSuP@tW{e?cHWbsz2nO!WY~1*uT$gm%@x zRrn3qdIDnwFGP5l8zdVh=+reHwp#Zk>?tdb)5w_n(Jx%z0B6(Yh7s#xMVG09i LPABYzUL5=ZBP$>7 literal 0 HcmV?d00001 diff --git a/tile.py b/tile.py index 697cf8e..5271194 100644 --- a/tile.py +++ b/tile.py @@ -1,27 +1,26 @@ from turtle import * +import math def draw_tile(size): "Draws one tile, which can be repeated to form a pattern." draw_tile_outline(size) - draw_squiggle(size) + draw_design(size) def draw_tile_outline(size): pencolor("#dddddd") square(size) -def draw_squiggle(size): - forward(size/4) +def draw_design(size): + forward(size/2) pencolor("black") - left(90) - quarter_arc_right(size/4) - quarter_arc_left(size/4) - quarter_arc_left(size/4) - quarter_arc_right(size/4) - left(90) - fly(size/4) - left(90) - fly(size) - left(90) + fillcolor("black") + left(45) + begin_fill() + square(math.sqrt(2 * ((size / 2) ** 2))) + end_fill() + left(135) + fly(size/2) + left(180) def fly(distance): "Moves without drawing." diff --git a/tile_grid.py b/tile_grid.py index 72a0f43..f2cfab6 100644 --- a/tile_grid.py +++ b/tile_grid.py @@ -10,7 +10,12 @@ from tile import fly def draw_tile_grid(width, height, tile_size, tile_function): """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 x in range(width):