A stylized drawing of a simple window with gradient-colored frame. The Python Turtle code was made less complicated and shorter by drawing the window panes as color-filled squares in the end. The Python code in this case allows the user to change the window dimensions and colors.
Feel free to copy the basic Python Turtle code that is given below. Don't hesitate to ask questions about the code if you have any. Enjoy! Please comment, like, or subscribe :)
Incidentally, for manually colorable graphics and variations, please visit my author url at https://www.amazon.com/author/basicpy...
import turtle
t = turtle.Turtle() #Definitions and Initializations
screen = turtle.Screen()
t.pensize(4)
screen.colormode(1.0) #Requirement for use of numbers 0 to 1.0 as red, green, and blue values
graphic_height = 500 #Changeable; distance from top to bottom of drawn object
graphic_length = 600 #Changeable; distance from left to right of drawn object
change_in_y = 3 #Changeable to 2 or 1; hop distance from one horizontal line to another
horizontal_lines = graphic_height // change_in_y #Integral number of horizontal lines that create the window frame
r1 = 1 #Values of r, g, and b in the initial color; (1, 0, 0) in this case is red
g1 = 0
b1 = 0
r2 = 1 #Values of r, g, and b in the final color; (1, 1, 0) in this case is yellow
g2 = 1 #Note: Changeable (r1, g1, b1) and (r2, g2, b2) to desired colors
b2 = 0
change_in_r = (r2 - r1) / graphic_height #Increases or decreases in values of r, g, and b, respectively
change_in_g = (g2 - g1) / graphic_height
change_in_b = (b2 - b1) / graphic_height
def colored_frame(): #Procedure for drawing the window frame with gradient colors given above
r = 1 #Initialization of variables r, g, b according to initial color (r1, g1, b1)
g = 0
b = 0
sign = 1 #Variable for +1 and -1 to move turtle L to R or R to L, respectively
for i in range(horizontal_lines): #Loop to draw the calculated number of horizontal lines
t.pencolor(r, g, b) #changer of pen color as turtle draws one horizontal line after another
t.forward(sign * graphic_length) #Drawing of colored horizontal line L to R or R to L according to sign
t.goto(sign * graphic_length / 2, graphic_height / 2 - change_in_y * i) #Hop of turtle to start of next horizontal
r += change_in_y * change_in_r #Changes in values of r, g, and b for the next horizontal line
g += change_in_y * change_in_g #according to calculated change_in_y and change_in_r (or _g or _b)
b += change_in_y * change_in_b
sign = -1 * sign #Change in algebraic sign to dictate the movement of turtle L to R or R to L
def pane(): #Procedure for drawing a window pane
t.forward(graphic_height / 6.5)
t.right(45)
t.pendown()
t.fillcolor("white") #Start of color-filling procedure
t.begin_fill()
for i in range(4): #Loop to draw the 4 sides of a window pane
t.forward(graphic_height / 3)
t.left(90)
t.end_fill()
t.penup() #Python_graphic start of drawing procedure
t.goto(-graphic_length / 2, graphic_height / 2) #Trail-less movement of turtle to starting point of frame drawing
t.pendown()
colored_frame() #Function call to draw the window frame with gradient colors
for j in range(4): #Loop to draw the 4 window panes
t.penup()
t.goto(0, 0)
t.setheading(45 + j * 90)
pane() #Function call to draw a pane
t.hideturtle()
screen.exitonclick()