Drawing Pak Flag in Python...

 




Hi guys, here I am going to draw an awesome design of Pakistan Flag in Python Programming Language with the help of Turtle Library. Turtle is a graphics drawing library in python.

For this tutorial you will need turtle module. If you have already installed, so fine. Let's go for try. If not, please install the Turtle module through pip from command line (CMD) before practicing the code.


Code:


  1. import turtle
  2. import tkinter as tk
  3. turtle.title("Hamsafar Py Pak Flag Drawer")
    wn = turtle.Screen()
    wn.bgcolor("yellow")
    wn.setup(900,600)
    turtle = turtle.Turtle()
    turtle.speed(10)
    turtle.shape("turtle")
  4. def DandFrec(x, y, length, width, color):
        turtle.goto(x,y)
        turtle.pd()
        turtle.color(color)
        turtle.begin_fill()
        turtle.forward(width)
        turtle.right(90)
        turtle.forward(length)
        turtle.right(90)
        turtle.forward(width)
        turtle.right(90)
        turtle.forward(length)
        turtle.right(90)
        turtle.end_fill()
        turtle.penup()
  5. def drBodyOfStar(x,y,color,length):
        turtle.goto(x,y)
        turtle.setheading(0)
        turtle.pd()
        turtle.begin_fill()
        turtle.color(color)
        for turn in range(0,5):
            turtle.forward(length)
            turtle.right(144)
        turtle.end_fill()
        turtle.penup()
  6. def drCrcl(x,y,color,radius):
        turtle.goto(x,y)
        turtle.color(color)
        turtle.begin_fill()
        turtle.circle(radius)
        turtle.end_fill()
  7. def DrMoon (x,y,color,radius):
        turtle.up()
        turtle.goto(x,y)
        turtle.color(color)
        turtle.begin_fill()
        turtle.circle(radius)
        turtle.end_fill()
  8. def FillGreenArea():
        x = -245
        y = 140
        color = 'dark green'
        DandFrec(x, y, 295, 465, color)
  9. def FillWhiteArea():
        x = -245
        y =  140
        color = 'white'
        DandFrec(x, y, 295, 135, color)
  10. def StarShape():
            x = 90
            y = 45
            color = 'white'
            drBodyOfStar(x, y, color, 70)
  11. def CrclShape():
               x = 65
               y = -115
               color = 'white'
               drCrcl(x, y, color, 100)
  12. def MoonShape():
                x = 85
                y = -87
                color = 'dark green'
                DrMoon(x, y, color, 90)
  13. FillGreenArea()
    FillWhiteArea()
    CrclShape()
    MoonShape()
    StarShape()
  14. turtle.goto(-180,-260)
    turtle.color('green')
    turtle.write("Programmed by: Khairullah Hamsafar", move=True, font=("Berkshire Swash", 16, "normal"))
  15. turtle.goto(-170,180)
    turtle.write("Markhorism - The 50 shades of Green.", move=True, font=("Aclonica", 14, "normal"))
  16. turtle.goto(-170,220)
    turtle.write("Long Live Pakistan...!", move=True, font=("Berkshire Swash", 20, "normal"))
  17. turtle.goto(+180,280)
    turtle.write("", move=True)
  18. turtle.back(20)
    


Simply copy this code and run in any python IDLE shell or interpreter to execute.


Output:


              


Regards: Khairullah Hamsafar

Post a Comment

Previous Post Next Post