教你使用python画一朵花送女朋友
作者:Ly_ox 发布时间:2023-01-04 21:12:26
标签:python,画花
本文实例为大家分享了用python画一朵花的具体代码,供大家参考,具体内容如下
第一种,画法
from turtle import *
import time
setup(600,800,0,0)
speed(0)
penup()
seth(90)
fd(340)
seth(0)
pendown()
speed(5)
begin_fill()
fillcolor('red')
circle(50,30)
for i in range(10):
fd(1)
left(10)
circle(40,40)
for i in range(6):
fd(1)
left(3)
circle(80,40)
for i in range(20):
fd(0.5)
left(5)
circle(80,45)
for i in range(10):
fd(2)
left(1)
circle(80,25)
for i in range(20):
fd(1)
left(4)
circle(50,50)
time.sleep(0.1)
circle(120,55)
speed(0)
seth(-90)
fd(70)
right(150)
fd(20)
left(140)
circle(140,90)
left(30)
circle(160,100)
left(130)
fd(25)
penup()
right(150)
circle(40,80)
pendown()
left(115)
fd(60)
penup()
left(180)
fd(60)
pendown()
end_fill()
right(120)
circle(-50,50)
circle(-20,90)
speed(1)
fd(75)
speed(0)
circle(90,110)
penup()
left(162)
fd(185)
left(170)
pendown()
circle(200,10)
circle(100,40)
circle(-52,115)
left(20)
circle(100,20)
circle(300,20)
speed(1)
fd(250)
penup()
speed(0)
left(180)
fd(250)
circle(-300,7)
right(80)
circle(200,5)
pendown()
left(60)
begin_fill()
fillcolor('green')
circle(-80,100)
right(90)
fd(10)
left(20)
circle(-63,127)
end_fill()
penup()
left(50)
fd(20)
left(180)
pendown()
circle(200,25)
penup()
right(150)
fd(180)
right(40)
pendown()
begin_fill()
fillcolor('green')
circle(-100,80)
right(150)
fd(10)
left(60)
circle(-80,98)
end_fill()
penup()
left(60)
fd(13)
left(180)
pendown()
speed(1)
circle(-200,23)
exitonclick()
第二种,画法
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, r, angle, p)
t.end_fill()
def main():
window = turtle.Screen() # creat a screen
window.bgcolor("white")
window.title("draw a flower")
lucy = turtle.Turtle()
lucy.shape("turtle")
lucy.color("red")
lucy.width(3)
# lucy.speed(10)
# Drawing flower
flower(lucy, 7, 60, 100, 360)
# Drawing pedicel
lucy.color("brown")
lucy.rt(90)
lucy.fd(200)
# Drawing leaf 1
lucy.width(1)
lucy.rt(270)
lucy.color("green")
leaf(lucy, 40, 80, 180)
lucy.rt(140)
lucy.color("black")
lucy.fd(30)
lucy.lt(180)
lucy.fd(30)
# Drawing leaf 2
lucy.rt(120)
lucy.color("green")
leaf(lucy, 40, 80, 180)
lucy.color("black")
lucy.rt(140)
lucy.fd(30)
lucy.ht() # hideturtle
window.exitonclick()
main()
更多精彩书单,请点击python编程必备书单
领取干货:零基础入门学习python视频教程
来源:https://www.cnblogs.com/lyox/p/8668167.html
0
投稿
猜你喜欢
- 99bill: 1.md5.asp 代码如下:<% '''''''&
- 本文实例讲述了Python实现的简单计算器功能。分享给大家供大家参考,具体如下:使用python编写一款简易的计算器计算器效果图首先搭建计算
- 1、基本用法# coding:utf-8import tkinter as tk# 创建窗口对象window = tk.Tk()# 设置串口
- 一、写在前面本文基于64位windows系统(鼠标右键点击桌面“此电脑”图标——属性可查看电脑系统版本)、python3.x(pycharm
- 1 Tenacity描述今天 给大家介绍一个Python 重试库,Tenacity 这个库 是我 这些年 使用的一个非常好的库,几乎满足了我
- python解释器默认编码(python2与python3的区别一)python2 解释器默认编码:asciipython3 解释器默认编码
- 作用:用ASP程序将页面中的电话号码生成图片格式。以下是引用片段:<% Call Com_CreatValidCode(Request
- 1 Series线性的数据结构, series是一个一维数组Pandas 会默然用0到n-1来作为series的index, 但也可以自己指
- 用django开发,经常要处理用户上传的文件, 比如user模型里面如果又个人头像的字段 ImageField等等,而django在Fiel
- UDP 套接字是可以使用 connect 系统调用连接到指定的地址的。从此以后,这个套接字只会接收来自这个地址的数据,而且可以使用 send
- 1、psutil是一个跨平台库(https://github.com/giampaolo/psutil)能够实现获取系统运行的进程和系统利用
- AICodeHelper是一款AI编程助手,旨在帮助程序员提高他们的编码技能。简单的像尝试的代码直接问就行,但是一些复杂的,就得需要写技巧;
- 1.实例方法Python 的实例方法用得最多,也最常见。我们先来看 Python 的实例方法。class Kls(object): &nbs
- 对于英文不行我来说使用英文版PyCharm实在是太难受了,网上好多汉化补丁都是网友提供了,下面为大家介绍一种PyCharm官方中文语言包汉化
- 前言wx.gird.Gird是实现类似excel表格的库,扩展面很广,本文讲述它添加按钮,按钮响应的内容实现效果图如下:本文基于wxPyth
- 1.安装pyinstaller https://www.jb51.net/article/177160.htm2.安装pywin32 htt
- Python实现新版正方系统滑动验证码识别算法和方案步骤一:点击数据分析点击滑动按钮,将发送一个请求到 /zfcaptchaLogin请求内
- 本文实例讲述了Python3使用turtle绘制超立方体图形。分享给大家供大家参考,具体如下:利用Python3中turtle的绘制超立方体
- 动态 web 应用也会需要静态文件,通常是 CSS 和 JavaScript 文件。理想状况下, 我们已经配置好 Web 服务器来提供静态文
- 在用户研究工作中,如何让自己的数据和结论更有说服力,是很重要的问题。最近将自己积累的用研信度和效度的笔记整理一下,罗列在文中,希望对大家有所