首页 > 技术文章 > turtle库应用实例-五角星绘制

Anjoras-bk 2020-03-14 21:56 原文

五角星绘制

 ‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‭‬

描述

使用turtle库绘制一个红色五角星图形

import turtle as t
t.fillcolor("red")   #填充颜色red
t.begin_fill()       #开始填充
for i in range(5):    #五次循环
    t.fd(50)
    t.right(-144)
t.end_fill()         #停止填充

  

其中涉及的语法知识:

1,库的引用

法一:import <库名>

           <库名>.<函数名>(<函数参数>)

法二:from <库名> import <函数名>

法三:form <库名> import *

           <函数名>(<函数参数>)

but, 法二三会出现函数重名问题,因此可使用

           import <库名> as <库别名>

           <库别名>.<函数名>(<函数参数>)

‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬

 

推荐阅读