Answer the question
In order to leave comments, you need to log in
How to draw with turtle using def functions?
Usually, to draw a hexagon, I would write like this:
sides = 6
import turtle
win = turtle.Screen()
table = turtle.Turtle()
win.setup(600,600)
table.pencolor("black")
table.begin_fill()
table.circle(100, 360, sides)
table.fillcolor("grern")
table.end_fill()
win.exitonclick()
def table (sides, length, x, y): #length это длина пикселя каждой стороны, x and y это точки, где turtle начнёт рисовать
for i in range(6):
table.forward(100)
table.left(60)
Answer the question
In order to leave comments, you need to log in
import turtle
def draw_n(n, length, x = 0,y = 0):
turtle.penup()
turtle.setpos(x,y)
turtle.pendown()
deg = 180 - 180*(n-2)/n
print(deg)
for i in range(n):
turtle.left(deg)
turtle.forward(length)
win = turtle.Screen()
table = turtle.Turtle()
win.setup(600,600)
table.pencolor("black")
draw_n(8,100,100,100)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question