diff --git a/__pycache__/drawing.cpython-312.pyc b/__pycache__/drawing.cpython-312.pyc index e4df4f2..33993ce 100644 Binary files a/__pycache__/drawing.cpython-312.pyc and b/__pycache__/drawing.cpython-312.pyc differ diff --git a/__pycache__/penguins.cpython-312.pyc b/__pycache__/penguins.cpython-312.pyc new file mode 100644 index 0000000..38b1c6d Binary files /dev/null and b/__pycache__/penguins.cpython-312.pyc differ 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()