Python畫河大
阿新 • • 發佈:2018-11-13
點選檢視視訊:
http://v.youku.com/v_show/id_XMzkxNzA0Mzk3Ng==.html?sharekey=d352dfb1e74fc9249863da3b52a3d0e69
import turtle turtle.screensize(None, None, "skyblue") turtle.pensize(3) turtle.color("white") turtle.penup() turtle.goto(-220,-180) turtle.fillcolor("gray") turtle.pendown() turtle.begin_fill() #左面 turtle.left(90) turtle.forward(250) turtle.right(90) turtle.forward(25) turtle.left(90) turtle.forward(25) turtle.right(90) turtle.forward(35) turtle.left(90) turtle.forward(50) turtle.right(90) turtle.forward(15) turtle.left(90) turtle.forward(15) turtle.right(90) turtle.forward(25) turtle.right(90) turtle.forward(15) turtle.left(90) turtle.forward(15) turtle.right(90) turtle.forward(25) turtle.left(90) turtle.forward(200) #右面 turtle.left(90) turtle.forward(25) turtle.right(90) turtle.forward(15) turtle.left(90) turtle.forward(15) turtle.right(90) turtle.forward(25) turtle.right(90) turtle.forward(15) turtle.left(90) turtle.forward(15) turtle.right(90) turtle.forward(50) turtle.left(90) turtle.forward(35) turtle.right(90) turtle.forward(25) turtle.left(90) turtle.forward(25) turtle.right(90) turtle.forward(250) #底 turtle.right(90) turtle.forward(430) turtle.end_fill() #小人 turtle.left(180) turtle.penup() turtle.goto(330,-150) turtle.pendown() turtle.circle(20) turtle.penup() turtle.goto(325,-148) turtle.pendown() turtle.right(120) turtle.forward(40) turtle.left(120) turtle.forward(52) turtle.left(120) turtle.forward(40) turtle.penup() turtle.goto(318,-155) turtle.pendown() turtle.left(90) turtle.forward(40) turtle.penup() turtle.goto(340,-155) turtle.pendown() turtle.left(120) turtle.forward(40) turtle.penup() turtle.goto(318,-185) turtle.pendown() turtle.right(60) turtle.forward(40) turtle.penup() turtle.goto(340,-185) turtle.pendown() turtle.forward(40) turtle.right(90) #公路 turtle.fillcolor("royalblue") turtle.begin_fill() turtle.speed(20) turtle.penup() turtle.goto(360,-230) turtle.pendown() turtle.forward(750) turtle.left(60) turtle.forward(150) turtle.left(120) turtle.forward(750) turtle.left(60) turtle.forward(150) turtle.end_fill() turtle.left(120) turtle.fillcolor("white") turtle.begin_fill() turtle.speed(30) turtle.penup() turtle.goto(330,-235) turtle.pendown() turtle.forward(100) turtle.left(60) turtle.forward(10) turtle.left(120) turtle.forward(100) turtle.left(60) turtle.forward(10) turtle.end_fill() turtle.left(120) turtle.fillcolor("white") turtle.begin_fill() turtle.penup() turtle.goto(320,-250) turtle.pendown() turtle.forward(100) turtle.left(60) turtle.forward(10) turtle.left(120) turtle.forward(100) turtle.left(60) turtle.forward(10) turtle.end_fill() turtle.left(120) turtle.fillcolor("white") turtle.begin_fill() turtle.penup() turtle.goto(310,-265) turtle.pendown() turtle.forward(100) turtle.left(60) turtle.forward(10) turtle.left(120) turtle.forward(100) turtle.left(60) turtle.forward(10) turtle.end_fill() turtle.left(120) turtle.fillcolor("white") turtle.begin_fill() turtle.penup() turtle.goto(300,-280) turtle.pendown() turtle.forward(100) turtle.left(60) turtle.forward(10) turtle.left(120) turtle.forward(100) turtle.left(60) turtle.forward(10) turtle.end_fill() turtle.left(120) turtle.fillcolor("white") turtle.begin_fill() turtle.penup() turtle.goto(290,-295) turtle.pendown() turtle.forward(100) turtle.left(60) turtle.forward(10) turtle.left(120) turtle.forward(100) turtle.left(60) turtle.forward(10) turtle.end_fill() turtle.left(120) turtle.fillcolor("white") turtle.begin_fill() turtle.penup() turtle.goto(280,-310) turtle.pendown() turtle.forward(100) turtle.left(60) turtle.forward(10) turtle.left(120) turtle.forward(100) turtle.left(60) turtle.forward(10) turtle.end_fill() turtle.left(120) #雲 turtle.fillcolor("white") turtle.begin_fill() turtle.speed(20) turtle.penup() turtle.goto(100,280) turtle.pendown() turtle.circle(30) turtle.end_fill() turtle.begin_fill() turtle.penup() turtle.goto(100,320) turtle.pendown() turtle.circle(30) turtle.end_fill() turtle.begin_fill() turtle.penup() turtle.goto(60,300) turtle.pendown() turtle.circle(30) turtle.end_fill() turtle.begin_fill() turtle.penup() turtle.goto(120,310) turtle.pendown() turtle.circle(30) turtle.end_fill() turtle.begin_fill() turtle.penup() turtle.goto(140,290) turtle.pendown() turtle.circle(30) turtle.end_fill() #太陽 turtle.penup() turtle.goto(-280,230) turtle.pendown() from turtle import* import turtle as t import time t.color("yellow", "yellow") t.begin_fill() t.speed(20) for _ in range(50): t.forward(150) t.left(170) end_fill() time.sleep(1) #樹 turtle.penup() turtle.goto(-350,-220) turtle.pendown() turtle.speed(100) turtle.right(35) def draw_brach(brach_length): if brach_length > 3: if brach_length < 30: turtle.color('green') else: turtle.color('brown') # 繪製右側的樹枝 turtle.forward(brach_length) print('向前',brach_length) turtle.right(25) print('右轉20') draw_brach(brach_length-10) # 繪製左側的樹枝 turtle.left(50) print('左轉40') draw_brach(brach_length-10) if brach_length < 30: turtle.color('green') else: turtle.color('brown') # 返回之前的樹枝上 turtle.right(25) print('右轉20') turtle.backward(brach_length) print('返回',brach_length) def main(): turtle.left(90) turtle.penup() turtle.backward(180) turtle.pendown() turtle.color('brown') draw_brach(80) turtle.exitonclick() if __name__ == '__main__': main()