Open In App

How to draw a Spiral using arcs in Processing with Python Mode?

Processing is a programming language, and a development environment. It is an open-source software to create visual arts, graphics and animation using programming. It supports around 8 different modes, and in this article, we will be using Python Mode.

In this article, we are going to draw a spiral made of arcs using Processing with Python Mode. In case if you have not installed the Processing Software yet, follow this How to setup Python mode for Processing to download and install Processing and setup Python Mode. Here is a preview of what we are going to do. We are going to draw this spiral.



Approach:

Below is the full implementation:



Here is the Python code for the above approach. Now type the following code in the code editor.




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

Output:


Article Tags :