zoukankan      html  css  js  c++  java
  • turtle绘制多个五角星

    学习了初步的使用turtle库,绘制简单的五角星

     1 # coding=gbk
     2 import turtle
     3 
     4 
     5 # 画一个五角星
     6 def star(size):
     7     for i in range(0, 5):
     8         turtle.fd(size)
     9         turtle.right(144)
    10 
    11 
    12 # 指定初始长度,画多少个五角星,相邻五角星长度差
    13 def some_star(init_size, count, step):
    14     for i in range(0, count):
    15         star(init_size+i*step)
    16 
    17 
    18 # 递归的方法
    19 def recursive(size, count, step):
    20     for i in range(0, 5):
    21         turtle.fd(size)
    22         turtle.right(144)
    23     size += step
    24     count -= 1
    25     if count > 0:
    26         recursive(size, count, step)
    27 
    28 
    29 def main():
    30     # 一些方法的练习
    31     turtle.penup()
    32     turtle.forward(50)
    33     turtle.pendown()
    34     turtle.pensize(2)
    35     turtle.pencolor('red')
    36 
    37     # some_star(50, 5, 50)
    38     recursive(50, 5, 50)
    39     turtle.exitonclick()
    40 
    41 
    42 if __name__ == '__main__':
    43     main()
  • 相关阅读:
    AOV网和AOE网对比
    AOV网和AOE网对比
    Python类型总结
    Python数据结构
    Django之认证系统
    day22笔记
    数据库概念知识
    pymsql模块使用
    多表查询(子查询)
    多表查询(链接查询)
  • 原文地址:https://www.cnblogs.com/weiwei2016/p/10172836.html
Copyright © 2011-2022 走看看