【Python打卡2019】之turtle库画五角星

0.turtle的具体使用见我室友的博客

https://blog.csdn.net/MessiNine/article/details/80314783#commentBox

1.画一下最简单的五角星

1.1思路:
  • 将turtle画笔想象成自己的笔,先向右画一笔,然后转向左下方画一笔,然后再向右上方画一笔…一共五笔;
  • 转化为函数思路,先前进一段,再右转144°,前进一段;然后再右转144°,前进一段…重复五次;
1.2实现:

turtle.fd(dis)表示前进dis距离(默认方向向右);
turtle.right(degree)表示右转degree度;
于是乎:

turtle.fd(100)
turtle.right(144)

就是向右一笔。
一共五笔,那么:

    for i in range(5):
        fd_right(100, 144)
fd_right()就是上面的一笔的函数:
def fd_right(fd_length,right_degree):
    turtle.fd(fd_length)
    turtle.right(right_degree)

最终程序与效果:

"""
    五角星的绘制
    日期20190412
"""
import turtle #调用turtle函数库

def main():
    """
    主函数
    """
    turtle.setup(500, 600, 50, 50)
    for i in range(5):
        fd_right(100, 144)
    turtle.done()
def fd_right(fd_length,right_degree):
    turtle.fd(fd_length)
    turtle.right(right_degree)
if __name__=='__main__':
    main()

五角星

2.未完待续,有空来补

我来了!没想到吧!
下面画一下多个五角星,思路也比较简单,每画一次五角星之后,把边长增加;

"""
    多个五角星的绘制
    日期20190412
"""
import turtle #调用turtle函数库

def main():
    """
    主函数
    """
    turtle.setup(800, 600, 50, 50)#设置窗口位置和大小
    fd_first = 100  #五角星边的初始长度
    for i in range(5):#画五个
        for j in range(5):#共五笔
            fd_right(fd_first, 144)
        fd_first+=20 #增加边长
    turtle.done()

def fd_right(fd_length,right_degree):
    turtle.fd(fd_length)
    turtle.right(right_degree)
if __name__=='__main__':
    main()

五个五角星

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值