Reproducing LeWitt 340

Drawing with code.

October 15, 2016 - 13 minute read -
blog art

Following my last post on reproducing instruction-based art by Sol LeWitt, here is another one, slightly more complicated.

Sol LeWitt, 1980
Red, yellow, blue crayon on red, yellow and blue wall
Carnegie Museum of Art, Pittsburgh; Purchase: gift of Carol R. Brown and Family and A.W. Mellon Acquisition Endowment Fund, 84.79.1

Here is my reproduced version: Source code below (pretty hacky):

# Reproducing Sol LeWitt
# Wall Drawing 340
# http://massmoca.org/event/walldrawing340/

# Six-part drawing.
# The wall is divided horizontally and vertically into six equal parts.


def setup():
    size(1320, 490)
    background(255, 255, 255)


w = 400
h = 200
space_x = 30
space_y = 30
step = 5
    
def panel1():
   # 1st part: On red, blue horizontal parallel lines, and in the center, 
    # a circle within which are yellow vertical parallel lines; 
    noStroke()
    fill(255, 0, 0)
    rect(space_x, space_y, w, h)
    stroke(0, 195, 255)
    cnt_x = h / step
    for i in range(1, cnt_x):
        line(space_x, space_y + step*i, 
             space_x + w - 1, space_y + step*i)
    fill(255, 0 , 0)
    noStroke()
    ellipse(space_x + w/2, space_y + h/2, h*0.8, h*0.8)
    stroke(255, 255, 0)
    cnt_left = int(0.4*h / step)

    for i in range(0, cnt_left):
        temp_x = space_x + w/2 - step*i
        a = acos(float(step*i/(0.4*h)))
        temp_height = sin(a)*0.4*h
        line(temp_x, space_y + h/2 - temp_height, 
             temp_x, space_y + h/2 + temp_height)
        
    for i in range(1, cnt_left):
        temp_x = space_x + w/2 + step*i
        a = acos(float(step*i/(0.4*h)))
        temp_height = sin(a)*0.4*h
        line(temp_x, space_y + h/2 - temp_height, 
             temp_x, space_y + h/2 + temp_height)
    
def panel2():
    # 2nd part: On yellow, red horizontal parallel lines, 
    # and in the center, a square within which are blue vertical parallel lines;
    noStroke()
    fill(255, 255, 0)
    rect(2*space_x + w, space_y, w, h)
    stroke(255, 0, 0)
    cnt_x = h / step
    for i in range(1, cnt_x):
        line(2*space_x + w, space_y + step*i, 
             2*space_x + 2*w - 1, space_y + step*i)
    fill(255, 255 , 0)
    noStroke()
    rect(2*space_x + 3*w/2 - h*0.4, space_y + h/2 - h*0.4 + 1, h*0.8, h*0.8 - 1)
    stroke(0, 191, 255)
    cnt_y = int(h*0.8/step)
    for i in range(cnt_y+1):
        line(2*space_x + 3*w/2 - h*0.4 + step*i, 
             space_y + h/2 - h*0.4 + 1, 
             2*space_x + 3*w/2 - h*0.4 + step*i,
             space_y + h/2 - h*0.4 + h*0.8 - 1)


def panel3():
   # 3rd part: On blue, yellow horizontal parallel lines, and in the center, 
    # a triangle within which are red vertical parallel lines; 
    noStroke()
    fill(0, 191, 255)
    rect(3*space_x + 2*w, space_y, w, h)
    stroke(255, 255, 0)
    cnt_x = h / step
    for i in range(1, cnt_x):
        line(3*space_x + 2*w, space_y + step*i, 
             3*space_x + 3*w - 1, space_y + step*i)
    
    fill(0, 191, 255)
    noStroke()
    triangle(3*space_x + 2*w + 0.5*w, space_y + 0.1*h + 1,
             3*space_x + 2*w + 0.3*w, space_y + 0.9*h - 1,
             3*space_x + 2*w + 0.7*w, space_y + 0.9*h - 1)
    
    a = float(0.8*h/(0.2*w))
    cnt_left = int(0.2*w/step)
    stroke(225, 0, 0)
    for i in range(1, cnt_left):
        temp_x = 3*space_x + 2*w + 0.3*w + i*step
        temp_height = i*step*a
        line(temp_x, space_y + 0.9*h - 1,
             temp_x, space_y + 0.9*h - temp_height)
   
    for i in range(cnt_left):
        temp_x = 3*space_x + 2*w + 0.5*w + i*step
        temp_height = (0.2*w-i*step)*a
        line(temp_x, space_y + 0.9*h - 1,
             temp_x, space_y + 0.9*h - temp_height)



def panel4():
    # 4th part: On red, yellow horizontal parallel lines, 
    # and in the center, a rectangle within which are blue vertical parallel lines; 
    noStroke()
    fill(255, 0, 0)
    rect(space_x, 2*space_y + h, w, h)
    stroke(255, 255, 0)
    cnt_x = h / step
    for i in range(1, cnt_x):
        line(space_x, 2*space_y + h + step*i, 
             space_x + w - 1, 2*space_y + h + step*i)
    fill(255, 0, 0)
    noStroke()
    rect(0.4*w + space_x, 2*space_y + h + 0.1*h + 1, 0.2*w, 0.8*h - 1)
    stroke(0, 191, 255)
    cnt_y = int(0.2*w/step)
    for i in range(cnt_y+1):
        line(0.4*w + space_x + step*i,
             2*space_y + h + 0.1*h + 1,
             0.4*w + space_x + step*i,
             2*space_y + h + 0.9*h - 1)
    

def panel5():
    # 5th part: On yellow, blue horizontal parallel lines, 
    # and in the center, a trapezoid within which are red vertical parallel lines; 
    noStroke()
    fill(255, 255, 0)
    rect(2*space_x + w, 2*space_y + h, w, h)
    stroke(0, 191, 255)
    cnt_x = h / step
    for i in range(1, cnt_x):
        line(2*space_x + w, 2*space_y + h + i*step, 
             2*space_x + 2*w - 1, 2*space_y + h + i*step)
    noStroke()
    fill(255, 255, 0)
    triangle(0.4*w + 2*space_x + w, 2*space_y + h + 0.1*h + 1,
             0.4*w + 2*space_x + w, 2*space_y + h + 0.9*h,
             0.25*w + 2*space_x + w, 2*space_y + h + 0.9*h,)
    rect(0.4*w + 2*space_x + w, 2*space_y + h + 0.1*h + 1, 0.2*w, 0.8*h - 1)
    triangle(0.6*w + 2*space_x + w, 2*space_y + h + 0.1*h + 1,
             0.6*w + 2*space_x + w, 2*space_y + h + 0.9*h,
             0.75*w + 2*space_x + w, 2*space_y + h + 0.9*h,)
    
    stroke(255, 0, 0)
    cnt_left = int(0.15*w/step)
    a = 0.8*h/(0.15*w)
    for i in range(1, cnt_left+1):
        temp_x = 0.25*w + 2*space_x + w + i*step
        temp_height = a*i*step
        line(temp_x, 2*space_y + h + 0.9*h - temp_height + 1,
             temp_x, 2*space_y + h + 0.9*h - 1)
    for i in range(1, int(0.2*w/step)):
        temp_x = 0.4*w + 2*space_x + w + i*step
        line(temp_x, 2*space_y + h + 0.1*h,
             temp_x, 2*space_y + h + 0.9*h)
    for i in range(cnt_left):
        temp_x = 0.6*w + 2*space_x + w + i*step
        temp_height = a*(0.15*w - i*step)
        line(temp_x, 2*space_y + h + 0.9*h - temp_height + 1,
             temp_x, 2*space_y + h + 0.9*h - 1)

    

def panel6():
    # 6th part: On blue, red horizontal parallel lines, and in the center, 
    # a parallelogram within which are yellow vertical parallel lines. 
    noStroke()
    fill(0, 191, 255)
    rect(3*space_x + 2*w, 2*space_y + h, w, h)
    stroke(255, 0, 0)
    cnt_x = h / step
    for i in range(1, cnt_x):
        line(3*space_x + 2*w, 2*space_y + h + i*step,
             3*space_x + 3*w - 1, 2*space_y + h + i*step)
    stroke(0, 191, 255)
    fill(0, 191, 255)
    triangle(3*space_x + 2*w + 0.35*w, 2*space_y + 1.1*h + 1,
             3*space_x + 2*w + 0.25*w, 2*space_y + 1.9*h - 1,
             3*space_x + 2*w + 0.6*w, 2*space_y + 1.9*h - 1)
    triangle(3*space_x + 2*w + 0.35*w, 2*space_y + 1.1*h + 1,
             3*space_x + 2*w + 0.7*w, 2*space_y + 1.1*h + 1,
             3*space_x + 2*w + 0.6*w, 2*space_y + 1.9*h - 1)
    
    cnt_left = int(0.1*w/step)
    a = 0.8*h/(0.1*w)
    stroke(255, 255, 0)
    for i in range(1, cnt_left+1):
        temp_x = 3*space_x + 2*w + 0.25*w + step*i
        temp_height = a*step*i
        line(temp_x, 2*space_y +1.9*h - temp_height + 1,
             temp_x, 2*space_y + 1.9*h - 1)
    for i in range(0, int(0.25*w/step)):
        temp_x = 3*space_x + 2*w + 0.35*w + step*i
        line(temp_x, 2*space_y + 1.1*h + 1,
             temp_x, 2*space_y + 1.9*h - 1 )
    for i in range(0, cnt_left):
        temp_x = 3*space_x + 2*w + 0.6*w + step*i
        temp_height = a*step*i
        line(temp_x, 2*space_y +1.1*h  + 1,
             temp_x, 2*space_y + 1.9*h - 1 - temp_height)
    
    # The horizontal lines do not enter the figures.


def draw():
    panel1()
    panel2()
    panel3()
    panel4()
    panel5()
    panel6()