python

How to Draw 4-Leaf Clover Using a Turtle in Python

· John Doe

909 Views

This graphics system is a great way for beginners to conquer both Python and 2D drawing.

 

Code:

import turtle as t

def draw_leaf(color):
    t.begin_fill()
    t.color(color)
    t.left(50)
    t.forward(60)
    t.circle(25, 190)
    t.right(100)
    t.circle(25, 180)
    t.forward(50)
    t.left(50)
    t.end_fill()

def draw_stem(degree, length, color):
    t.rt(degree)
    t.pensize(5)
    t.color(color)
    t.fd(length)
    t.back(length)
    t.lt(degree)

n = 4
color = 'green'
t.setup(430, 430)
draw_stem(90, 150, color)
t.pensize(2)
for i in range(n):
    draw_leaf(color)
    t.home()
    t.lt((360 / n) * (i + 1))

t.pu()
t.mainloop()

 

Result:

 

Turtle clover