forked from michaelliao/learn-python3
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b2d7068
commit dcfcf7b
Showing
3 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# 导入turtle包的所有内容: | ||
from turtle import * | ||
|
||
# 设置笔刷宽度: | ||
width(4) | ||
|
||
# 前进: | ||
forward(200) | ||
# 右转90度: | ||
right(90) | ||
|
||
# 笔刷颜色: | ||
pencolor('red') | ||
forward(100) | ||
right(90) | ||
|
||
pencolor('green') | ||
forward(200) | ||
right(90) | ||
|
||
pencolor('blue') | ||
forward(100) | ||
right(90) | ||
|
||
# 调用done()使得窗口等待被关闭,否则将立刻关闭窗口: | ||
done() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from turtle import * | ||
|
||
def drawStar(x, y): | ||
pu() | ||
goto(x, y) | ||
pd() | ||
# set heading: 0 | ||
seth(0) | ||
for i in range(5): | ||
fd(40) | ||
rt(144) | ||
|
||
for x in range(0, 250, 50): | ||
drawStar(x, 0) | ||
|
||
done() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
from turtle import * | ||
|
||
colormode(255) | ||
|
||
lt(90) | ||
|
||
lv = 14 | ||
l = 120 | ||
s = 45 | ||
|
||
width(lv) | ||
|
||
r = 0 | ||
g = 0 | ||
b = 0 | ||
pencolor(r, g, b) | ||
|
||
penup() | ||
bk(l) | ||
pendown() | ||
fd(l) | ||
|
||
def draw_tree(l, level): | ||
global r, g, b | ||
# save the current pen width | ||
w = width() | ||
|
||
# narrow the pen width | ||
width(w * 3.0 / 4.0) | ||
# set color: | ||
r = r + 1 | ||
g = g + 2 | ||
b = b + 3 | ||
pencolor(r % 200, g % 200, b % 200) | ||
|
||
l = 3.0 / 4.0 * l | ||
|
||
lt(s) | ||
fd(l) | ||
|
||
if level < lv: | ||
draw_tree(l, level + 1) | ||
bk(l) | ||
rt(2 * s) | ||
fd(l) | ||
|
||
if level < lv: | ||
draw_tree(l, level + 1) | ||
bk(l) | ||
lt(s) | ||
|
||
# restore the previous pen width | ||
width(w) | ||
|
||
speed("fastest") | ||
|
||
draw_tree(l, 4) | ||
|
||
done() |