原文链接:http://www.juzicode.com/archives/2575
要画桔子,先对着个桔子看几分钟:
看完了桔子该动手了,先画个外形:
print('\n-----欢迎来到juzicode.com')
print('-----公众号: 桔子code/juzicode \n')
import turtle
turtle.setup(width=700,height=500)
turtle.speed(10)
#画桔子本身
turtle.penup()
turtle.goto(0,-80)
turtle.pendown()
turtle.circle(80)
#回到桔子顶部
turtle.penup()
turtle.goto(0,80)
turtle.pendown()
#画桔子柄
turtle.left(90)
turtle.forward(60)
#回到桔子顶部,画左边叶子
turtle.penup()
turtle.goto(0,80)
turtle.pendown()
turtle.left(60)
turtle.forward(60)
#回到桔子顶部,画右边叶子
turtle.penup()
turtle.goto(0,80)
turtle.pendown()
turtle.right(130)
turtle.forward(60)
#
turtle.mainloop()
画出来的桔子基本骨架是这样的:
看起来还是有点简陋,继续修饰下:桔子身由橘色填充,桔子叶画的大一些,用绿色填充,桔子柄用棕色:
print('\n-----欢迎来到juzicode.com')
print('-----公众号: 桔子code/juzicode \n')
import turtle
turtle.setup(width=700,height=500)
turtle.speed(1)
turtle.hideturtle()
#画桔子本身
turtle.penup()
turtle.goto(0,-80)
turtle.pendown()
turtle.begin_fill()
turtle.circle(80)
turtle.fillcolor('orange')
turtle.end_fill()
#回到桔子柄根部
turtle.penup()
turtle.goto(0,80)
turtle.pendown()
#画桔子柄
steam_len = 60 #桔子柄长度
turtle.left(90)#左转,竖直向上走
turtle.pensize(8)
turtle.pencolor('brown')
turtle.forward(steam_len)
turtle.pensize(1)
leaf_len = 60 #叶子中心长度
#回到桔子柄根部,画左边叶子
turtle.pencolor('green')
turtle.penup()
turtle.home()
turtle.goto(0,80)
turtle.pendown()
turtle.left(160)
turtle.forward(leaf_len)
turtle.begin_fill()
turtle.fillcolor('green')
turtle.left(135)
turtle.forward(leaf_len/3)
turtle.left(45)
turtle.forward(leaf_len/3)
turtle.left(45)
turtle.forward(leaf_len/3)
turtle.end_fill()
#回到桔子柄根部,画右边叶子
turtle.pencolor('green')
turtle.penup()
turtle.home()
turtle.goto(0,80)
turtle.pendown()
turtle.left(45)
turtle.forward(leaf_len)
turtle.begin_fill()
turtle.fillcolor('green')
turtle.right(135)
turtle.forward(leaf_len/3)
turtle.right(45)
turtle.forward(leaf_len/3)
turtle.right(45)
turtle.forward(leaf_len/3)
turtle.end_fill()
turtle.mainloop()
桔子菌画的桔子