Day 27 - Bar Chart Using Turtle and Nested Functions, Part 1

This is part one of two - We will be making a bar chart using Python's Turtle module and custom functions.

Finished Code

from turtle import *

intSpace = 20

scr = Screen()
print(window_width()/2, window_height()/2)


teleport(-300,-300)


def drawBar(intHeight, intWidth, strColor):
    setheading(90)
    tupStart = (xcor(),ycor())
    color(strColor)
    begin_fill()
    forward(intHeight)
    right(90)
    forward(intWidth)
    right(90)
    forward(intHeight)
    right(90)
    forward(intWidth)
    right(90)
    end_fill()
    teleport(xcor()+(intWidth//2),ycor()-20)
    write(intHeight, align='center', font=('Arial',12,'bold'))
    teleport(tupStart[0]+intWidth+intSpace,tupStart[1])

drawBar(200,20,"red")
drawBar(300,20,"blue")


done()