Python Turtle 库的使用

    xiaoxiao2023-10-28  31

    Turtle 库的创意绘图

    源代码效果图展示相关库的链接简言

    1、源代码

    #!/usr/bin/env python # -*- coding:utf-8 -*- """ @Author: _Scale @File name: turtle_demo.py @Creative time: 2018/11/07 8:43 @Document description: turtle 模块实现闪烁创意循环 """ import turtle as t # 导入turtle库并别名为t提高码字效率 import random while True: t.screensize(300,300, "black") # 设置画布,可自定义背景色 t.speed(0) # 设置画笔速度,1-10,值越大速度越快,10可用0来输入 t.pensize(1) # 设置画笔粗细 t.hideturtle() # 隐藏画笔 r1, g1, b1 = random.random(), random.random(), random.random() # 用随机数库函数随机输出画笔颜色 r2, g2, b2 = random.random(), random.random(), random.random() r3, g3, b3 = random.random(), random.random(), random.random() r4, g4, b4 = random.random(), random.random(), random.random() c1 = r1, g1, b1 c2 = r2, g2, b2 c3 = r3, g3, b3 c4 = r4, g4, b4 colors = [c1, c2, c3, c4] # 可自定义色彩 for x in range(600): # for循环遍历 t.pencolor(colors[x % 4]) # 顺序使用颜色列表里的元素 t.forward(x + 1) # 画笔每次前进 x 步长,每次循环递增一个步长 t.left(91) # 每一次前进后左转91度 t.home() # 仅使画笔回到初始位置 for y in range(600): t.pencolor('black') # 设置背景色覆盖原路线,制作出消失的错觉 t.forward(y + 1) t.bgcolor('white') # 反色配布实现炫酷视觉 t.bgcolor('black') t.left(91) t.reset() # 清空窗口

    2、效果图展示

    3、相关库的链接

    链接   turtle 库的详解链接 : link(声明:此链接为转载博客仅供参考)

    4、简言

    简言   我也是第一次接触 Python 的这个用于控制命令绘图的库,觉得很有想象的空间,所以试着创意了一次,后面会不定时的更新博客。   ps:2020-07-15,更正了源码的展示。   ps:2020-07-23,感谢 My apologies 这位 C 友的建议,已使用 random 随机数库函数随机输出画笔的颜色。      感谢 ,感谢 C 友们的支持

    最新回复(0)