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

Administrator / level3-lesson15-diy1

  • 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
Commit 995e1507 authored 2 years ago by BellCodeEditor's avatar BellCodeEditor
Browse files
Options
  • Browse Files
  • Download
  • Email Patches
  • Plain Diff

save project

parent 316004e3
Show whitespace changes
Inline Side-by-side
Showing with 24 additions and 10 deletions
  • my_tree.py
my_tree.py
View file @ 995e1507
import turtle import turtle
import random
t = turtle.Turtle() t = turtle.Turtle()
t.color('sienna') t.color('sienna')
t.hideturtle()
# 画布大小 # 画布大小
w = turtle.Screen() w = turtle.Screen()
w.bgcolor('wheat') # wheat小麦 w.bgcolor('wheat') # wheat小麦
...@@ -13,17 +14,29 @@ t.backward(150) # 后退 ...@@ -13,17 +14,29 @@ t.backward(150) # 后退
t.down() t.down()
def tree(n): def tree(n):
if n>=50: if n>= 0:
t.pensize(100) if n<=12:
t.speed(-1) t.speed(100)
color_list = ['snow','lightcoral']
color = random.choice(color_list)
t.color(color)
t.pensize(n / 3)
else:
t.color('sienna')
t.pensize(n / 10)
t.forward(n) t.forward(n)
t.right(30) angle = random.random()
tree(n-50) t.right(30*angle)
t.left(60) length = 1.5*random.random()
tree(n-50) tree(n-10*length)
t.right(30) t.left(60*angle)
tree(n-10*length)
t.right(30*angle)
t.up() t.up()
t.backward(n) t.backward(n)
t.down() t.down()
tree(100) tree(60)
turtle.done() turtle.done()
for i in range (5):
tree()
lt(72)
\ No newline at end of file
This diff is collapsed. Click to expand it.
  • Write
  • Preview
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment