如何使用python中的turtle画一个红苹果🍎?

如题所述

全部代码如下列出, 使用的是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()

追答

温馨提示:答案为网友推荐,仅供参考
第1个回答  2019-12-24
Turtle库是Python语言中一个很流行的绘制图像的函数库,想象一个小乌龟,在一个横轴为x、纵轴为y的坐标系原点...追问

有代码吗?

本回答被网友采纳
第2个回答  2019-12-24
兄弟找到了么,求分享一下,我也是异地没办法
相似回答