【python实例教学】
【每天一例,九周学会python】
实例2-3: 五角星绘制
描述
使用turtle库,绘制一个红色五角星。
【参考代码】
import turtle as t #导入turtle库并命名别名t.title("画五角星") #设置画板标题t.setup(500,300) #设置画板大小t.fillcolor("red") #设置填充色t.pencolor("yellow") #设置笔的颜色t.pensize(3) #设置笔的宽度t.speed(5) #设置速度t.penup() #抬起画笔t.goto(-100,25) #移动到初始位置t.pendown() #放下画笔t.begin_fill() #开始填充for i in range(5): #循环5次(五角星由5条边画成) t.forward(200) #画线长200 t.right(144) #右转144度t.end_fill() #停止填充t.done #停留在结束界面