📜  如何在Python模式下使用弧线绘制螺旋线?

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

如何在Python模式下使用弧线绘制螺旋线?

处理是一种编程语言,也是一种开发环境。它是一个使用编程创建视觉艺术、图形和动画的开源软件。它支持大约 8 种不同的模式,在本文中,我们将使用Python模式

在本文中,我们将使用Python模式处理绘制由弧组成的螺旋。如果您尚未安装处理软件,请按照如何为处理设置Python模式下载并安装处理和设置Python模式。这是我们将要做的事情的预览。我们将画出这个螺旋。

方法:

  • 首先打开Processing软件,选择Python Mode。
  • 然后在编码部分,我们将定义两个函数setup()draw()
  • setup()函数在程序启动之前被调用。这里我们要设置窗口的背景颜色大小
  • draw()函数中,我们首先使用noFill()函数将弧的填充颜色设置为无。然后将弧线的颜色描边为白色
  • 之后,我们使用一个循环来使用arc()函数创建弧。在每次迭代中,我们必须将弧的高度和宽度增加 50px 并将弧倾斜 180 度,以形成螺旋。

下面是完整的实现:

这是上述方法的Python代码。现在在代码编辑器中键入以下代码。

Python3
# function to setup size of
# output window
def setup():
    # to set background color of window
    # to black color
    background(0)
      
    # to set width and height of window
    # to 1000px and 1000px respectively
    size(1000, 1000)
  
# function to draw on the window
def draw():
    
    # to set the fill color of the arcs to None
    noFill()
      
    # to set the border color of arcs to white
    #that is rgb(255,255,255)
    stroke(255, 255, 255)
      
    # loop to create 16 arcs
    for i in range(16):
        # if i is even
        if i % 2 == 0:
            
          # function to create an arc with center (500,525)
          # and width and height as 50px and 50px respectively
          # In each alternate iteration, the height and width of
          # the arcs increases by 100px. The arc starts at
          # 90 degrees that is half times PI and end at 270
          # degrees (90 + 180) that is PI + half times PI
            arc(500, 525, 50+i*50, 50+i*50,
                HALF_PI, HALF_PI+PI)
              
        # if i is odd
        else:
          # function to create an arc with center (500,500)
          # and width and height as 50px and 50px respectively
          # In each alternate iteration, the height and width of
          # the arcs increases by 100px. The arc starts at
          # 270 degrees that is PI + half times PI and end at 450
          # degrees (90 + 360) that is 2 times PI + half times PI
            arc(500, 500, 50+i*50, 50+i*50, 
                HALF_PI+PI, HALF_PI + 2*PI)


输出: