python创意turtle作品和代码-艺术和代码的结合turtle+python
的结合
1.环境
pip install turtal
如果安装失败:
1.1 wget turtal的下载地址,⾃⾏解压, 按照提⽰更改, 更改完成--> pip install -e "你的下载turtle路径"。
2. 当导包turtal时,报错如下
File "/usr/lib/python3.6/turtle.py", line 107, in
import tkinter as TK
ModuleNotFoundError: No module named 'tkinter'
解决⽅案:
sudo apt-get update
sudo apt-get install tcl-dev tk-dev python3-tk
2. 参考案例--(资源收集于⽹络)
2.0 多边形(⼏⾏代码实现)
私人网站建设import turtle
t = turtle.Pen()
for x in range(360):
t.forward(x)
t.left(59)
2.1 花
import turtle
# 设置初始位置
turtle.penup()
turtle.left(90)
turtle.fd(200)
turtle.pendown()
textbox显示提示文字
turtle.right(90)
# 花蕊
turtle.fillcolor("red")
turtle.begin_fill()
turtle.left(50)
turtle.circle(60, 45) turtle.circle(20, 170) turtle.right(24) turtle.fd(30)
turtle.left(10)
turtle.circle(30, 110) turtle.fd(20)
turtle.left(40)
turtle.circle(90, 70) turtle.circle(30, 150) turtle.right(30) turtle.fd(15)
turtle.circle(80, 90) turtle.left(15)
turtle.fd(45)
turtle.right(165) turtle.fd(20)
turtle.left(155) turtle.circle(150, 80) turtle.left(50)
turtle.circle(150, 90) d_fill()
# 花瓣1
turtle.left(150) turtle.circle(-90, 70) turtle.left(20)
turtle.circle(75, 105) turtle.setheading(60) turtle.circle(80, 98) turtle.circle(-90, 40) # 花瓣2
turtle.circle(-80, 98) turtle.setheading(-83) # 叶⼦1
turtle.fd(30)
turtle.left(90)
turtle.fd(25)
turtle.left(45)
turtle.fillcolor("green") turtle.begin_fill() turtle.circle(-80, 90) turtle.right(90) turtle.circle(-80, 90) d_fill()
turtle.right(135) turtle.fd(60)
turtle.left(180) turtle.fd(85)
turtle.left(90)
turtle.fd(80)
# 叶⼦2
turtle.right(90) turtle.right(45) turtle.fillcolor("green") turtle.begin_fill() turtle.circle(80, 90) turtle.left(90)
turtle.circle(80, 90) d_fill()
turtle.left(135) turtle.fd(60)
turtle.left(180) turtle.fd(60)
2.2 机器猫
import turtle
def flyTo(x, y):
turtle.penup()
<(x, y)
turtle.pendown()
def drawEye():
a = 2.5
for i in range(120):
if 0 <= i < 30 or 60 <= i < 90: a -= 0.05
else:
a += 0.05
turtle.left(3)
turtle.fd(a)
python代码画图案
def beard():米哈游脑机接口测试
""" 画胡⼦, ⼀共六根
"""
# 左边第⼀根胡⼦
flyTo(-37, 135)
turtle.seth(165)
turtle.fd(60)数据库在哪里
# 左边第⼆根胡⼦
flyTo(-37, 125)
turtle.seth(180)
turtle.fd(60)
# 左边第三根胡⼦
flyTo(-37, 115)
turtle.seth(193)
turtle.fd(60)伦勃朗自画像早中晚期图片
turtle.seth(15)
turtle.fd(60)
# 右边第⼆根胡⼦
flyTo(37, 125)
turtle.seth(0)
turtle.fd(60)
# 右边第三根胡⼦
flyTo(37, 115)
turtle.seth(-13)
turtle.fd(60)
def drawRedScarf():
""" 画围⼱
"""
turtle.fillcolor("red") # 填充颜⾊turtle.begin_fill()
turtle.seth(0) # 朝向右
turtle.fd(200) # 前进10个单位turtle.circle(-5, 90)
turtle.fd(10)
turtle.circle(-5, 90)
turtle.fd(207)
turtle.circle(-5, 90)
turtle.fd(10)
turtle.circle(-5, 90)
def drawMouse():
flyTo(5, 148)
turtle.seth(270)
turtle.fd(100)
turtle.seth(0)
turtle.circle(120, 50)
turtle.seth(230)

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。