首页 > 编程语言 >实验6 turtle绘图与python库应用编程体验

实验6 turtle绘图与python库应用编程体验

时间:2023-06-06 23:35:08浏览次数:42  
标签:turtle moveto python range 绘图 import main def

实验任务1

task1_.py

实验源码:

from turtle import *
def move(x, y):
    penup()
    goto(x, y)
    pendown()
def draw(n, size = 100):
    for i in range(n):
        fd(size)
        left(360/n)
def main():
    pensize(2)
    pencolor('red')
    move(-200, 0)
    draw(3)
    move(0, 0)
    draw(4)
    move(200, 0)
    draw(5)
    hideturtle()
    done()
main()

运行测试截图:

 task1_2.py

实验源码:

from turtle import *
def moveto(x, y):
    penup()
    goto(x, y)
    pendown()
def main():
    pensize(2)
    pencolor('blue')
    moveto(-150, 0)
    circle(50)
    moveto(0, 0)
    circle(50, steps = 4)
    moveto(150, 0)
    circle(50, steps = 5)
    moveto(300, 0)
    circle(50, steps = 6)
    hideturtle()
    done()
main()

运行测试截图:

实验任务2

task2_1.py

实验源码:

from turtle import *
def moveto(x, y):
    penup()
    goto(x, y)
    pendown()
def main():
    setup(800, 600)
    radius = 20
    offset = 20
    for i in range(9):
        moveto(0, -radius)
        circle(radius)
        radius += offset
    hideturtle()
    done()
main()

运行测试截图:

 task2_2.py

实验源码:

from turtle import *
from random import random
def moveto(x, y):
    penup()
    goto(x, y)
    pendown()
def gen_color():
    return tuple((random() for i in range(3)))
def main():
    setup(800, 600)
    radius = 180
    offset = 20
    for i in range(8):
        moveto(0, -radius)
        color(gen_color())
        begin_fill()
        circle(radius)
        end_fill()
        radius -= offset
    hideturtle()
    done()
main()

运行测试截图:

实验任务3

task3_1.py

实验源码:

运行测试截图:

from turtle import *
def square(size = 50, rgb = 'orange'):
    pencolor(rgb)
    for i in range(4):
        fd(size)
        left(90)
def main():
    setup(800, 600)
    speed(0)
    n = 10
    for i in range(n):
        square(80)
        left(360/n)
    hideturtle()
    done()
main()

task3_2.py

实验源码:

from turtle import *
setup(800, 600)
pencolor('pink')
n = 10
for i in range(10):
    for j in range(2):
        circle(80, 90)
        left(90)
    right(360/n)
hideturtle()
done()

运行测试截图:

实验任务4

task4.py

实验源码:

from turtle import *
setup(800, 600)
bgcolor('black')
pencolor('white')
speed(0)
angle = 0
size = 2
n = 5
count = 50
for i in range(count):
    fd(size)
    angle += 360/n
    seth(angle)
    size += 5
hideturtle()
done()

运行测试截图:

实验任务5

task5_1.py

实验源码:

from turtle import *
def start(x,y):
    penup()
    goto(x,y)
    pendown()
def main(c,n,l):
    color(c)
    begin_fill()
    for i in range(n):
        fd(l)
        left(360/n)
    end_fill()
start(-100,-100)
main('black',4,200)
start(-100,0)
right(45)
main('red',4,100*2**(1/2))
hideturtle()
done()

运行测试截图:

 task5_2.py

实验源码:

from turtle import *
color('blue')
r = 20
for i in range(5):
    r += 20
    forward(r)
    left(90)
    circle(r,90)
    left(90)
    forward(r)
    left(90)
    forward(40)
    goto(0,0)
hideturtle()
done()

运行测试截图:

实验任务6

task6.py

实验源码:

from turtle import *
def moveto(x,y):
    penup()
    goto(x,y)
    pendown()
bgcolor('black')
moveto(200,-200)
color('yellow')
begin_fill()
left(135)
fd(200)
right(90)
fd(200)
left(90)
circle(200,270)
end_fill()
moveto(80,70)
dot(40,'black')
moveto(72,76)
dot(10,'white')
hideturtle()
done()

运行测试截图:

 

标签:turtle,moveto,python,range,绘图,import,main,def
From: https://www.cnblogs.com/sxy59e/p/17461924.html

相关文章

  • 【如何入门Python】
    (文章目录)人生苦短,我用Python。欢迎大家一起分享,你是如何入门Python的~方向一:你是如何学习/自学Python的?学习/自学Python的步骤如下:了解Python的基础知识:了解Python的语法、变量、数据类型、算术操作、流程控制语句、函数、模块和包等基础知识。学习Python的核......
  • Python程序与设计
    2-27在命令行窗口中启动的Python解释器中实现在Python自带的IDLE中实现print("Helloworld")编码规范每个import语句只导入一个模块,尽量避免一次导入多个模块不要在行尾添加分号“:”,也不要用分号将两条命令放在同一行建议每行不超过80个字符使用必要的空行可以增加代码的可读性运算......
  • Python爬虫————泉州二手房数据爬取和数据可视化
    1.选题的背景我本次的主题是泉州二手房房价的调查分析。首先通过爬虫采集链家网上所有二手房的房源数据,并对采集到的数据进行清洗;然后,对清洗后的数据进行可视化分析,探索隐藏在大量数据背后的规律;将这些房源大致分类,以对所有数据的概括总结。通过上述分析,我们可以了解到目前市面......
  • Python-变量交换
    前戏Python3的变量交换功能使得我们能够轻松交换两个变量的值,无需借助额外的临时变量。这种交换可以通过多重赋值语法实现,即将变量的值同时赋给另一个变量,从而实现值的交换。例如,以下代码展示了一个简单的变量交换示例:a=10b=20#交换变量的值a,b=b,aprint(a)#输......
  • Python爬虫--爬取当当网关于python的书籍
    (一)选题背景因为现如今的科技越来越发达,人们对于信息的获取道路变得更加宽广了,在以前的话,人们会受到空间,时间,科技等问题的阻碍,对于大部分知识只有在书籍当中才能够找到。不过随着现如今科技的进步,信息的载体也会变得越来越多,信息的传播方式也变得多种多样,电子书就可以通过图像......
  • python函数的位置参数和关键字参数
    基本类型:(1)位置参数(positional): 传参时不带"变量名=",顺序不可变, 需要按照函数定义时参数的顺序进行传参.(2)关键字参数(keyword):使用key=value形式传参, 传参时前面加上"变量名=",顺序可变,可以不按照函数定时参数的顺序进行传参.(3)可变位置参数(*args):......
  • python-日记模块模板
    1"""2logging配置3"""45#定义三种日志输出格式开始6standard_format='[%(asctime)s][%(threadName)s:%(thread)d][task_id:%(name)s][%(filename)s:%(lineno)d]'\7'[%(levelname)s][%(message)s]......
  • 实验6 turtle绘图与python库应用编程体验
    实验任务1task1_1fromturtleimport*defmoveto(x,y):'''画笔移动到坐标(x,y)处'''penup()goto(x,y)pendown()defdraw(n,size=100):'''绘制边长为size的正n边形'''for......
  • python笔记
    python官方文档6.6的代码:frommaiximportcamera,mjpg,displayimportsocket#host_name='192.168.4.1'shuzu=bytearray(57600)#bytes是不能被修改的#s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)#地址簇:AF_INET(IPv4)类型:SOCK_STREAM(使用TCP传输控......
  • python opencv GaussianBlur
    pythonopencvGaussianBlur importcv2#Loadtheimageimg=cv2.imread('20230222100736979.jpg')#ApplyaGaussianblurwithakernelsizeof5x5blur=cv2.GaussianBlur(img,(5,5),0)#Displaytheoriginalandblurredimagessidebysi......