From c33df2727fa4c1286f837449853a59c14e7e31c1 Mon Sep 17 00:00:00 2001
From: schwabmi <michel.j.schwab@gmail.com>
Date: Wed, 14 Dec 2022 11:35:39 +0100
Subject: [PATCH] updated solution ex2

---
 notebooks/seminar04.ipynb | 47 ++++++++++++++++++++-------------------
 1 file changed, 24 insertions(+), 23 deletions(-)

diff --git a/notebooks/seminar04.ipynb b/notebooks/seminar04.ipynb
index eb77a47..dc1f589 100644
--- a/notebooks/seminar04.ipynb
+++ b/notebooks/seminar04.ipynb
@@ -1316,39 +1316,40 @@
    "metadata": {},
    "outputs": [],
    "source": [
-    "import turtle\n",
+    "import turtle, math\n",
     "\n",
     "zoe = turtle.Turtle()\n",
     "zoe.speed(10)\n",
     "\n",
-    "def ring(t, length, radius, k):\n",
-    "    t.color(colors[k])\n",
-    "    t.up()\n",
-    "    t.forward(length)\n",
-    "    t.down()\n",
-    "    t.circle(radius)\n",
-    "        \n",
     "\n",
+    "# colors of the olympic rings     \n",
+    "colors = [\"blue\", \"yellow\", \"black\", \"green\", \"red\"] \n",
     "\n",
-    "def rings(t, length, radius):\n",
-    "    t.width(10)\n",
-    "    k = 0\n",
-    "    for i in range(3):\n",
-    "        ring(t, length, radius, k)\n",
-    "        k += 1\n",
-    "    t.penup()\n",
-    "    t.goto(radius,-radius)\n",
-    "    t.pendown()\n",
-    "    for i in range(2):\n",
-    "        ring(t, length, radius, k)\n",
-    "        k += 1\n",
     "\n",
-    "        \n",
-    "colors = [\"blue\", \"black\", \"red\", \"yellow\", \"green\"]\n",
+    "# jumps to correct position for drawing a circle\n",
+    "def goto(t, radius, i):\n",
+    "    t.fd(radius*1.1) \n",
+    "    if i % 2 == 0:\n",
+    "        t.rt(90)\n",
+    "        t.fd(radius)\n",
+    "        t.lt(90)  \n",
+    "    else:\n",
+    "        t.lt(90)\n",
+    "        t.fd(radius)\n",
+    "        t.rt(90)  \n",
     "\n",
-    "rings(zoe, 125, 50)\n",
+    "# draws the olympic rings\n",
+    "def olympic_rings(t, radius):\n",
+    "    t.width(math.sqrt(radius)) \n",
+    "    for i in range(5): # draw five circles\n",
+    "        t.color(colors[i]) # remove this line for drawing without colors\n",
+    "        t.circle(radius) \n",
+    "        t.up()\n",
+    "        goto(t, radius, i) # jump to next starting point \n",
+    "        t.down()\n",
     "\n",
     "\n",
+    "olympic_rings(zoe, 50)\n",
     "\n",
     "        \n",
     "turtle.mainloop()\n",
-- 
GitLab