turtle画图代码大全简单(Python turtle海龟制图 求代码)

您所在的位置:网站首页 任务栏快捷方式怎么删除掉 turtle画图代码大全简单(Python turtle海龟制图 求代码)

turtle画图代码大全简单(Python turtle海龟制图 求代码)

2023-04-11 20:09| 来源: 网络整理| 查看: 265

本文目录Python turtle海龟制图 求代码Python绘图之(1)Turtle库详解python turtle画4个同心圆方法如何使用python中的turtle画一个苹果有大神可以用python的turtle模块画图吗,求解Python中Turtle模块的基本指令都有哪些用Python画图turtle库的入门操作怎么用python的turtle库画出这个图案,要代码如何使用pycharm中的turtle来画一个苹果,求代码Python turtle海龟制图 求代码

# coding:utf-8import turtle as t# 绘制小猪佩奇# =======================================t.pensize(4)t.hideturtle()t.colormode(255)t.color((255, 155, 192), “pink“)t.setup(840, 500)t.speed(10)# 鼻子t.pu()t.goto(-100, 100)t.pd()t.seth(-30)t.begin_fill()a = 0.4for i in range(120):if 0 《= i 《 30 or 60 《= i 《 90:a = a + 0.08t.lt(3) # 向左转3度t.fd(a) # 向前走a的步长else:a = a - 0.08t.lt(3)t.fd(a)t.end_fill()t.pu()t.seth(90)t.fd(25)t.seth(0)t.fd(10)t.pd()t.pencolor(255, 155, 192)t.seth(10)t.begin_fill()t.circle(5)t.color(160, 82, 45)t.end_fill()t.pu()t.seth(0)t.fd(20)t.pd()t.pencolor(255, 155, 192)t.seth(10)t.begin_fill()t.circle(5)t.color(160, 82, 45)t.end_fill()# 头t.color((255, 155, 192), “pink“)t.pu()t.seth(90)t.fd(41)t.seth(0)t.fd(0)t.pd()t.begin_fill()t.seth(180)t.circle(300, -30)t.circle(100, -60)t.circle(80, -100)t.circle(150, -20)t.circle(60, -95)t.seth(161)t.circle(-300, 15)t.pu()t.goto(-100, 100)t.pd()t.seth(-30)a = 0.4for i in range(60):if 0 《= i 《 30 or 60 《= i 《 90:a = a + 0.08t.lt(3) # 向左转3度t.fd(a) # 向前走a的步长else:a = a - 0.08t.lt(3)t.fd(a)t.end_fill()# 耳朵t.color((255, 155, 192), “pink“)t.pu()t.seth(90)t.fd(-7)t.seth(0)t.fd(70)t.pd()t.begin_fill()t.seth(100)t.circle(-50, 50)t.circle(-10, 120)t.circle(-50, 54)t.end_fill()t.pu()t.seth(90)t.fd(-12)t.seth(0)t.fd(30)t.pd()t.begin_fill()t.seth(100)t.circle(-50, 50)t.circle(-10, 120)t.circle(-50, 56)t.end_fill()# 眼睛t.color((255, 155, 192), “white“)t.pu()t.seth(90)t.fd(-20)t.seth(0)t.fd(-95)t.pd()t.begin_fill()t.circle(15)t.end_fill()t.color(“black“)t.pu()t.seth(90)t.fd(12)t.seth(0)t.fd(-3)t.pd()t.begin_fill()t.circle(3)t.end_fill()t.color((255, 155, 192), “white“)t.pu()t.seth(90)t.fd(-25)t.seth(0)t.fd(40)t.pd()t.begin_fill()t.circle(15)t.end_fill()t.color(“black“)t.pu()t.seth(90)t.fd(12)t.seth(0)t.fd(-3)t.pd()t.begin_fill()t.circle(3)t.end_fill()# 腮t.color((255, 155, 192))t.pu()t.seth(90)t.fd(-95)t.seth(0)t.fd(65)t.pd()t.begin_fill()t.circle(30)t.end_fill()# 嘴t.color(239, 69, 19)t.pu()t.seth(90)t.fd(15)t.seth(0)t.fd(-100)t.pd()t.seth(-80)t.circle(30, 40)t.circle(40, 80)# 身体t.color(“red“, (255, 99, 71))t.pu()t.seth(90)t.fd(-20)t.seth(0)t.fd(-78)t.pd()t.begin_fill()t.seth(-130)t.circle(100, 10)t.circle(300, 30)t.seth(0)t.fd(230)t.seth(90)t.circle(300, 30)t.circle(100, 3)t.color((255, 155, 192), (255, 100, 100))t.seth(-135)t.circle(-80, 63)t.circle(-150, 24)t.end_fill()# 手t.color((255, 155, 192))t.pu()t.seth(90)t.fd(-40)t.seth(0)t.fd(-27)t.pd()t.seth(-160)t.circle(300, 15)t.pu()t.seth(90)t.fd(15)t.seth(0)t.fd(0)t.pd()t.seth(-10)t.circle(-20, 90)t.pu()t.seth(90)t.fd(30)t.seth(0)t.fd(237)t.pd()t.seth(-20)t.circle(-300, 15)t.pu()t.seth(90)t.fd(20)t.seth(0)t.fd(0)t.pd()t.seth(-170)t.circle(20, 90)# 脚t.pensize(10)t.color((240, 128, 128))t.pu()t.seth(90)t.fd(-75)t.seth(0)t.fd(-180)t.pd()t.seth(-90)t.fd(40)t.seth(-180)t.color(“black“)t.pensize(15)t.fd(20)t.pensize(10)t.color((240, 128, 128))t.pu()t.seth(90)t.fd(40)t.seth(0)t.fd(90)t.pd()t.seth(-90)t.fd(40)t.seth(-180)t.color(“black“)t.pensize(15)t.fd(20)# 尾巴t.pensize(4)t.color((255, 155, 192))t.pu()t.seth(90)t.fd(70)t.seth(0)t.fd(95)t.pd()t.seth(0)t.circle(70, 20)t.circle(10, 330)t.circle(70, 30)t.done()

Python绘图之(1)Turtle库详解

Turtle库是Python语言中一个很流行的绘制图像的函数库,想象一个小乌龟,在一个横轴为x、纵轴为y的坐标系原点,(0,0)位置开始,它根据一组函数指令的控制,在这个平面坐标系中移动,从而在它爬行的路径上绘制了图形。

画布就是turtle为我们展开用于绘图区域,我们可以设置它的大小和初始位置。

设置画布大小

turtle.screensize(canvwidth=None, canvheight=None, bg=None),参数分别为画布的宽(单位像素), 高, 背景颜色。

如:turtle.screensize(800,600, “green“)

turtle.screensize() #返回默认大小(400, 300)

turtle.setup(width=0.5, height=0.75, startx=None, starty=None),参数:width, height: 输入宽和高为整数时, 表示像素; 为小数时, 表示占据电脑屏幕的比例,(startx, starty): 这一坐标表示矩形窗口左上角顶点的位置, 如果为空,则窗口位于屏幕中心。

如:turtle.setup(width=0.6,height=0.6)

turtle.setup(width=800,height=800, startx=100, starty=100)

2.1 画笔的状态

在画布上,默认有一个坐标原点为画布中心的坐标轴,坐标原点上有一只面朝x轴正方向小乌龟。这里我们描述小乌龟时使用了两个词语:坐标原点(位置),面朝x轴正方向(方向), turtle绘图中,就是使用位置方向描述小乌龟(画笔)的状态。

2.2 画笔的属性

画笔(画笔的属性,颜色、画线的宽度等)

1) turtle.pensize():设置画笔的宽度;

2) turtle.pencolor():没有参数传入,返回当前画笔颜色,传入参数设置画笔颜色,可以是字符串如“green“, “red“,也可以是RGB 3元组。

3) turtle.speed(speed):设置画笔移动速度,画笔绘制的速度范围整数,数字越大越快。

2.3 绘图命令

操纵海龟绘图有着许多的命令,这些命令可以划分为3种:一种为运动命令,一种为画笔控制命令,还有一种是全局控制命令。

(1) 画笔运动命令

(2) 画笔控制命令

(3) 全局控制命令

(4) 其他命令

3. 命令详解

3.1 turtle.circle(radius, extent=None, steps=None)

描述:以给定半径画圆

参数:

radius(半径):半径为正(负),表示圆心在画笔的左边(右边)画圆;

extent(弧度) (optional);

steps (optional) (做半径为radius的圆的内切正多边形,多边形边数为steps)。

举例:

circle(50) # 整圆;

circle(50,steps=3) # 三角形;

circle(120, 180) # 半圆

实例:

1、太阳花

2、五角星

3、时钟程序

python turtle画4个同心圆方法

import turtle#draw first circleturtle.penup()turtle.goto(0,-200)turtle.pendown()turtle.circle(200)#draw second circleturtle.penup()turtle.goto(0,-150)turtle.pendown()turtle.circle(150)#draw third circleturtle.penup()turtle.goto(0,-100)turtle.pendown()turtle.circle(100)#draw fourth circleturtle.penup()turtle.goto(0,-50)turtle.pendown()turtle.circle(50)

画笔的坐标默认在0,0,就以它为圆心。

因为turtle画圆的时候是从圆的底部开始画的,所以需要找到四个圆底部的坐标

比如:

第一个半径为200的圆,底部为(0,-200)

第二个半径为150的圆,底部为(0,-150)

第三个半径为100的圆,底部为(0,-100)

第四个半径为  50的圆,底部为(0,  -50)

画的时候按下面的步骤:

抬起画笔:turtle.penup()

移动到相应坐标:turtle.goto(坐标)

放下画笔:turtle.pendown()

画圆:turtle.circle(半径)

效果如下图所示:

如何使用python中的turtle画一个苹果

1、首先在电脑中打开pycharm软件,右键单击选择新建一个python file,如下图所示。

2、接下来在弹出的界面中,给python文件起一个名字,如下图所示。

3、然后点击OK之后,运用import命令导入turtle库,如下图所示。

4、接下来编写如下图所示的绘图语句,主要利用turtle进行循环绘图。

5、然后鼠标右键单击选择Run选项,如下图所示,来执行python文件。

6、最后在打开的窗口中,就可以弹出界面中线条在不断的增加,如下图所示就完成了。

有大神可以用python的turtle模块画图吗,求解

from turtle import*pensize(4)penup()fd(150)right(90)fd(200)pendown()seth(100)fd(150)seth(31)circle(130,300)seth(170)fd(80)#shouseth(85)fd(30)#qiangleft(90)#qiangfd(120)#qiangleft(90)#qiangfd(40)#qiangleft(90)#qiangfd(80)#qiangright(90)fd(45)left(90)fd(40)left(90)fd(21)penup()fd(30)pendown()seth(100)circle(20,290)seth(340)fd(90)seth(270)fd(100)penup()seth(90)fd(250)pendown()pensize(20)seth(270)fd(7)penup()seth(0)fd(100)pendown()seth(90)fd(7)penup()

Python中Turtle模块的基本指令都有哪些

1、画布(canvas)

turtle.screensize(700, 600, “green“)

turtle.screensize() #返回默认大小(400, 300)

2、画笔控制命令:

turtle.down() #移动时绘制图形,缺省时也为绘制

turtle.up() #移动时不绘制图形

turtle.pensize(width) #绘制图形时的宽度

turtle.color(colorstring) #绘制图形时的颜色

turtle.fillcolor(colorstring) #绘制图形的填充颜色

turtle.fill(Ture)

turtle.fill(false)

3、运动命令:

turtle.forward(degree) #向前移动距离degree代表距离

turtle.backward(degree) #向后移动距离degree代表距离

turtle.right(degree) #向右移动多少度,角度

turtle.left(degree) #向左移动多少度

turtle.goto(x,y) #将画笔移动到坐标为x,y的位置

turtle.stamp() #复制当前图形

turtle.speed(speed) #画笔绘制的速度范围整数

turtle.clear() 清空turtle画的笔迹

turtle.reset() 清空窗口,重置turtle状态为起始状态

turtle.undo()  撤销上一个turtle动作

turtle.isvisible() 返回当前turtle是否可见

turtle.stamp()  复制当前图形

turtle.write(’vshmily’) 写字符串’vshmily’

扩展资料:

在Python中,自定义模块有两个作用,一个是规范代码,另一个是方便其他程序使用的已经编写好的代码,从而提高开发效率。自定义模块主要分为两部分,一部分是创建模块,另一部分是导入模块。

创建模块可以将模块中相关的代码编写在一个单独的文件中,并且将该文件命名为“模块名+.py”的形式。

创建模块后,就可以在其他程序中使用该模块了,当加载模块时,可以使用import语句实现,语法格式为:import modulename

用Python画图

今天开始琢磨用Python画图,没使用之前是一脸懵的,我使用的开发环境是Pycharm,这个输出的是一行行命令,这个图画在哪里呢? 搜索之后发现,它会弹出一个对话框,然后就开始画了,比如下图第一个常用的库是Turtle,它是Python语言中一个很流行的绘制图像的函数库,这个词的意思就是乌龟,你可以想象下一个小乌龟在一个x和y轴的平面坐标系里,从原点开始根据指令控制,爬行出来就是绘制的图形了。   它最常用的指令就是旋转和移动,比如画个圆,就是绕着圆心移动;再比如上图这个怎么画呢,其实主要就两个命令: turtle.forwa

turtle库的入门操作

Turtle库是Python内置的图形化模块,属于标准库之一,位于Python安装目录的lib文件夹下,常用函数有以下几种: penup():抬起画笔 pendown():落下画笔 pensize(width):画笔宽度 pencolor(color):画笔颜色 color为颜色字符串’red’或者r,g,b值 turtle.hideturtle() #将画笔隐藏 turtle.setup(width,height,startx,trarty):设置窗体大小 turtle.goto(x,y):直接到达(x,y)位置 turtle.fd(d):朝海龟的正前方前进 turtle.forward(d) 功能类似 turtle.bk(d):朝海龟的后方前进 turtle.forward(d) 功能类似 turtle.circle(r,angle):以海龟左侧一点为圆心曲线运行 turtle.seth(angle):改变海龟的行进角度 (绝对角度) turtle.left(angle):改变海龟的行进角度(海龟的左方) turtle.right(angle):改变海龟的行进角度 (海龟的右方) turtle.tracer(False) :设置动画开关来加速绘画,不显示过程。默认为ture显示过程 p.mainloop() :在最后画图执行的命令或者p.done() 绘制雪花飘洒大地

怎么用python的turtle库画出这个图案,要代码

import turtle as t

def quad(color):

    t.begin_fill()

    t.color(color)

    t.forward(100)

    t.left(36)

    t.forward(100)

    t.left(36*4)

    t.forward(100)

    t.left(36)

    t.forward(100)

    t.end_fill()

    t.left(36*3)

for i in range(10):

    if i%2:

        quad(’#99c8de’)

    else:

        quad(’#e5b9c4’)

两三年没碰海龟了,觉得没啥用,看你赏金又提了就回去学了学

如何使用pycharm中的turtle来画一个苹果,求代码

我有小人的

import turtlep = turtlep.speed(1)p.pensize(1)p.color(’blue’)p.penup()p.pendown()p.circle(100,360)

p.penup()p.goto(-40,100)p.pendown()p.circle(20,360)p.penup()p.goto(40,100)p.pendown()p.circle(20,360)

p.penup()p.goto(30,30)p.pendown()p.goto(-30,30)

p.penup()p.goto(0,0)p.pendown()p.goto(0,-200)

p.penup()p.goto(0,0)p.pendown()p.goto(-100,-200)p.penup()p.goto(0,0)p.pendown()p.goto(100,-200)

p.penup()p.goto(0,-200)p.pendown()p.goto(-100,-300)

p.penup()p.goto(0,-200)p.pendown()p.goto(100,-300)p.done()



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3