Blog
Square-in-Square Design using Python's Turtle
- Akhila27
- January 4, 2021
- 11:09 am
- One Comment
A code to draw a square-in-square design using the Turtle programming in Python
Welcome to the code! Here’s a simple code for drawing a beautiful square-in-square design using Turtle programming.
In this code, we used a turtle named “s” to draw the square-in-square design
“turtle.begin_fill()” is called just before drawing a shape to be filled. “turtle.end_fill()” is used to fill the shape drawn after the last call to begin_fill().
“turtle.fillcolor(*args)” return or sets the fillcolor.
Four input formats are allowed:
- fillcolor()
Return the current fillcolor as color specification string, possibly in tuple format (see example). May be used as input to another color/pencolor/fillcolor call. - fillcolor(colorstring)
Set fillcolor to colorstring, which is a Tk color specification string, such as “red”, “yellow”, or “#33cc8c”. - fillcolor((r, g, b))
Set fillcolor to the RGB color represented by the tuple of r, g, and b. Each of r, g, and b must be in the range 0..colormode, where colormode is either 1.0 or 255 (see colormode()). - fillcolor(r, g, b)
Set fillcolor to the RGB color represented by r, g, and b. Each of r, g, and b must be in the range 0..colormode.
If the turtle shape is a polygon, the interior of that polygon is drawn with the newly set fillcolor.
Note: Loved the post? You too can publish your article on “Python for fun” which will be loved by millions. Contribute an article!
import turtle
wn = turtle.Screen()
wn.setup(400,600)
wn.bgcolor(“white”)
s = turtle.Turtle()
for i in range(4):
s.begin_fill()
s.forward(100)
s.left(90)
s.pencolor(“red”)
s.forward(100)
s.fillcolor(“red”)
s.end_fill()
for i in range(4):
s.begin_fill()
s.forward(80)
s.left(90)
s.pencolor(“green”)
s.forward(80)
s.fillcolor(“green”)
s.end_fill()
for i in range(4):
s.begin_fill()
s.forward(60)
s.left(90)
s.pencolor(“yellow”)
s.forward(60)
s.fillcolor(“yellow”)
s.end_fill()
for i in range(4):
s.begin_fill()
s.forward(40)
s.left(90)
s.pencolor(‘brown’)
s.forward(40)
s.fillcolor(“brown”)
s.end_fill()
for i in range(4):
s.begin_fill()
s.forward(20)
s.left(90)
s.pencolor(“black”)
s.forward(20)
s.fillcolor(“black”)
s.end_fill()
turtle.done()