本文实例为大家分享了用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视频教程
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
标签:
python,画花
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
白云城资源网 Copyright www.dyhadc.com
暂无“教你使用python画一朵花送女朋友”评论...
稳了!魔兽国服回归的3条重磅消息!官宣时间再确认!
昨天有一位朋友在大神群里分享,自己亚服账号被封号之后居然弹出了国服的封号信息对话框。
这里面让他访问的是一个国服的战网网址,com.cn和后面的zh都非常明白地表明这就是国服战网。
而他在复制这个网址并且进行登录之后,确实是网易的网址,也就是我们熟悉的停服之后国服发布的暴雪游戏产品运营到期开放退款的说明。这是一件比较奇怪的事情,因为以前都没有出现这样的情况,现在突然提示跳转到国服战网的网址,是不是说明了简体中文客户端已经开始进行更新了呢?
更新日志
2025年04月29日
2025年04月29日
- 小骆驼-《草原狼2(蓝光CD)》[原抓WAV+CUE]
- 群星《欢迎来到我身边 电影原声专辑》[320K/MP3][105.02MB]
- 群星《欢迎来到我身边 电影原声专辑》[FLAC/分轨][480.9MB]
- 雷婷《梦里蓝天HQⅡ》 2023头版限量编号低速原抓[WAV+CUE][463M]
- 群星《2024好听新歌42》AI调整音效【WAV分轨】
- 王思雨-《思念陪着鸿雁飞》WAV
- 王思雨《喜马拉雅HQ》头版限量编号[WAV+CUE]
- 李健《无时无刻》[WAV+CUE][590M]
- 陈奕迅《酝酿》[WAV分轨][502M]
- 卓依婷《化蝶》2CD[WAV+CUE][1.1G]
- 群星《吉他王(黑胶CD)》[WAV+CUE]
- 齐秦《穿乐(穿越)》[WAV+CUE]
- 发烧珍品《数位CD音响测试-动向效果(九)》【WAV+CUE】
- 邝美云《邝美云精装歌集》[DSF][1.6G]
- 吕方《爱一回伤一回》[WAV+CUE][454M]