Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

(Python) Turtle Graphics To do this you should write the following functions: de

ID: 3717626 • Letter: #

Question

(Python) Turtle Graphics

To do this you should write the following functions:

def draw_U(posx, posy, color)

Draws the character U at the position (posx,posy) using a given color.

def draw_H(posx, posy, color)

Draws the character H at the position (posx,posy) using a given color.

def draw_UH(posx, posy)

Draws the characters U and H at the position (posx,posy).

def draw_Grid(posx, posy, rows, cols)

TURTLE GRAPHICS The goal is to design two programs using the Turtle graphics library. The idea is to create two visualizations using control structures and functions that facilitate your work. Problem 1: UH Logo Grid You should write a program to create a visualization similar to this one: ???? ????

Explanation / Answer

import turtle
wn = turtle.Screen()

def draw_u(posx, posy, color):
u = turtle.Turtle()
u.color(color)
u.penup()
u.setposition(posx, posy)
u.begin_fill()

u.pendown()
u.forward(40)
u.right(90)
u.forward(20)
u.right(90)
u.forward(40)
u.right(90)
u.forward(20)

u.end_fill()

u.penup()
u.back(20)
u.right(90)
u.forward(10)

u.begin_fill()

u.pendown()
u.forward(20)
u.right(90)
u.forward(80)
u.right(90)
u.forward(20)
u.right(90)
u.forward(80)

u.end_fill()

u.penup()
u.right(90)
u.forward(20)
u.right(90)
u.forward(80)
u.right(90)
u.forward(20)
u.left(140)

u.begin_fill()

u.pendown()
u.forward(30)
u.left(40)
u.forward(60)
u.left(40)
u.forward(30)
u.left(140)
u.forward(80)

u.end_fill()

u.penup()
u.back(60)
u.right(90)

u.begin_fill()

u.pendown()
u.forward(80)
u.right(90)
u.forward(20)
u.right(90)
u.forward(80)
u.right(90)
u.forward(20)

u.end_fill()

u.penup()
u.right(90)
u.forward(80)
u.left(90)

u.begin_fill()

u.pendown()
u.forward(10)
u.right(90)
u.forward(20)
u.right(90)
u.forward(40)
u.right(90)
u.forward(20)
u.right(90)
u.forward(40)

u.end_fill()

u.right(90)
u.penup()
u.setposition(posx, posy)
u.pendown()

def draw_h(posx, posy, color):
t = turtle.Turtle()
t.color(color)
t.penup()
t.setposition(posx, posy)
t.forward(50)
t.right(90)
t.forward(50)
t.right(90)
t.right(90)
t.right(90)

t.begin_fill()
t.pendown()
t.forward(40)
t.left(90)
t.forward(20)
t.left(90)
t.forward(40)
t.left(90)
t.forward(20)

t.end_fill()

t.penup()
t.left(90)
t.forward(10)

t.begin_fill()

t.pendown()
t.forward(20)
t.right(90)
t.forward(80)
t.right(90)
t.forward(20)
t.right(90)
t.forward(80)

t.end_fill()

t.penup()
t.right(90)
t.forward(20)
t.right(90)
t.forward(80)
t.right(90)
t.forward(20)

t.begin_fill()

t.pendown()
t.forward(10)
t.left(90)
t.forward(20)
t.left(90)
t.forward(40)
t.left(90)
t.forward(20)
t.left(90)
t.forward(40)

t.end_fill()

t.penup()
t.back(30)
t.right(90)
t.forward(40)

t.begin_fill()

t.pendown()
t.forward(20)
t.right(90)
t.forward(60)
t.right(90)
t.forward(20)
t.right(90)
t.forward(60)

t.end_fill()

t.penup()
t.back(60)
t.right(90)

t.begin_fill()

t.pendown()
t.forward(40)
t.right(90)
t.forward(20)
t.right(90)
t.forward(80)
t.right(90)
t.forward(20)
t.right(90)
t.forward(20)

t.end_fill()

t.penup()
t.back(20)
t.left(90)

t.begin_fill()

t.pendown()
t.forward(10)
t.left(90)
t.forward(20)
t.left(90)
t.forward(40)
t.left(90)
t.forward(20)
t.left(90)
t.forward(20)

t.end_fill()

t.penup()
t.right(90)
t.forward(80)
t.left(90)
t.forward(10)

t.begin_fill()

t.pendown()
t.forward(10)
t.right(90)
t.forward(20)
t.right(90)
t.forward(40)
t.right(90)
t.forward(20)
t.right(90)
t.forward(10)

t.end_fill()

t.right(90)
t.penup()
t.setposition(posx, posy)
t.pendown()


def draw_Grid(posx, posy, rows, cols):
t.ht()
pathwidth, pathheight = 200, 160
for i in range(cols):
x = posx + pathwidth * i
for j in range(rows):
y = posy + pathheight * j
draw_UH(x,y)

def draw_UH(posx, posy):
draw_u( posx, posy, 'black')
draw_h( posx, posy, 'black')
  

turtle.setup(800, 600)
width, height = turtle.window_width(), turtle.window_height()

t = turtle.Turtle()
t.speed(7)
t.ht()
draw_Grid(10-width//2, 250-height//2, 3, 4)

turtle.done()