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.
This commit is contained in:
ilmabura
2025-09-29 20:57:37 -04:00
parent 711b8de28d
commit f41cffdf23
4 changed files with 237 additions and 2 deletions

Binary file not shown.

View File

@@ -1,7 +1,105 @@
# drawing.py # drawing.py
# ---------- # ----------
# By ____(you)___________ # By Ilma Buraira
# #
# Draws the image of penguins on an iceberg
# (Briefly describe what this program does.) # (Briefly describe what this program does.)
from turtle import * import turtle
from math import cos, sin, pi, radians
# ---------- Setup ----------
turtle.setup(1000, 600)
screen = turtle.Screen()
screen.title("Penguin on Ice (with real ovals)")
screen.bgcolor("white")
t = turtle.Turtle(visible=False)
t.speed(0)
t.pensize(3)
t.pencolor("black")
# ---------- Helpers ----------
def move_to(x, y):
t.penup(); t.goto(x, y); t.pendown()
def filled_rect(x1, y1, x2, y2, fill, outline="black"):
t.pencolor(outline)
t.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()
def draw_oval(cx, cy, rx, ry, tilt=0, fill=None, steps=180):
"""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 "")
move_to(cx + rx, cy) # start at angle 0
if fill:
t.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)
if fill:
t.end_fill()
def poly(points, fill=None):
if fill: t.fillcolor(fill); t.begin_fill()
move_to(*points[0])
for p in points[1:]:
t.goto(*p)
t.goto(*points[0])
if fill: t.end_fill()
def right_triangle(ax, ay, leg1, leg2, angle=0, fill=None):
"""Right angle at (ax, ay). leg1 along 'angle' degrees, leg2 perpendicular."""
a = radians(angle)
B = (ax + leg1*cos(a), ay + leg1*sin(a)) # along angle
C = (ax - leg2*sin(a), ay + leg2*cos(a)) # 90° to the left
poly([(ax, ay), B, C], fill=fill)
# ---------- Scene ----------
# Ocean (bottom half)
filled_rect(-500, -60, 500, -300, fill="#3d44c6", outline="#3d44c6")
# Ice block (white with light gray outline)
t.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)
input()

49
shapes.py Normal file
View File

@@ -0,0 +1,49 @@
import turtle
from math import cos, sin, pi, radians
def move_to(x, y):
t.penup(); t.goto(x, y); t.pendown()
def filled_rect(x1, y1, x2, y2, fill, outline="black"):
t.pencolor(outline)
t.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()
def draw_oval(cx, cy, rx, ry, tilt=0, fill=None, steps=180):
"""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 "")
move_to(cx + rx, cy) # start at angle 0
if fill:
t.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)
if fill:
t.end_fill()
def poly(points, fill=None):
if fill: t.fillcolor(fill); t.begin_fill()
move_to(*points[0])
for p in points[1:]:
t.goto(*p)
t.goto(*points[0])
if fill: t.end_fill()
def right_triangle(ax, ay, leg1, leg2, angle=0, fill=None):
"""Right angle at (ax, ay). leg1 along 'angle' degrees, leg2 perpendicular."""
a = radians(angle)
B = (ax + leg1*cos(a), ay + leg1*sin(a)) # along angle
C = (ax - leg2*sin(a), ay + leg2*cos(a)) # 90° to the left
poly([(ax, ay), B, C], fill=fill)

88
trial.py Normal file
View File

@@ -0,0 +1,88 @@
import turtle
# --- Setup ---
turtle.setup(800, 500)
screen = turtle.Screen()
screen.title("Penguin on Ice")
screen.bgcolor("white")
pen = turtle.Turtle()
pen.speed(8)
pen.pensize(2)
# --- Draw ocean ---
pen.penup()
pen.goto(-400, -100)
pen.pendown()
pen.fillcolor("royalblue")
pen.begin_fill()
for _ in range(2):
pen.forward(800)
pen.right(90)
pen.forward(250)
pen.right(90)
pen.end_fill()
# --- Draw ice block ---
pen.penup()
pen.goto(-400, -100)
pen.pendown()
pen.pencolor("black")
pen.fillcolor("white")
pen.begin_fill()
pen.forward(350) # top edge
pen.right(90)
pen.forward(100) # side edge
pen.right(90)
pen.forward(350)
pen.end_fill()
# --- Draw penguin body ---
pen.penup()
pen.goto(0, -100)
pen.left(90)
pen.pendown()
pen.circle(40, 180) # big oval side
pen.circle(40, 180)
# --- Draw penguin belly (smaller oval) ---
pen.penup()
pen.goto(10, -100)
pen.setheading(90)
pen.pendown()
pen.circle(20, 360)
# --- Draw head ---
pen.penup()
pen.goto(0, -20)
pen.setheading(0)
pen.pendown()
pen.circle(20)
# --- Draw beak (triangle) ---
pen.penup()
pen.goto(20, -10)
pen.pendown()
pen.setheading(0)
pen.forward(20)
pen.right(120)
pen.forward(20)
pen.right(120)
pen.forward(20)
# --- Draw feet ---
pen.penup()
pen.goto(-5, -100)
pen.pendown()
pen.setheading(-30)
pen.forward(20)
pen.penup()
pen.goto(5, -100)
pen.pendown()
pen.setheading(-150)
pen.forward(20)
# Done
pen.hideturtle()
turtle.done()