Home > Problem, Projects/Experiments, Python > Python Project

Python Project




Python: Draw Flower

Drawing with Python

In a previous post, we use the t.forward(size) & t.left(x) to draw something looks-like flower petal. That post (See it Here) is drawing (8) petals facing left side to complete a flower shape… So can we improve it? Can we make it looks better?..

OK, I work on it and divide the code into two functions, one will draw a petal facing left side and another to draw a petal facing right side, each petals will be close to each other and touching or almost touching each’s head. Bellow I am posting the codes, and an image for the result.

You can play with the code and change the numbers, size and rotation degree and let’s see what we will have.



#To draw a flower using turtel and circle function
import turtle
# Here is some setting for the turtel
t = turtle.Turtle()
t.color(‘black’)
t.hideturtle()
t.speed(9)
t.left(0)
t.penup
size=10

#Draw petal facing left side
def petal_l():

t.pendown()

for x in range (40):

t.forward(size)

t.left(x)

t.penup()

#Draw petal facing right side
def petal_r():

t.pendown()

for x in range (40):

t.forward(size)

t.right(x)

t.penup()

left_d=-15

# To draw 5 petals
for pet in range (5):

petal_l ()

t.goto(0,0)

t.left(50)

petal_r ()

t.goto(0,0)

t.left(22)
t.penup



Follow me on Twitter..

The Code: The Result
Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s