📌  相关文章
📜  在Python中使用 Turtle 使用 VIBGYOR 绘制同心圆

📅  最后修改于: 2022-05-13 01:54:39.377000             🧑  作者: Mango

在Python中使用 Turtle 使用 VIBGYOR 绘制同心圆

先决条件:海龟编程基础

Turtle是Python中的一个内置模块。它使用屏幕(纸板)和海龟(笔)提供绘图。要在屏幕上绘制一些东西,我们需要移动海龟(笔)。要移动海龟,有一些函数,即 forward()、backward() 等。

绘制同心 VIBGYOR :

下面是实现:

Python3
# 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()


输出 :

同心振动器