这是一个简单的Python教程,之前在红客(http://www.cnhonkerarmy.com/forum.php)发过,链接:http://www.cnhonkerarmy.com/forum.php?mod=viewthread&tid=251321&fromuid=1254105
解析:
import turtle —— 这个我就不多说了哈
·背景:
turtle.setup(600,400,0,0) —— 画布大小
turtle.bgcolor("red") —— 画布颜色
·主星:
turtle.fillcolor("yellow") —— 绘制图形的填充颜色(以下的都是)
turtle.color('yellow') —— 设置画笔的颜色(以下的都是)
turtle.speed(10) —— 这个是设定画笔的速度(以下的都是)
·第一颗星:
turtle.begin_fill() —— 准备开始填充图形(以下的都是)
turtle.up()
turtle.goto(-280,100) —— 设置画的位置(以下的都是)
turtle.down()
for i in range (5): —— 把5依次赋值给i(以下的都是)
turtle.forward(150) —— 向当前画笔方向移动150像素长度(以下的都是)
turtle.right(144) —— 顺时针移动144°(以下的都是)
turtle.end_fill() —— 填充完成(以下的都是)
·第二颗星:
turtle.begin_fill()
turtle.up()
turtle.goto(-100,180)
turtle.setheading(305)
turtle.down()
for i in range (5):
turtle.forward(50)
turtle.left(144)
turtle.end_fill()
·第三颗星:
turtle.begin_fill()
turtle.up()
turtle.goto(-50,110)
turtle.setheading(30)
turtle.down()
for i in range (5):
turtle.forward(50)
turtle.right(144)
turtle.end_fill()
·第四颗星:
turtle.begin_fill()
turtle.up()
turtle.goto(-40,50)
turtle.setheading(5)
turtle.down()
for i in range (5):
turtle.forward(50)
turtle.right(144)
turtle.end_fill()
·最后再设定一下画笔:
turtle.begin_fill()
turtle.up()
turtle.goto(-100,10)
turtle.setheading(300)
turtle.down()
for i in range (5):
turtle.forward(50)
turtle.left(144)
turtle.end_fill()
turtle.done()
源码:
[Python] 纯文本查看 复制代码 import turtle
turtle.setup(600,400,0,0)
turtle.bgcolor("red")
turtle.fillcolor("yellow")
turtle.color('yellow')
turtle.speed(10)
turtle.begin_fill()
turtle.up()
turtle.goto(-280,100)
turtle.down()
for i in range (5):
turtle.forward(150)
turtle.right(144)
turtle.end_fill()
turtle.begin_fill()
turtle.up()
turtle.goto(-100,180)
turtle.setheading(305)
turtle.down()
for i in range (5):
turtle.forward(50)
turtle.left(144)
turtle.end_fill()
turtle.begin_fill()
turtle.up()
turtle.goto(-50,110)
turtle.setheading(30)
turtle.down()
for i in range (5):
turtle.forward(50)
turtle.right(144)
turtle.end_fill()
turtle.begin_fill()
turtle.up()
turtle.goto(-40,50)
turtle.setheading(5)
turtle.down()
for i in range (5):
turtle.forward(50)
turtle.right(144)
turtle.end_fill()
turtle.begin_fill()
turtle.up()
turtle.goto(-100,10)
turtle.setheading(300)
turtle.down()
for i in range (5):
turtle.forward(50)
turtle.left(144)
turtle.end_fill()
turtle.done()
效果:
|