From 23e57c7c6c1c3ff0a8053ce6df0c9e9006d52c9f Mon Sep 17 00:00:00 2001 From: ilmabura Date: Tue, 30 Sep 2025 23:15:41 -0400 Subject: [PATCH] Commit 3: Created watching penguins I had a lot of fun creating the animation of walking penguins. I initially didn't understand how the frames worked but reading the source code helped me a lot. While creating an animation I realized that I needed to edit my static drawing functions. I still need to edit them to firther my animation. For some strange reason when running my animation, i get the background and i need to hit enter before the animation starts playing. I don't understand why this occurs. Is it something I did or is that just how it runs? Commit 1: Created a static image of a penguin on an iceberg I was struggling how to draw an oval for my penguin. I needed to look up videos/read up how to do it. I also had to look up how to set the size of the image. I found it really difficult to just start the penguin, but once I got the shapes I felt more comfortable. Commit 2: Created an iteration of penguins Created a function penguins which iterates the drawing of the penguin until the end of the screen. I needed to do some debugging for this to work, I managed to solve it, but I don't know how I fixed the issue. For some strange reason it's drawing the first penguin twice and I don't know why. I need to figure that out. This part was much easier than drawing out the shapes. --- __pycache__/drawing.cpython-312.pyc | Bin 4715 -> 3948 bytes __pycache__/penguins.cpython-312.pyc | Bin 0 -> 1161 bytes diving_penguins.py | 11 ++++ drawing.py | 87 ++++++++++----------------- penguins.py | 34 ++++++----- 5 files changed, 64 insertions(+), 68 deletions(-) create mode 100644 __pycache__/penguins.cpython-312.pyc create mode 100644 diving_penguins.py diff --git a/__pycache__/drawing.cpython-312.pyc b/__pycache__/drawing.cpython-312.pyc index e4df4f223de55fb533482e0780aebcc4faaaa6a4..33993cee1e4f3bf1af4ff37f68a70bc2c412dabe 100644 GIT binary patch literal 3948 zcma)9T}&L;6~1?NW_I=uSir`1T6-E?%%(0BNaI9}QUi7zI|;RM8YlDz4SR=W?A;x5 zX9z4^BrH*7ut~MZsf=4HQ6-hI>`JZF2TSckAF96e1r!|FBc!UTAIh6;{80I!?m08C zGbE1MyP7lS-gEAmd(Y2z@BS^7iW6u*`NjH3Ta1u@VrRQ4Tg>KBO2}2h2%~xOTY(}c z(HmQ41{7U6->_{wcr)n+*vCc*XzcR& z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uOqzCE!78;)vka|SH1J~0jh1!tyosgBT^zmaWUkZq4-LaQg_OTo!t=47sWp0q6b zn={Q<*JsyX-Y_9A5}S3ux?`Taj-8sx8hE;rmcNVj6ZTG}GhwM%sp-S)VF&|qd?Zgb9< z-ZzuF7g`|ua9cuA%L7tXVvpSOFOc44Z1*CMVO}7!Dbt@jKHWQW?Dhu> q1+r`T2+Ay<2O~Riq!#j9SB`^Y>|Y=|iX+{S?|NrWeM#DEbN>&y7@yz( diff --git a/__pycache__/penguins.cpython-312.pyc b/__pycache__/penguins.cpython-312.pyc new file mode 100644 index 0000000000000000000000000000000000000000..38b1c6df8db6ca227d6ba76c510a465d0cfa8fcd GIT binary patch literal 1161 zcmaKqO-vI(6vt^bcy-r_PWOGP)-C+)*c+8xkrY_3VNf{#CD=uj}R!KH zQzFG!Nh*=A%Gf?q0x`USYjUJGy{Y_=dyD6bv8{_Gp+vV6J1g(=Rr%(hRpZ0cs(i0q z$EC#f;*PO<>r?zol2m2AJ=72and?8~!Qx6Ovc*b^+Y!K*s`9mV?e6vkSWw-)^i7`K z8{xY;fGwj1IJ!`?M>oiFlv%ppl^ZbaOpd)lR0WJ)26rgWq#cs8^c!>%QvNEkL*Raj Y7~>imsG2LJ#7 literal 0 HcmV?d00001 diff --git a/diving_penguins.py b/diving_penguins.py new file mode 100644 index 0000000..a9a067b --- /dev/null +++ b/diving_penguins.py @@ -0,0 +1,11 @@ +from superturtle.animation import animate +from penguins import * +from drawing import * + +for frame in animate(60, debug=False, loop=True): + if frame.index%2==0: + penguins(120,0,0) + else: + penguins(120,345,35) + +input() \ No newline at end of file diff --git a/drawing.py b/drawing.py index f819276..87a0d9b 100644 --- a/drawing.py +++ b/drawing.py @@ -5,60 +5,60 @@ # Draws the image of penguins on an iceberg # (Briefly describe what this program does.) -import turtle +from turtle import * from math import cos, sin, pi, radians # ---------- Setup ---------- -turtle.setup(1000, 600) -screen = turtle.Screen() +setup(1000, 600) +screen = Screen() screen.title("Penguin on Ice (with real ovals)") screen.bgcolor("white") +screen.tracer(0) -t = turtle.Turtle(visible=True) -t.speed(0) -t.pensize(3) -t.pencolor("black") +pensize(3) +pencolor("black") # ---------- Helpers ---------- def move_to(x, y): - t.penup(); t.goto(x, y); t.pendown() + penup(); goto(x, y); pendown() def filled_rect(x1, y1, x2, y2, fill, outline="black"): - t.pencolor(outline) - t.fillcolor(fill) + pencolor(outline) + fillcolor(fill) move_to(x1, y1) - t.begin_fill() - t.goto(x2, y1) - t.goto(x2, y2) - t.goto(x1, y2) - t.goto(x1, y1) - t.end_fill() + begin_fill() + goto(x2, y1) + goto(x2, y2) + goto(x1, y2) + goto(x1, y1) + end_fill() -def draw_oval(cx, cy, rx, ry, tilt=0, fill=None, steps=180): +def draw_oval(cx, cy, rx, ry, tilt=0, fill=None, outline=None, steps=180, pen=None): """Parametric ellipse; steps controls smoothness.""" ang = radians(tilt) def R(x, y): # rotate (x,y) by tilt return (x*cos(ang) - y*sin(ang), x*sin(ang) + y*cos(ang)) - - t.fillcolor(fill if fill else "") + pensize(pen if pen else 3) + pencolor(outline if outline else "") + fillcolor(fill if fill else "") move_to(cx + rx, cy) # start at angle 0 if fill: - t.begin_fill() + begin_fill() for i in range(1, steps + 1): theta = 2*pi*i/steps x, y = rx*cos(theta), ry*sin(theta) xr, yr = R(x, y) - t.goto(cx + xr, cy + yr) + goto(cx + xr, cy + yr) if fill: - t.end_fill() + end_fill() def poly(points, fill=None): - if fill: t.fillcolor(fill); t.begin_fill() + if fill: fillcolor(fill); begin_fill() move_to(*points[0]) for p in points[1:]: - t.goto(*p) - t.goto(*points[0]) - if fill: t.end_fill() + goto(*p) + goto(*points[0]) + if fill: end_fill() def right_triangle(ax, ay, leg1, leg2, angle=0, fill=None): """Right angle at (ax, ay). leg1 along 'angle' degrees, leg2 perpendicular.""" @@ -69,38 +69,17 @@ def right_triangle(ax, ay, leg1, leg2, angle=0, fill=None): # ---------- Scene ---------- # Ocean (bottom half) -filled_rect(-500, -60, 500, -300, fill="#3d44c6", outline="#3d44c6") +filled_rect(-500, -100, 500, -300, fill="#3d44c6", outline="#3d44c6") # Iceberg (white with light gray outline) -t.pensize(4) +pensize(4) filled_rect(-500, -60, 120, -150, fill="white", outline="#7f7f7f") -# ---------- Penguin (line-art) ---------- -t.pensize(3) -t.pencolor("black") - -# Body (tall oval) -draw_oval(60, 10, rx=28, ry=70, tilt=0, fill="black") # outer body -# Belly (smaller inner oval) -draw_oval(78, 12, rx=12, ry=65, tilt=0,fill="white") -# Arm (middle oval) -draw_oval(63, -5, rx=13, ry=30, tilt=0, fill="black") - -# Head (circle = oval with equal radii) -draw_oval(78, 80, rx=25, ry=25, fill="black") - -# Beak (little triangle pointing right) -right_triangle(92, 60, 25, 20, fill="gold") - -# Feet (two small triangles resting on ice) -right_triangle(70, -60, 35, 15, fill="gold") - -#first penguin starts outer body(60,10) -# belly (78,12) -# arm (63,-5) -# head (78,80) -# beak (92, 60) -# feet (70, -60) +def background(): + filled_rect(-500, -100, 500, -300, fill="#3d44c6", outline="#3d44c6") + # Iceberg (white with light gray outline) + pensize(4) + filled_rect(-500, -60, 120, -150, fill="white", outline="#7f7f7f") diff --git a/penguins.py b/penguins.py index 71fc7c8..7c34c9f 100644 --- a/penguins.py +++ b/penguins.py @@ -1,24 +1,30 @@ from drawing import * from turtle import * -def penguins(ax): +def penguins(ax, armtilt, footangle): + background() for x in range (ax, -500, -100): - pendown() - # Body (tall oval) + setheading(0) + # Body draw_oval(x-60, 10, rx=28, ry=70, tilt=0, fill="black") - # Belly (smaller inner oval) - draw_oval(x-42, 12, rx=12, ry=65, tilt=0,fill="white") - # Arm (middle oval) - draw_oval(x-57, -5, rx=13, ry=30, tilt=0, fill="black") - # Head (circle = oval with equal radii) + # Belly + draw_oval(x-42, 12, rx=12, ry=65, tilt=0,fill="white", outline="darkslategray") + # Arm + draw_oval(x-65, 0, rx=10, ry=40, tilt=armtilt, fill="black", outline="darkslategray", pen= 1) + # Head draw_oval(x-42, 80, rx=25, ry=25, fill="black") - # Beak (little triangle pointing right) + # Beak right_triangle(x-28, 60, 25, 20, fill="gold") - # Feet (two small triangles resting on ice) - right_triangle(x-50, -60, 35, 15, fill="gold") - penup() + # Foot + right_triangle(x-50, -60, 35, 15, footangle, fill="gold") + - -penguins (120) +#penguin arm movement: armtilt=345 +#foot movement: footangle=35 + + + + +input()