Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add a fun flower-drawing program using Turtle library #544

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
add a fun flower-drawing program using Turtle library
  • Loading branch information
madkng committed Mar 21, 2025
commit 501c7047a24fa3316100243d716a6d397109b47a
44 changes: 44 additions & 0 deletions flower.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
"""
Using Turtle library, given a flower radius
and its amount of petals, draw such flower
in the screen
"""
#!/usr/bin/env python3
from turtle import Turtle, Screen

def draw_petal(turtle:Turtle, radius:int|float):
"""
A function to draw a petal for a flower of certain radius

Args:
turtle (Turtle): The instantiated Turtle object (pen)
radius (int | float): The radius of the flower
"""
heading = turtle.heading()
turtle.begin_fill()
turtle.circle(radius, 60)
turtle.left(120)
turtle.circle(radius, 60)
turtle.color("yellow") #To set the fill color for petals
turtle.end_fill()
turtle.setheading(heading)

if __name__ == '__main__':
#To draw a sunflower
FLOWER_RADIUS = 400
AMOUNT_OF_PETALS = 35

pen = Turtle()
pen.speed(10)


for _ in range(AMOUNT_OF_PETALS):
pen.color("black") #To set the outline color for petals
draw_petal(pen, FLOWER_RADIUS)
pen.left(360 / AMOUNT_OF_PETALS)

pen.hideturtle()

SCREEN = Screen()
SCREEN.exitonclick()