python_海龟绘图_坐标系问题_画笔各种方法-python工作笔记013

Python011

python_海龟绘图_坐标系问题_画笔各种方法-python工作笔记013,第1张

然后我们继续看,这次我们用海龟绘图,程序包,去画画,

看看海龟绘图都有哪些方法

可以看到,先导入import turtle 海龟绘图

然后turtle.showturtle() 会显示一个箭头

turtle.write("hello world") 会显示对应文字

然后turtle.forward(300),会向前走300像素

然后看看海龟绘图的,坐标体系

然后turtle.color("red"),把画笔颜色换成红色

然后turtle.left(90)把箭头,逆时针转90度

然后turtle.forward(300) 向前移动300个像素

然后turtle.goto(0,50) 走到0,50这个坐标点去

再看一下坐标系,原点0,0开始操作

还有上面这些操作,我们也试一试

turtle.goto(0,0)是回到原点

turtle.penup()是抬起画笔

然后turtle.goto(0,300),turtle.goto(0,0) 然后再去,turtle.pendown()放下画笔

然后再去turtle.goto(0,50) turtle.goto(50,50)走到对应的坐标去

然后再去turtle.circle(100),以100为半径,逆时针画一个圆

可以看到,半径是100对吧

import turtle就引入海龟作图模块。运行这个模块,就可以作图。

#旋转的正方形

import turtle

import random

t=turtle.Turtle()

t.speed(0)

a=200

n=4

k=360/n

for i in range(90):

####t.pencolor(random.random(),random.random(),random.random())

####t.rt(1)

####for j in range(n):

########t.forward(a)

########t.right(360/n)

t.done()

a=input()

把#替换为空格就可以运行。

请想象绘图区有一只机器海龟,起始位置在 x-y 平面的 (0, 0) 点。先执行 import turtle,再执行 turtle.forward(15),它将(在屏幕上)朝所面对的 x 轴正方向前进 15 像素,随着它的移动画出一条线段。再执行 turtle.right(25),它将原地右转 25 度。

Turtle star

使用海龟绘图可以编写重复执行简单动作的程序画出精细复杂的形状。

from turtle import *

color('red', 'yellow')

begin_fill()

while True:

forward(200)

left(170)

if abs(pos()) <1:

break

end_fill()

done()

通过组合使用此类命令,可以轻松地绘制出精美的形状和图案。