Skip to content
  • P
    Projects
  • G
    Groups
  • S
    Snippets
  • Help

Administrator / level3-lesson15-diy2

  • This project
    • Loading...
  • Sign in
Go to a project
  • Project
  • Repository
  • Issues 0
  • Merge Requests 0
  • Pipelines
  • Wiki
  • Snippets
  • Members
  • Activity
  • Graph
  • Charts
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • Files
  • Commits
  • Branches
  • Tags
  • Contributors
  • Graph
  • Compare
  • Charts
Switch branch/tag
  • level3-lesson15-diy2
  • my_tree.py
Find file
BlameHistoryPermalink
  • BellCodeEditor's avatar
    save project · e1372b81
    BellCodeEditor committed a year ago
    e1372b81
my_tree.py 1.72 KB
Edit
1
import turtle as T 2 import random 3 import time 4  5 # 画樱花的躯干(60,t) 6 def Tree(branch, t): 7     time.sleep(0.0005) 8     if branch > 3: 9         if 8 <= branch <= 12:10             if random.randint(0, 2) == 0:11                 t.color('snow')  # 白12             else:13                 t.color('lightcoral')  # 淡珊瑚色14             t.pensize(branch / 3)15         elif branch < 8:16             if random.randint(0, 1) == 0:17                 t.color('snow')18             else:19                 t.color('lightcoral')  # 淡珊瑚色20             t.pensize(branch / 2)21         else:22             t.color('sienna')  # 赭(zhě)色23             t.pensize(branch / 10)  # 624         t.forward(branch)25         a = 1.5 * random.random()26         t.right(20 * a)27         b = 1.5 * random.random()28         Tree(branch - 10 * b, t)29         t.left(40 * a)30         Tree(branch - 10 * b, t)31         t.right(20 * a)32         t.up()33         t.backward(branch)34         t.down()35 36 # 掉落的花瓣37 def Petal(m, t):38     for i in range(m):39         a = 200 - 400 * random.random()40         b = 10 - 20 * random.random()41         t.up()42         t.forward(b)43         t.left(90)44         t.forward(a)45         t.down()46         t.color('lightcoral')  # 淡珊瑚色47         t.circle(1)48         t.up()49         t.backward(a)50         t.right(90)51         t.backward(b)52 53 # 绘图区域54 t = T.Turtle()55 # 画布大小56 w = T.Screen()57 t.hideturtle()  # 隐藏画笔58 t.getscreen().tracer(5, 0)59 w.screensize(bg='wheat')  # wheat小麦60 t.left(90)61 t.up()62 t.backward(150)63 t.down()64 t.color('sienna')65 66 # 画樱花的躯干67 Tree(60, t)68 # 掉落的花瓣69 Petal(200, t)70 w.exitonclick()