《2018年5月7日》【连续209天】
标题:turtle库和海龟绘图法;
内容:
A.绘制Python的代码:
#PythonDraw.py
import turtle
turtle.setup(650,350,200,200)
turtle.penup()
turtle.fd(-250)
turtle.pendown()
turtle.pensize(25)
turtle.pencolor("purple")
turtle.seth(-40)
for i in range(4):
turtle.circle(40,80)
turtle.circle(-40,80)
turtle.circle(40,80/2)
turtle.fd(40)
turtle.circle(16,180)
turtle.fd(40 * 2/3)
turtle.done()
1.turtle库:
setup(width, height, startx, starty)
turtle空间坐标体系:分为绝对坐标和海龟坐标;
绝对坐标:goto(x, y)
海龟:
forward() 别名: fd(d)
bk(d)
circle(r, angle) #定左侧r距离的圆心,绕过angle角度,如果r为负,即为右侧;
角度坐标体系:
绝对度数:
setheading() seth(angle)
海归角度:
left(angle) lt()
right() rt()
画笔控制:
penup() 别名:pu()
pendown() 别名:pd()
pensize() 别名: width()
pencolor() #color有三种控制方式,1.颜色字符串 2.RGB小数值 //colormode(1.0) 3.RGB元组值//(255);
库引用:
import <库名>
或 from <库名> import <函数名>/*
或 import <库名> as <别名>
B.练习用turtle画了一朵花:
代码如下:
#flower.py
import turtle as t
t.setup(1500,1000,0,0)
t.pensize(5)
t.pencolor("pink")
m = 45
t.seth(m)
t.pu()
t.fd(80)
t.pd()
for i in range(8):
t.seth(m)
t.circle(40,180)
m =m + 45
t.done
效果:
本文介绍了Python中的turtle库,详细解释了如何利用该库进行基本绘图操作,并提供了一个具体的例子——绘制一朵由多个弧形组成的花朵。
814

被折叠的 条评论
为什么被折叠?



