Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

程式與生活期中- python_turtle 繪圖

410714033 林子為
1.六角形
程式碼:
import turtle as t

t.screensize(600,400)
t.showturtle()
t.shape("turtle")
t.speed('slow')
t.bgcolor('white')

t.penup()

t.goto(0,30)
t.pendown()
t.setheading(0)
t.pensize(1)
t.color('orange')
#t.begin_fill()
t.left(30)
for i in range(6):
t.forward(60)
t.left(60)
#t.end_fill()
t.penup()

t.exitonclick()
t.mainloop()
執行結果:
2.五個圓圈
程式碼:
方法一
import turtle as t

t.screensize(600,400)
t.showturtle()
t.shape("turtle")
t.bgcolor('white')

t.penup()

t.goto(0,30)
t.pendown()
t.setheading(0)
t.pensize(1)
t.color('black')
#t.begin_fill()
t.setheading(360/5*0)
t.circle(100)
t.setheading(360/5*1)
t.circle(100)
t.setheading(360/5*2)
t.circle(100)
t.setheading(360/5*3)
t.circle(100)
t.setheading(360/5*4)
t.circle(100)
#t.end_fill()
t.penup()

t.exitonclick()
t.mainloop()
方法二
import turtle as t

t.screensize(600,400)
t.showturtle()
t.shape("turtle")
t.bgcolor('white')

t.penup()

t.goto(0,30)
t.pendown()
t.setheading(0)
t.pensize(1)
t.color('black')
#t.begin_fill()
for i in range(5):
t.setheading(360/5*i)
t.circle(100)
#t.end_fill()
t.penup()

t.exitonclick()
t.mainloop()
執行結果:

3.五角星
程式碼:
import turtle as t

t.screensize(600,400)
t.showturtle()
t.shape("turtle")
t.bgcolor('white')

t.penup()
t.goto(0,30)
t.pendown()
t.setheading(0)
t.pensize(1)
t.color('black')
#t.begin_fill()
for i in range(5):
t.forward(200)
t.left(180-(180/5))

#t.end_fill()
t.penup()

t.exitonclick()
t.mainloop()
執行結果:

You might also like