目标:
使用turtle模块绘制指定图形
内容:
利用turtle模块绘制一些5个图形,并且为这些图像填充不同的颜色。
步骤:
在程序中利用turtle模块绘制图2-13所示的5个图形,为这写图形填充不同的颜色。
代码如下:
#-*-coding: utf-8-*-
####三角形
import turtle as t
t.fillcolor( "red") #设置填充颜色为红色
t.penup() #提起画笔
t.goto(-300,-50) #画笔移动到横坐标为-308,纵坐标为-50的位置
t.begin_fil1() #开始填充
t.pendown() #放下画笔
t.circle( 50,steps-3) #设置图形半径为50,步长为3
t.end_fi11() #填充结束
####四边形
t.fillcolor("bLue")
t.penup()
t.goto(-200,-50)
t.begin_fil1()
t.pendown()
t.circle(50,steps=4)
t.end_fill()
####五边形
t.fillcolor("yelLow")
t.penup()
t.goto(-100,-50)
t.begin_fil1()
t.pendown()
t.circle(50,steps=5)
t.end_fill()
####六边形
t.fillcolor("pink")
t.penup()
t.goto(0,-50)
t.begin_fil1()
t.pendown()
t.circle(50,steps=6)
t.end_fi11()
####圆形
t.fillcolor("purpLe")
t.penup()
t.goto(100,-50)
t.begin_fil1()
t.pendown()
t.circle(50)
t.end_fil1()
t.pendown()
运行结果: