turtle 画一朵花
2024-09-06 00:08:15
操纵海龟绘图有着许多的命令,这些命令可以划分为两种:一种为运动命令,一种为画笔控制命令
1. 运动命令:
forward(degree) #向前移动距离degree代表距离
backward(degree) #向后移动距离degree代表距离
right(degree) #向右移动多少度
left(degree) #向左移动多少度
goto(x,y) #将画笔移动到坐标为x,y的位置
stamp() #复制当前图形
speed(speed) #画笔绘制的速度范围[0,10]整数
2. 画笔控制命令:
down() #移动时绘制图形,缺省时也为绘制
up() #移动时不绘制图形
pensize(width) #绘制图形时的宽度
color(colorstring) #绘制图形时的颜色
fillcolor(colorstring) #绘制图形的填充颜色
fill(Ture)
fill(false)
lucy : 梦想照进现实;露茜;青春风采;
draw_flower1.py
import turtle
import math def p_line(t, n, length, angle):
"""Draws n line segments."""
for i in range(n):
t.fd(length)
t.lt(angle) def polygon(t, n, length):
"""Draws a polygon with n sides."""
angle = 360/n
p_line(t, n, length, angle) def arc(t, r, angle):
"""Draws an arc with the given radius and angle."""
arc_length = 2 * math.pi * r * abs(angle) / 360
n = int(arc_length / 4) + 1
step_length = arc_length / n
step_angle = float(angle) / n # Before starting reduces, making a slight left turn.
t.lt(step_angle/2)
p_line(t, n, step_length, step_angle)
t.rt(step_angle/2) def petal(t, r, angle):
"""Draws a 花瓣 using two arcs."""
for i in range(2):
arc(t, r, angle)
t.lt(180-angle) def flower(t, n, r, angle, p):
"""Draws a flower with n petals."""
for i in range(n):
petal(t, r, angle)
t.lt(p/n) def leaf(t, r, angle, p):
"""Draws a 叶子 and fill it."""
t.begin_fill() # Begin the fill process.
t.down()
flower(t, 1, 40, 80, 180)
t.end_fill() def main(): window=turtle.Screen() #creat a screen
window.bgcolor("blue")
lucy=turtle.Turtle()
lucy.shape("turtle")
lucy.color("red")
lucy.width(5)
lucy.speed(0) # Drawing flower
flower(lucy, 10, 40, 100, 360) # Drawing pedicel
lucy.color("brown")
lucy.rt(90)
lucy.fd(200) # Drawing leaf
lucy.rt(270)
lucy.color("green")
leaf(lucy, 40, 80, 180)
lucy.ht()
window.exitonclick() main()
执行结果:
最新文章
- Android开源项目分类汇总
- 创建Visual studio项目模板 vstemplate关键点纪要
- POJ 3662 Telephone Lines(二分+最短路)
- CentOS 6.4安装配置LAMP服务器(Apache+PHP5+MySQL)
- java入门第四步之应用服务器的安装(Tomcat)【转】
- oracle 启用归档日志
- CSS Margin(外边距)
- Creating Contextual Menus创建上下文菜单
- How can I create an Asynchronous function in Javascript?
- Centos7 动态创建文件系统
- BeetleX之WebSocket详解
- dsp实验一 常见问题教程
- 【HANA系列】SAP HANA XS使用Data Services查询CDS实体【一】
- 深度学习FPGA实现基础知识10(Deep Learning(深度学习)卷积神经网络(Convolutional Neural Network,CNN))
- Eclipse 真机调试检测不到手机解决方案
- eclipse中maven install提示编码GBK的不可映射字符
- Frequently Used Algo
- SPOJ1812 Longest Common Substring II
- 【SQL】- 基础知识梳理(一) - 数据库
- How to Google
热门文章
- elasticsearch7.X x-pack破解
- [MSSQL] [EntityFramework(.Net Core)] 自增长id字段,无法插入数据
- 二维DCT变换 | Python实现
- 关于hexo-blog-encrypt插件输入密码后无响应的问题
- 【MobileNet-V1】-2017-CVPR-MobileNets Efficient Convolutional Neural Networks for Mobile Vision Applications-论文阅读
- 小谢第7问:js前端如何实现大文件分片上传、上传进度、终止上传以及删除服务器文件?
- Rocket - devices - bootrom
- Mysql查询语句,select,inner/left/right join on,group by.....[例题及答案]
- Java 第十一届 蓝桥杯 省模拟赛 计算机存储中有多少字节
- 第七届蓝桥杯JavaB组国(决)赛部分真题