用VIBGYOR在Python中使用Turtle绘制同心圆 | 您所在的位置:网站首页 › 用python绘制嵌套五边形 › 用VIBGYOR在Python中使用Turtle绘制同心圆 |
用VIBGYOR在Python中使用Turtle绘制同心圆
Turtle是Python中的一个内置模块。它提供了使用屏幕(纸板)和Turtle(笔)的绘画。为了在屏幕上画东西,我们需要移动Turtle(笔)。为了移动Turtle,有一些函数,如forward()、backward()等。 绘制同心圆VIBGYOR :以下是使用的步骤。 导入Turtle模块 设置一个屏幕 制作Turtle对象 定义一个具有动态半径和颜色的圆的方法。 通过将Turtle对象设置在所需的位置来编写文本。以下是实现。 # import turtle package import turtle # Screen object sc = turtle.Screen() # Screen background color sc.bgcolor('black') # turtle object pen = turtle.Turtle() # turtle width pen.width(4) # function to draw a circle of # rad radius and col color def circle(col, rad, val): pen.color(col) pen.circle(rad) pen.up() # set position for space pen.setpos(0, val) pen.down() # function to write text # by setting positions def text(): pen.color('white') pen.up() pen.setpos(-100, 140) pen.down() pen.write("Concentric VIBGYOR", font = ("Verdana", 15)) pen.up() pen.setpos(-82, -188) pen.down() pen.write("Using Turtle Graphics", font = ("Verdana", 12)) pen.hideturtle() # Driver code if __name__ == "__main__" : # VIBGYOR color list col = ['violet', 'indigo', 'blue', 'green', 'yellow', 'orange', 'red'] # 7 Concentric circles for i in range(7): # function call circle(col[i], -20*(i+1), 20*(i+1)) # function call text() 输出 :Concentric Vibgyor |
今日新闻 |
推荐新闻 |
专题文章 |
CopyRight 2018-2019 实验室设备网 版权所有 |