From 15a9448b12e7e2163dd423169b1ada80181f0629 Mon Sep 17 00:00:00 2001 From: TiagoRG <35657250+TiagoRG@users.noreply.github.com> Date: Mon, 16 Jan 2023 13:53:04 +0000 Subject: [PATCH] FP: Aula10 - Ex6 added --- 1ano/fp/aula10/recmickey.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 1ano/fp/aula10/recmickey.py diff --git a/1ano/fp/aula10/recmickey.py b/1ano/fp/aula10/recmickey.py new file mode 100644 index 0000000..d7f730c --- /dev/null +++ b/1ano/fp/aula10/recmickey.py @@ -0,0 +1,35 @@ +import sys +from ezgraphics import GraphicsWindow + + +def circle(canvas, x, y, r): + """Draw a filled circle with center (x, y) and radius r.""" + canvas.drawOval(x - r, y - r, 2 * r, 2 * r) + + +# Draw a Mickey fractal with n levels. +# n=1 produces a circle, n=2 produces a familiar face. +def mickeyFractal(canvas, x, y, r, n): + # The largest circle has center (x, y) and radius r. + circle(canvas, x, y, r) + if n == 1: + return + mickeyFractal(canvas, x - r, y - r, r / 2, n - 1) + mickeyFractal(canvas, x + r, y - r, r / 2, n - 1) + + +def main(): + UNIT = 32 + + win = GraphicsWindow(4 * UNIT, 4 + 3 * UNIT) + canvas = win.canvas() + canvas.setColor("cyan") + canvas.setOutline("black") + + n = int(sys.argv[1]) + mickeyFractal(canvas, 2 * UNIT, 2 * UNIT, UNIT, n) + + win.wait() + + +main()