Tuesday, November 16, 2021

Draw japan flag in python turtle

 

Japan Flag
Japan Flag

Code:

# Draw japan flag in turtle
from turtle import *

bgcolor('black')
hideturtle()  # for hiding turtle icon
speed(5)  # to increasing the speed of output

height = 200  # flag height
width = 3*height/2  # flag width

x_pos = -width/2  # initial x position
y_pos = height/2  # initial y position

penup()  # turtle pointer up
colormode(255)


def draw_rect(x_pos, y_pos, height, width):
    goto(x_pos, y_pos)  # changing the position of the turtle pointer
    pendown()  # turtle pointer down
    pencolor(255, 255, 255)  # changing the pen color
    fillcolor(255, 255, 255)  # filling the color
    begin_fill()  # beginning the filling
    for i in range(2):
        forward(width) # Forward turtle by width units
        right(90) # Turn right turtle by 90 degree
        forward(height) # Forward turtle by height units
        right(90) # Turn right turtle by 90 degree
    end_fill()  # ending the filling
    penup()  # turtle pointer up
# end def


def draw_circle(height):
    radius = ((height/5)*3/2)  # circle radius
    goto(0, -radius)  # changing the position of the turtle pointer
    pendown()  # turtle pointer down
    pencolor(188, 0, 45)  # changing the pen color
    fillcolor(188, 0, 45)  # filling the color
    begin_fill()  # beginning the filling
    circle(radius)  # draw circle
    end_fill()  # ending the filling
    penup()  # turtle pointer up
# end def


draw_rect(x_pos, y_pos, height, width)
draw_circle(height)

# It will keep output to wait for the click,
# Otherwise output will be disappear.
exitonclick()

Output:

Japan Flag Output

No comments:

Post a Comment

Draw bahamas flag in python turtle

  Bahamas Flag