国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

教你使用python畫一朵花送女朋友

2020-01-04 15:27:24
字體:
來源:轉載
供稿:網友

本文實例為大家分享了用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()

第二種,畫法

python,畫花

import turtleimport mathdef 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()

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持VEVB武林網。


注:相關教程知識閱讀請移步到python教程頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 常山县| 故城县| 东辽县| 佛山市| 清原| 汝州市| 全州县| 信丰县| 盐津县| 德兴市| 维西| 孟州市| 长子县| 特克斯县| 临湘市| 囊谦县| 堆龙德庆县| 肇庆市| 个旧市| 白玉县| 巴东县| 清流县| 石狮市| 华蓥市| 黄浦区| 固镇县| 奎屯市| 新邵县| 沙坪坝区| 威远县| 科技| 廊坊市| 墨江| 虹口区| 宝坻区| 丰原市| 平远县| 宁安市| 东乡县| 华坪县| 会宁县|