全部代码如下列出, 使用的是python3。
可以作为参考,这个代码比较简单,是用圆形来近似地画一个苹果。
可以复制代码,我把缩进也打进去了,因此我加上了网页链接,目的地是菜鸟教程(不过与本题无关,[doge])
from turtle import *
def leaf(radius,an=90,co="green",co1="green"):
width(3)
color(co,co1)
pass
begin_fill()
circle(radius/2., an)
end_fill()
def stem(radius):
color("")
right(90)
fd(radius)
color("brown")
right(0)
width(9)
circle(radius*5,-19)
color("")
pass
def pulp(radius):
pass#果肉
begin_fill()
circle(radius)
end_fill()
color("white")
left(90)
fd(0.24/0.84*radius)
left(90)
begin_fill()
circle(1.32/0.84*radius)
end_fill()
color("")
home()
fd(radius*5/4/9)
right(90)
fd(radius*2)
right(180)
color("white")
fd(0.16/0.84*radius)
right(-90)
begin_fill()
circle(0.48/0.84*radius)
end_fill()
color("")
fd(0.13/0.37*radius)#0.13
right(90)
bk(0.06/0.43*radius)
left(90)
color("")
def main():
speed="fast"
aplfr=160
reset()
width(3)
#yin(200, "black", "white")
#yin(200, "white", "black")
ht()
home()
color("")
fd(aplfr/9.)
rt(90)
#fd(aplfr/9)
color("red")
right(90)
strt=pos()
pulp(aplfr*2/2.5)#0.84
home()
setpos(strt)
stem(40)
home()
left(180-80)#init as 0
st()
pass
leaf(aplfr)
left(90)
leaf(aplfr)
pass
return "Done!"
if __name__ == '__main__':
main()
mainloop()
说明 sep:分隔符。可以为空 seq:要连接的元素序列、字符串、元组、字典 上面的语法即:以sep作为分隔符,将seq所有的元素合并成一个新的字符串 返回值:返回一个以分隔符sep连接各个元素后生成的字符串