Simple Python Turtle Graphic and Code: Cut-Out 1

Published: 15 February 2025
on channel: Basic Python Turtle Art
17
0

An image created by cutting out portions of a multicolored background.

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 site at https://www.amazon.com/author/basicpy...
import turtle
import colorsys #Module call to enable use of (h, s, v) color format
t = turtle.Turtle() #Definitions and Initializations
screen = turtle.Screen()
t.speed(0) #Drawing speed for gradient background
side_half = 255 #Half of the square background's side
sign2 = 1 #Positive/negative switch in cutout function to draw mirror images
def variant_background(x, sign1, h): #Procedure to draw the gradient background
for i in range(2 * x): #Loop to draw 2 * side_half lines with slowly changing colors
c = colorsys.hsv_to_rgb(h, 1, 1) #Update of the (h, s, v) color format, with h initially equal to 0
t.color(c) #Color assignment according to current (h, s, v)
t.goto((sign1 * x, x - i)) #Turtle movement one unit downward to start of new line to be drawn
t.forward(2 * (-sign1) * x) #Turtle drawing of new line with current color specified in (h, s, v)
sign1 = -1 * sign1 #Positive/negative switch to change drawing direction of turtle
h += 1 / (2 * x) #Slight change in value of h or hue for the next line to be drawn
def cutout(x): #Procedure to draw a cutout, which is a mirror image of the other
t.begin_fill() #Start of fill procedure that makes cutout color different from background
t.forward(0.5 * x)
t.right(sign2 * 60)
t.circle(sign2 * (-1.6) * x / 2, 60) #For this line and the following: the arcs on the border of the cutout
t.circle(sign2 * 1.6 * x / 2, 60)
t.right(sign2 * 120)
t.forward(0.5 * x) #The straight line immediately before the execution of color-fill
t.end_fill() #Execution of color-fill
variant_background(side_half, -1, 0) #Python_graphic start of drawing procedure
t.speed(4) #Drawing speed for the cutouts
t.color("white") #Color assignment for cutout
for j in {(-0.8 * side_half, 0.8 * side_half), (0.8 * side_half, 0.8 * side_half)}:
t.penup() #Loop to draw 2 cutouts which are mirror images of themselves
t.goto(j) #Turtle movement to starting point of current cutout to be drawn
t.pendown()
cutout(side_half)
sign2 = -1 * sign2 #Positive/negative switch to draw the mirror image of the first cutout
t.hideturtle()
screen.exitonclick()


On this page of the site you can watch the video online Simple Python Turtle Graphic and Code: Cut-Out 1 with a duration of hours minute second in good quality, which was uploaded by the user Basic Python Turtle Art 15 February 2025, share the link with friends and acquaintances, this video has already been watched 17 times on youtube and it was liked by 0 viewers. Enjoy your viewing!