예제 #1
0
def checker(boardsize_x, boardsize_y, blocksize_x, blocksize_y):
    print('Starting')

    xwt = 0
    ywt = 0
    temp = one_color.struc()
    bluepoints = [copy.deepcopy(one_color.struc)]
    redpoints = [copy.deepcopy(one_color.struc)]

    for y in range(boardsize_y):
        t2 = y % blocksize_y
        if t2 == 0:
            ywt = ywt + 1
        #end if on t2

        ywt2 = ywt % 2

        if ywt2 == 1:
            n = 1
        elif ywt2 == 0:
            n = 2
        #end if on ywt2

        for x in range(boardsize_x):
            temp.x = x
            temp.y = y
            t = x % blocksize_x
            if t == 0:
                xwt = xwt + 1
            #end if on t

            xwt2 = xwt % 2

            if n == 1:
                if xwt2 == 1:
                    bluepoints.append(copy.deepcopy(temp))
                elif xwt2 == 0:
                    redpoints.append(copy.deepcopy(temp))
                #end if on xwt2
            elif n == 2:
                if xwt2 == 1:
                    redpoints.append(copy.deepcopy(temp))
                elif xwt2 == 0:
                    bluepoints.append(copy.deepcopy(temp))
                #end if on xwt2
            #end if on n
        #end for loop on x
    #end for loop on y

    del redpoints[0]  #remove unused location
    del bluepoints[0]  #remove unused location

    image = one_color.main(boardsize_x, boardsize_y, 255, 255, 255)
    image = add_to_image.main(image, redpoints, 255, 0, 0)
    image = add_to_image.main(image, bluepoints, 0, 0, 255)

    write_ppm.main(image, 'test')
    print('Finish')
예제 #2
0
def checker( boardsize_x, boardsize_y, blocksize_x, blocksize_y ):
    print ('Starting')

    xwt = 0
    ywt = 0
    temp = one_color.struc()
    bluepoints = [ copy.deepcopy( one_color.struc ) ]
    redpoints = [ copy.deepcopy( one_color.struc ) ]

    for y in range( boardsize_y ):
        t2 = y%blocksize_y
        if t2 == 0:
            ywt = ywt + 1
        #end if on t2

        ywt2 = ywt%2

        if ywt2 == 1:
            n = 1
        elif ywt2 == 0:
            n = 2
        #end if on ywt2

        for x in range( boardsize_x ):
            temp.x = x
            temp.y = y
            t = x%blocksize_x
            if t == 0:
                xwt = xwt + 1
            #end if on t

            xwt2 = xwt%2

            if n == 1:
                if xwt2 == 1:
                    bluepoints.append( copy.deepcopy( temp ) )
                elif xwt2 == 0:
                    redpoints.append( copy.deepcopy( temp ) )
                #end if on xwt2
            elif n == 2:
                if xwt2 == 1:
                    redpoints.append( copy.deepcopy( temp ) )
                elif xwt2 == 0:
                    bluepoints.append( copy.deepcopy( temp ) )
                #end if on xwt2
            #end if on n
        #end for loop on x
    #end for loop on y

    del redpoints[ 0 ] #remove unused location
    del bluepoints[ 0 ] #remove unused location

    image = one_color.main( boardsize_x, boardsize_y, 255, 255, 255 )
    image = add_to_image.main( image, redpoints, 255, 0, 0 )
    image = add_to_image.main( image, bluepoints, 0, 0, 255 )

    write_ppm.main( image, 'test' )
    print ('Finish')
예제 #3
0
def Line( boardsize_x, boardsize_y, x1, y1, x2, y2, xx1, yy1, xx2, yy2 ):
    print ('Starting')
    
    image = one_color.main( boardsize_x, boardsize_y, 245, 245, 245 )
    redline = draw_line.main( x1, y1, x2, y2 )
    greenline = draw_line.main( xx1, yy1, xx2, yy2 )
    image = add_to_image.main( image, redline, 255, 0, 0 )
    image = add_to_image.main( image, greenline, 0, 255, 0 )

    write_ppm.main( image, 'test' )
    print ('Finish')
예제 #4
0
def Line(boardsize_x, boardsize_y, x1, y1, x2, y2, xx1, yy1, xx2, yy2):
    print('Starting')

    image = one_color.main(boardsize_x, boardsize_y, 245, 245, 245)
    redline = draw_line.main(x1, y1, x2, y2)
    greenline = draw_line.main(xx1, yy1, xx2, yy2)
    image = add_to_image.main(image, redline, 255, 0, 0)
    image = add_to_image.main(image, greenline, 0, 255, 0)

    write_ppm.main(image, 'test')
    print('Finish')
예제 #5
0
def Translate( boardsize_x, boardsize_y, x1, y1, x2, y2, x3, y3, x4, y4, xt, yt ):
    
    print ('Starting')
    
    image = one_color.main( boardsize_x, boardsize_y, 245, 245, 245 )
    redLine = translation.main( x1, y1, x2, y2, xt, yt )
    greenLine = translation.main( x3, y3, x4, y4, xt, yt )
    image = add_to_image.main( image, redLine, 255, 0, 0 )
    image = add_to_image.main( image, greenLine, 0, 255, 0 )

    write_ppm.main( image, 'test' )
    print ('Finish')
예제 #6
0
def FillPolygon2( boardsize_x, boardsize_y ):
    
    print ('Starting')
    
    image = one_color.main( boardsize_x, boardsize_y, 245, 245, 245 )
    fill = fill_polygon2.main( 10, 10, 100, 10, 100, 300, 10, 150, 80, 150, 80, 50, 20, 50, 20, 100, 10, 100 )
    image = add_to_image.main( image, fill, 255, 0, 255 )
    border = draw_polygon.main( 10, 10, 100, 10, 100, 300, 10, 150, 80, 150, 80, 50, 20, 50, 20, 100, 10, 100 )
    image = add_to_image.main( image, border, 0 , 0, 0 )

    write_ppm.main( image, 'test' )
    print ('Finish')
예제 #7
0
def Polygon( boardsize_x, boardsize_y ):
    
    print ('Starting')
    
    image = one_color.main( boardsize_x, boardsize_y, 245, 245, 245 )
    poly = fill_polygon.main( 10, 10, 100, 10, 100, 300, 10, 150, 80, 150, 80, 50, 20, 50, 20, 100, 10, 100 )
    border = draw_polygon.main( 10, 10, 100, 10, 100, 300, 10, 150, 80, 150, 80, 50, 20, 50, 20, 100, 10, 100 )
    image = add_to_image.main( image, poly, 255, 0, 255 )
    image = add_to_image.main( image, border, 0, 0, 0 )

    write_ppm.main( image, 'test' )
    print ('Finish')
예제 #8
0
def Composite( boardsize_x, boardsize_y, x1, y1, x2, y2, x3, y3, x4, y4, xt, yt, d, xs, ys, xTrans, yTrans ):
    
    print ('Starting')
    
    image = one_color.main( boardsize_x, boardsize_y, 245, 245, 245 )
    redLine = composition.main( x1, y1, x2, y2, xt, yt, d, xs, ys, xTrans, yTrans )
    greenLine = composition.main( x3, y3, x4, y4, xt, yt, d, xs, ys, xTrans, yTrans )
    image = add_to_image.main( image, redLine, 255, 0, 0 )
    image = add_to_image.main( image, greenLine, 0, 255, 0 )

    write_ppm.main( image, 'test' )
    print ('Finish')
예제 #9
0
def Translate(boardsize_x, boardsize_y, x1, y1, x2, y2, x3, y3, x4, y4, xt,
              yt):

    print('Starting')

    image = one_color.main(boardsize_x, boardsize_y, 245, 245, 245)
    redLine = translation.main(x1, y1, x2, y2, xt, yt)
    greenLine = translation.main(x3, y3, x4, y4, xt, yt)
    image = add_to_image.main(image, redLine, 255, 0, 0)
    image = add_to_image.main(image, greenLine, 0, 255, 0)

    write_ppm.main(image, 'test')
    print('Finish')
예제 #10
0
def Scale( boardsize_x, boardsize_y, x1, y1, x2, y2, x3, y3, x4, y4, xt, yt, xs, ys ):
    
    print ('Starting')
    
    image = one_color.main( boardsize_x, boardsize_y, 245, 245, 245 )
    redPoints = scale.main( x1, y1, x2, y2, xt, yt, xs, ys )
    greenPoints = scale.main( x3, y3, x4, y4, xt, yt, xs, ys )
    redLine = draw_line.main( redPoints[ 0 ].x, redPoints[ 0 ].y, redPoints[ 1 ].x, redPoints[ 1 ].y )
    greenLine = draw_line.main( greenPoints[ 0 ].x, greenPoints[ 0 ].y, greenPoints[ 1 ].x, greenPoints[ 1 ].y )
    image = add_to_image.main( image, redLine, 255, 0, 0 )
    image = add_to_image.main( image, greenLine, 0, 255, 0 )

    write_ppm.main( image, 'test' )
    print ('Finish')
예제 #11
0
def Rotate(boardsize_x, boardsize_y, x1, y1, x2, y2, x3, y3, x4, y4, xf, yf,
           d):

    print('Starting')

    image = one_color.main(boardsize_x, boardsize_y, 245, 245, 245)
    redPoints = rotation.main(x1, y1, x2, y2, xf, yf, d)
    greenPoints = rotation.main(x3, y3, x4, y4, xf, yf, d)
    redLine = draw_line.main(redPoints[0].x, redPoints[0].y, redPoints[1].x,
                             redPoints[1].y)
    greenLine = draw_line.main(greenPoints[0].x, greenPoints[0].y,
                               greenPoints[1].x, greenPoints[1].y)
    image = add_to_image.main(image, redLine, 255, 0, 0)
    image = add_to_image.main(image, greenLine, 0, 255, 0)

    write_ppm.main(image, 'test')
    print('Finish')
예제 #12
0
def PolyTrans( boardsize_x, boardsize_y, x1, y1, x2, y2, x3, y3, x4, y4, x5, y5, xt, yt ):
    
    print ('Starting')
    
    image = one_color.main( boardsize_x, boardsize_y, 245, 245, 245 )
    poly = trans_poly.main( x1, y1, x2, y2, x3, y3, x4, y4, x5, y5, xt, yt )
    image = add_to_image.main( image, poly, 255, 0, 0 )

    write_ppm.main( image, 'test' )
    print ('Finish')
예제 #13
0
def TDview( boardsize_x, boardsize_y, xVRP, yVRP, zVRP, d, a, b, xt, yt, sf, x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, y4, z4, x5, y5, z5, x6, y6, z6, x7, y7, z7, x8, y8, z8, x9, y9, z9, x10, y10, z10, x11, y11, z11, x12, y12, z12, x13, y13, z13, x14, y14, z14, x15, y15, z15, x16, y16, z16, x17, y17, z17, x18, y18, z18, x19, y19, z19, x20, y20, z20, x21, y21, z21, x22, y22, z22, x23, y23, z23, x24, y24, z24, x25, y25, z25, x26, y26, z26, x27, y27, z27, x28, y28, z28, x29, y29, z29, x30, y30, z30 ):
    
    print ('Starting')
    
    image = one_color.main( boardsize_x, boardsize_y, 245, 245, 245 )
    frame = TDviewDisplay.main( xVRP, yVRP, zVRP, d, a, b, xt, yt, sf, x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, y4, z4, x5, y5, z5, x6, y6, z6, x7, y7, z7, x8, y8, z8, x9, y9, z9, x10, y10, z10, x11, y11, z11, x12, y12, z12, x13, y13, z13, x14, y14, z14, x15, y15, z15, x16, y16, z16, x17, y17, z17, x18, y18, z18, x19, y19, z19, x20, y20, z20, x21, y21, z21, x22, y22, z22, x23, y23, z23, x24, y24, z24, x25, y25, z25, x26, y26, z26, x27, y27, z27, x28, y28, z28, x29, y29, z29, x30, y30, z30 )
    image = add_to_image.main( image, frame, 255, 0, 0 )

    write_ppm.main( image, 'test' )
    print ('Finish')
예제 #14
0
def FillPolygon( boardsize_x, boardsize_y ):
    
    print ('Starting')
    
    image = one_color.main( boardsize_x, boardsize_y, 245, 245, 245 )
    fill = fill_polygon_test.main( 60, 120, 110, 200, 110, 150, 200, 220, 160, 120 )
    image = add_to_image.main( image, fill, 255, 0, 255 )

    write_ppm.main( image, 'test' )
    print ('Finish')
예제 #15
0
def Circle( boardsize_x, boardsize_y, x, y, r ):
    
    print ('Starting')
    
    image = one_color.main( boardsize_x, boardsize_y, 245, 245, 245 )
    circum = draw_circle.main( x, y, r )
    image = add_to_image.main( image, circum, 0, 0, 255 )

    write_ppm.main( image, 'test' )
    print ('Finish')
예제 #16
0
def CircleFill( boardsize_x, boardsize_y, x, y, r ):
    
    print ('Starting')
    
    image = one_color.main( boardsize_x, boardsize_y, 245, 245, 245 )
    circum = fill_circle.main( x, y, r )
    image = add_to_image.main( image, circum, 0, 0, 255 )

    write_ppm.main( image, 'test' )
    print ('Finish')
예제 #17
0
def Polygon(boardsize_x, boardsize_y):

    print('Starting')

    image = one_color.main(boardsize_x, boardsize_y, 245, 245, 245)
    poly = draw_polygon.main(60, 120, 110, 200, 110, 150, 200, 220, 160, 120)
    image = add_to_image.main(image, poly, 255, 0, 255)

    write_ppm.main(image, 'test')
    print('Finish')
예제 #18
0
def EllipseFill( boardsize_x, boardsize_y, x, y, majA, minB ):
    
    print ('Starting')
    
    image = one_color.main( boardsize_x, boardsize_y, 245, 245, 245 )
    circum = fill_ellipse.main( x, y, majA, minB )
    image = add_to_image.main( image, circum, 0, 0, 0 )

    write_ppm.main( image, 'test' )
    print ('Finish')
예제 #19
0
def PolyComp2( boardsize_x, boardsize_y, x1, y1, x2, y2, x3, y3, x4, y4, x5, y5, xt, yt, xTrans, yTrans, xs, ys, d ):
    
    print ('Starting')
    
    image = one_color.main( boardsize_x, boardsize_y, 245, 245, 245 )
    poly = comp_poly2.main( x1, y1, x2, y2, x3, y3, x4, y4, x5, y5, xt, yt, xTrans, yTrans, xs, ys, d )
    image = add_to_image.main( image, poly, 255, 0, 0 )

    write_ppm.main( image, 'test' )
    print ('Finish')
예제 #20
0
def Circle( boardsize_x, boardsize_y, x, y, majA, minB ):
    
    print ('Starting')
    
    image = one_color.main( boardsize_x, boardsize_y, 245, 245, 245 )
    circum = draw_ellipse.main( x, y, majA, minB )
    image = add_to_image.main( image, circum, 0, 0, 0 )

    write_ppm.main( image, 'test' )
    print ('Finish')
예제 #21
0
def Polygon( boardsize_x, boardsize_y ):
    
    print ('Starting')
    
    image = one_color.main( boardsize_x, boardsize_y, 245, 245, 245 )
    poly = draw_polygon.main( 60, 120, 110, 200, 110, 150, 200, 220, 160, 120 )
    image = add_to_image.main( image, poly, 255, 0, 255 )

    write_ppm.main( image, 'test' )
    print ('Finish')
예제 #22
0
def FillPolygon(boardsize_x, boardsize_y):

    print('Starting')

    image = one_color.main(boardsize_x, boardsize_y, 245, 245, 245)
    fill = fill_polygon_test.main(60, 120, 110, 200, 110, 150, 200, 220, 160,
                                  120)
    image = add_to_image.main(image, fill, 255, 0, 255)

    write_ppm.main(image, 'test')
    print('Finish')
예제 #23
0
def PolyTrans(boardsize_x, boardsize_y, x1, y1, x2, y2, x3, y3, x4, y4, x5, y5,
              xt, yt):

    print('Starting')

    image = one_color.main(boardsize_x, boardsize_y, 245, 245, 245)
    poly = trans_poly.main(x1, y1, x2, y2, x3, y3, x4, y4, x5, y5, xt, yt)
    image = add_to_image.main(image, poly, 255, 0, 0)

    write_ppm.main(image, 'test')
    print('Finish')
예제 #24
0
def TDline( boardsize_x, boardsize_y, d, xt, yt, sf, x1, y1, z1, x2, y2, z2 ):
    
    print ('Starting')

    array = [ x1, y1, z1, x2, y2, z2 ]
    
    image = one_color.main( boardsize_x, boardsize_y, 245, 245, 245 )
    frame = display.main( d, xt, yt, sf, array )
    image = add_to_image.main( image, frame, 255, 0, 0 )

    write_ppm.main( image, 'test' )
    print ('Finish')
예제 #25
0
def TDline(boardsize_x, boardsize_y, d, xt, yt, sf, x1, y1, z1, x2, y2, z2):

    print('Starting')

    array = [x1, y1, z1, x2, y2, z2]

    image = one_color.main(boardsize_x, boardsize_y, 245, 245, 245)
    frame = display.main(d, xt, yt, sf, array)
    image = add_to_image.main(image, frame, 255, 0, 0)

    write_ppm.main(image, 'test')
    print('Finish')
예제 #26
0
def TDview(boardsize_x, boardsize_y, xVRP, yVRP, zVRP, d, a, b, xt, yt, sf, x1,
           y1, z1, x2, y2, z2, x3, y3, z3, x4, y4, z4, x5, y5, z5, x6, y6, z6,
           x7, y7, z7, x8, y8, z8, x9, y9, z9, x10, y10, z10, x11, y11, z11,
           x12, y12, z12, x13, y13, z13, x14, y14, z14, x15, y15, z15, x16,
           y16, z16, x17, y17, z17, x18, y18, z18, x19, y19, z19, x20, y20,
           z20, x21, y21, z21, x22, y22, z22, x23, y23, z23, x24, y24, z24,
           x25, y25, z25, x26, y26, z26, x27, y27, z27, x28, y28, z28, x29,
           y29, z29, x30, y30, z30):

    print('Starting')

    image = one_color.main(boardsize_x, boardsize_y, 245, 245, 245)
    frame = TDviewDisplay.main(
        xVRP, yVRP, zVRP, d, a, b, xt, yt, sf, x1, y1, z1, x2, y2, z2, x3, y3,
        z3, x4, y4, z4, x5, y5, z5, x6, y6, z6, x7, y7, z7, x8, y8, z8, x9, y9,
        z9, x10, y10, z10, x11, y11, z11, x12, y12, z12, x13, y13, z13, x14,
        y14, z14, x15, y15, z15, x16, y16, z16, x17, y17, z17, x18, y18, z18,
        x19, y19, z19, x20, y20, z20, x21, y21, z21, x22, y22, z22, x23, y23,
        z23, x24, y24, z24, x25, y25, z25, x26, y26, z26, x27, y27, z27, x28,
        y28, z28, x29, y29, z29, x30, y30, z30)
    image = add_to_image.main(image, frame, 255, 0, 0)

    write_ppm.main(image, 'test')
    print('Finish')
            big_y = y2
            small_y = y1
        
        for y in range(small_y, big_y+1):
            temp.y = y

            #solve for corresponding x values using Eq. 2.4
            x_value = m_inverse*y - m_inverse*y1 + x1

            #Round x values to nearest integer value
            x_value = round(x_value)
            temp.x = int(x_value)

            #add x and y values to data structure
            points.append(copy.deepcopy(temp))

    del points[0]   # remove unused location
    return points

image = one_color.main(320,240,245,245,245)
image = add_to_image.main(image,fill_polygon(vertexes),255,0,255)
image = add_to_image.main(image,line(60,120,110,200),255,0,255)
image = add_to_image.main(image,line(110,200,110,150),255,0,255)
image = add_to_image.main(image,line(110,150,200,220),255,0,255)
image = add_to_image.main(image,line(200,220,160,120),255,0,255)
image = add_to_image.main(image,line(160,120,60,120),255,0,255)

write_ppm.main(image,'Chap2_Exercise7')

print 'printing done'
예제 #28
0
            temp.x = int(x_value)

            #add x and y values to data structure
            points.append(copy.deepcopy(temp))

    del points[0]  # remove unused location
    return points


# draw yellow background
image = one_color.main(150, 150, 255, 255, 58)

# draw black lines to differentiate 9 50x50 blocks
for i in range(0, len(line_list)):
    image = add_to_image.main(
        image,
        line(line_list[i][0][0], line_list[i][0][1], line_list[i][1][0],
             line_list[i][1][1]), 0, 0, 0)

#draw each number 1-8 according to number_list vertexes
for i in range(0, len(number_list)):
    for k in range(0, len(number_list[i])):
        if k == len(number_list[i]) - 1:
            pass
        else:
            image = add_to_image.main(
                image,
                line(number_list[i][k][0], number_list[i][k][1],
                     number_list[i][k + 1][0], number_list[i][k + 1][1]), 0, 0,
                0)

write_ppm.main(image, 'Chap2_Exercise9')
    x = vertexes[i][0]
    y = vertexes[i][1]
    vertexes[i][0] = int(
        round((x) * (math.cos(math.radians(rotation_angle))) - (y) *
              (math.sin(math.radians(rotation_angle)))))
    vertexes[i][1] = int(
        round((y) * (math.cos(math.radians(rotation_angle))) + (x) *
              (math.sin(math.radians(rotation_angle)))))

# translate end and start pts back
for i in range(0, len(vertexes)):
    vertexes[i][0] = vertexes[i][0] + rotation_point[0]
    vertexes[i][1] = vertexes[i][1] + rotation_point[1]

# draw the polygon
for i in range(0, len(vertexes)):
    if i == len(vertexes) - 1:
        image = add_to_image.main(
            image,
            line(vertexes[i][0], vertexes[i][1], vertexes[0][0],
                 vertexes[0][1]), 255, 0, 0)
    else:
        image = add_to_image.main(
            image,
            line(vertexes[i][0], vertexes[i][1], vertexes[i + 1][0],
                 vertexes[i + 1][1]), 255, 0, 0)

write_ppm.main(image, 'Chap3_Exercise7')

print 'printing done'
        if temp.x == 0:
            biglist.append([temp.x, temp.y])
            biglist.append([temp.x, -(temp.y)])
        else:
            biglist.append([temp.x, temp.y])
            biglist.append([-(temp.x), temp.y])
            biglist.append([-(temp.x), -(temp.y)])
            biglist.append([temp.x, -(temp.y)])

        if temp.x <= 0:
            break

    #add center point to all points
    for i in range(0, len(biglist)):
        temp.x = biglist[i][0] + center_x
        temp.y = biglist[i][1] + center_y

        biglist[i][0] = biglist[i][0] + center_x
        biglist[i][1] = biglist[i][1] + center_y

        #add updated/finalized points to data structure
        points.append(copy.deepcopy(temp))

    del points[0]  # remove unused location
    return points


image = one_color.main(320, 240, 245, 245, 245)
image = add_to_image.main(image, ellipse(50, 100, 160, 120), 0, 0, 0)
write_ppm.main(image, 'Chap2_Exercise3')
            big_y = y2
            small_y = y1
        
        for y in range(small_y, big_y+1):
            temp.y = y

            #solve for corresponding x values using Eq. 2.4
            x_value = m_inverse*y - m_inverse*y1 + x1

            #Round x values to nearest integer value
            x_value = round(x_value)
            temp.x = int(x_value)

            #add x and y values to data structure
            points.append(copy.deepcopy(temp))

    del points[0]   # remove unused location
    return points

image = one_color.main(320,240,245,245,245)

for i in range(0, len(vertexes)):
    if i == len(vertexes)-1:
        image = add_to_image.main(image,line(vertexes[i][0],vertexes[i][1],vertexes[0][0],vertexes[0][1]),255,0,255)
    else:
        image = add_to_image.main(image,line(vertexes[i][0],vertexes[i][1],vertexes[i+1][0],vertexes[i+1][1]),255,0,255)
    
write_ppm.main(image,'Chap2_Exercise4')

print 'printing done'
            small_y = y1

        for y in range(small_y, big_y + 1):
            temp.y = y

            #solve for corresponding x values using Eq. 2.4
            x_value = m_inverse * y - m_inverse * y1 + x1

            #Round x values to nearest integer value
            x_value = round(x_value)
            temp.x = int(x_value)

            #add x and y values to data structure
            points.append(copy.deepcopy(temp))

    del points[0]  # remove unused location
    return points


image = one_color.main(320, 240, 245, 245, 245)
image = add_to_image.main(image, fill_polygon(vertexes), 255, 0, 255)
image = add_to_image.main(image, line(60, 120, 110, 200), 255, 0, 255)
image = add_to_image.main(image, line(110, 200, 110, 150), 255, 0, 255)
image = add_to_image.main(image, line(110, 150, 200, 220), 255, 0, 255)
image = add_to_image.main(image, line(200, 220, 160, 120), 255, 0, 255)
image = add_to_image.main(image, line(160, 120, 60, 120), 255, 0, 255)

write_ppm.main(image, 'Chap2_Exercise7')

print 'printing done'
            points.append(copy.deepcopy(temp))

            counter = counter + 1

        rowlist = []
        smallest_holder = smallest_holder + 1

    del points[0]   # remove unused location
    return points


# Create image with a white background
image = one_color.main(320,240,255,255,255)

# Draw the head
image = add_to_image.main(image,fill_circle(head_circle[1],head_circle[0][0],head_circle[0][1]),255,255,0)
image = add_to_image.main(image,circle(head_circle[1],head_circle[0][0],head_circle[0][1]),0,0,0)

# Draw the neck
image = add_to_image.main(image,line(neck[0][0],neck[0][1],neck[1][0],neck[1][1]),0,0,0)

# Draw the body (polygon)
image = add_to_image.main(image,fill_polygon(body_vertexes),0,0,255)
for i in range(0, len(body_vertexes)):
    if i == len(body_vertexes)-1:
        image = add_to_image.main(image,line(body_vertexes[i][0],body_vertexes[i][1],body_vertexes[0][0],body_vertexes[0][1]),255,0,0)
    else:
        image = add_to_image.main(image,line(body_vertexes[i][0],body_vertexes[i][1],body_vertexes[i+1][0],body_vertexes[i+1][1]),255,0,0)

# Draw the right hand, fill it with color
image = add_to_image.main(image,fill_circle(right_hand_circle[1],right_hand_circle[0][0],right_hand_circle[0][1]),255,0,0)
            #Round x values to nearest integer value
            x_value = round(x_value)
            temp.x = int(x_value)

            #add x and y values to data structure
            points.append(copy.deepcopy(temp))

    del points[0]   # remove unused location
    return points

# draw yellow background
image = one_color.main(150,150,255,255,58)

# draw black lines to differentiate 9 50x50 blocks
for i in range(0, len(line_list)):
    image = add_to_image.main(image,line(line_list[i][0][0],line_list[i][0][1],line_list[i][1][0],line_list[i][1][1]),0,0,0)

# 1. Translate the lines for the number 4
# add xt, yt to the x values, y values
for i in range(0, len(number_list[4])):
    number_list[4][i][0] = number_list[4][i][0] + x_translation
    number_list[4][i][1] = number_list[4][i][1] + y_translation

#draw each number 1-8 according to number_list vertexes
for i in range(0, len(number_list)):
    for k in range(0, len(number_list[i])):
        if k == len(number_list[i])-1:
            pass
        else:
            image = add_to_image.main(image,line(number_list[i][k][0],number_list[i][k][1],number_list[i][k+1][0],number_list[i][k+1][1]),0,0,0)
    
            #add x and y values to data structure
            points.append(copy.deepcopy(temp))

    #compare x length, y length, if y length is longer...        
    elif y_length > x_length:
        m_inverse = float(x2-x1)/float(y2-y1)       # slope inverse

        #Find integer values from y1 to y2

        for y in range(y1, y2+1):
            temp.y = y

            #solve for corresponding x values using Eq. 2.4
            x_value = m_inverse*y - m_inverse*y1 + x1

            #Round x values to nearest integer value
            x_value = round(x_value)
            temp.x = int(x_value)

            #add x and y values to data structure
            points.append(copy.deepcopy(temp))

    del points[0]   # remove unused location
    return points

image = one_color.main(320,240,245,245,245)
image = add_to_image.main(image,line(60,120,160,120),255,0,0)
image = add_to_image.main(image,line(160,120,160,220),0,255,0)
write_ppm.main(image,'Chap2_Exercise1')
예제 #36
0
def StickFigure( boardsize_x, boardsize_y ):
    
    print ('Starting')
    
    image = one_color.main( boardsize_x, boardsize_y, 245, 245, 245 )
    
    head = draw_circle.main( 160, 200, 20 )
    headFill = fill_circle.main( 160, 200, 20 )
    
    neck = draw_line.main( 160, 180, 160, 170 )
    
    body = draw_polygon.main( 130, 170, 190, 170, 190, 110, 130, 110 )
    bodyFill = fill_polygon.main( 130, 170, 190, 170, 190, 110, 130, 110 )
    
    rArm = draw_line.main( 130, 170, 100, 100 )
    lArm = draw_line.main( 190, 170, 220, 100 )
    
    rHand = draw_circle.main( 100, 100, 10 )
    lHand = draw_circle.main( 220, 100, 10 )
    rHandFill = fill_circle.main( 100, 100, 10 )
    lHandFill = fill_circle.main( 220, 100, 10 )
    
    rLeg = draw_line.main( 140, 110, 120, 50 )
    lLeg = draw_line.main( 180, 110, 200, 50 )
    
    rFoot = draw_ellipse.main( 120, 50, 20, 5 )
    lFoot = draw_ellipse.main( 200, 50, 20, 5 )
    rFootFill = fill_ellipse.main( 120, 50, 20, 5 )
    lFootFill = fill_ellipse.main( 200, 50, 20, 5 )
    

    #Translate, Rotate, and Scale Flag/Pole

    pole = pole_composition.main( 100, 125, 100, 50, 0, 35, 100, 100, 45, 1.25, 1.25 )
    flagFill = flagFill_composition.main( 100, 125, 100, 95, 60, 110, 0, 35, 100, 100, 45, 1.25, 1.25 )
    flag = flag_composition.main( 100, 125, 100, 95, 60, 110, 0, 35, 100, 100, 45, 1.25, 1.25 )
    
    #Start adding pixels to fill
    image = add_to_image.main( image, headFill, 255, 255, 0 )
    image = add_to_image.main( image, head, 0, 0, 0 )
    
    image = add_to_image.main( image, neck, 0, 0, 0 )
    
    image = add_to_image.main( image, bodyFill, 0, 0, 255 )
    image = add_to_image.main( image, body, 255, 0, 0 )
    
    image = add_to_image.main( image, rArm, 0, 0, 0 )
    image = add_to_image.main( image, lArm, 0, 0, 0 )
    
    image = add_to_image.main( image, rHandFill, 255, 0, 0 )
    image = add_to_image.main( image, lHandFill, 255, 0, 0 )
    image = add_to_image.main( image, rHand, 0, 255, 0 )
    image = add_to_image.main( image, lHand, 0, 255, 0 )
    
    image = add_to_image.main( image, rLeg, 0, 0, 0 )
    image = add_to_image.main( image, lLeg, 0, 0, 0 )
    
    image = add_to_image.main( image, rFootFill, 0, 255, 0 )
    image = add_to_image.main( image, lFootFill, 0, 255, 0 )
    image = add_to_image.main( image, rFoot, 0, 0, 255 )
    image = add_to_image.main( image, lFoot, 0, 0, 255 )
    
    image = add_to_image.main( image, pole, 0, 0, 0 )
    
    image = add_to_image.main( image, flagFill, 255, 0 , 255 )
    image = add_to_image.main( image, flag, 0, 0, 0 )

    write_ppm.main( image, 'amos' )
    print ('Finish')
# draw light gray background
image = one_color.main(320,240,245,245,245)

# translate end and start pts to origin using translation algorithm
for i in range(0, len(line_list)):
    for k in range(0, len(line_list[i])):
        line_list[i][k][0] = line_list[i][k][0] - rotation_point[0]
        line_list[i][k][1] = line_list[i][k][1] - rotation_point[1]

# Rotate x values, y values, round them
for i in range(0, len(line_list)):
    for k in range(0, len(line_list[i])):
        x = line_list[i][k][0]
        y = line_list[i][k][1]
        line_list[i][k][0] = int(round((x)*(math.cos(math.radians(rotation_angle))) - (y)*(math.sin(math.radians(rotation_angle)))))
        line_list[i][k][1] = int(round((y)*(math.cos(math.radians(rotation_angle))) + (x)*(math.sin(math.radians(rotation_angle)))))

# translate end and start pts back
for i in range(0, len(line_list)):
    for k in range(0, len(line_list[i])):
        line_list[i][k][0] = line_list[i][k][0] + rotation_point[0]
        line_list[i][k][1] = line_list[i][k][1] + rotation_point[1]

image = add_to_image.main(image,line(line_list[0][0][0],line_list[0][0][1],line_list[0][1][0],line_list[0][1][1]),255,0,0)
image = add_to_image.main(image,line(line_list[1][0][0],line_list[1][0][1],line_list[1][1][0],line_list[1][1][1]),0,255,0)

write_ppm.main(image,'Chap3_Exercise2')

print 'printing done'
예제 #38
0
        for i in range(1, len(rowlist)):
            if rowlist[i][0]< smallest_x:
                smallest_x = rowlist[i][0]
                smallest_x_index = i
            if rowlist[i][0] > largest_x:
                largest_x = rowlist[i][0]
                largest_x_index = i

        # cycle through row and add all copy points
        counter = 0
        for i in range(rowlist[smallest_x_index][0],rowlist[largest_x_index][0]):
            temp.x = rowlist[smallest_x_index][0] + counter
            temp.y = rowlist[smallest_x_index][1]

            #add updated/finalized points to data structure
            points.append(copy.deepcopy(temp))

            counter = counter + 1

        rowlist = []
        smallest_holder = smallest_holder + 1

    del points[0]   # remove unused location
    return points

image = one_color.main(320,240,245,245,245)
image = add_to_image.main(image,circle(100,160,120),0,0,255)
write_ppm.main(image,'Chap2_Exercise5')

print 'printing done'
for i in range(0, len(line_list)):
    for k in range(0, len(line_list[i])):
        line_list[i][k][0] = int(round((line_list[i][k][0]) * (x_scale)))
        line_list[i][k][1] = int(round((line_list[i][k][1]) * (y_scale)))

# translate end and start pts back
for i in range(0, len(line_list)):
    for k in range(0, len(line_list[i])):
        line_list[i][k][0] = line_list[i][k][0] + fixed_point[0]
        line_list[i][k][1] = line_list[i][k][1] + fixed_point[1]

# 3. Translate the results
# add xt, yt to the x values, y values
for i in range(0, len(line_list)):
    for k in range(0, len(line_list[i])):
        line_list[i][k][0] = line_list[i][k][0] + x_translation
        line_list[i][k][1] = line_list[i][k][1] + y_translation

image = add_to_image.main(
    image,
    line(line_list[0][0][0], line_list[0][0][1], line_list[0][1][0],
         line_list[0][1][1]), 255, 0, 0)
image = add_to_image.main(
    image,
    line(line_list[1][0][0], line_list[1][0][1], line_list[1][1][0],
         line_list[1][1][1]), 0, 255, 0)

write_ppm.main(image, 'Chap3_Exercise4')

print 'printing done'
예제 #40
0
def StickFigure(boardsize_x, boardsize_y):

    print('Starting')

    image = one_color.main(boardsize_x, boardsize_y, 245, 245, 245)

    head = draw_circle.main(160, 200, 20)
    headFill = fill_circle.main(160, 200, 20)

    neck = draw_line.main(160, 180, 160, 170)

    body = draw_polygon.main(130, 170, 190, 170, 190, 110, 130, 110)
    bodyFill = fill_polygon.main(130, 170, 190, 170, 190, 110, 130, 110)

    rArm = draw_line.main(130, 170, 100, 100)
    lArm = draw_line.main(190, 170, 220, 100)

    rHand = draw_circle.main(100, 100, 10)
    lHand = draw_circle.main(220, 100, 10)
    rHandFill = fill_circle.main(100, 100, 10)
    lHandFill = fill_circle.main(220, 100, 10)

    rLeg = draw_line.main(140, 110, 120, 50)
    lLeg = draw_line.main(180, 110, 200, 50)

    rFoot = draw_ellipse.main(120, 50, 20, 5)
    lFoot = draw_ellipse.main(200, 50, 20, 5)
    rFootFill = fill_ellipse.main(120, 50, 20, 5)
    lFootFill = fill_ellipse.main(200, 50, 20, 5)

    #Translate, Rotate, and Scale Flag/Pole

    pole = pole_composition.main(100, 125, 100, 50, 0, 35, 100, 100, 45, 1.25,
                                 1.25)
    flagFill = flagFill_composition.main(100, 125, 100, 95, 60, 110, 0, 35,
                                         100, 100, 45, 1.25, 1.25)
    flag = flag_composition.main(100, 125, 100, 95, 60, 110, 0, 35, 100, 100,
                                 45, 1.25, 1.25)

    #Start adding pixels to fill
    image = add_to_image.main(image, headFill, 255, 255, 0)
    image = add_to_image.main(image, head, 0, 0, 0)

    image = add_to_image.main(image, neck, 0, 0, 0)

    image = add_to_image.main(image, bodyFill, 0, 0, 255)
    image = add_to_image.main(image, body, 255, 0, 0)

    image = add_to_image.main(image, rArm, 0, 0, 0)
    image = add_to_image.main(image, lArm, 0, 0, 0)

    image = add_to_image.main(image, rHandFill, 255, 0, 0)
    image = add_to_image.main(image, lHandFill, 255, 0, 0)
    image = add_to_image.main(image, rHand, 0, 255, 0)
    image = add_to_image.main(image, lHand, 0, 255, 0)

    image = add_to_image.main(image, rLeg, 0, 0, 0)
    image = add_to_image.main(image, lLeg, 0, 0, 0)

    image = add_to_image.main(image, rFootFill, 0, 255, 0)
    image = add_to_image.main(image, lFootFill, 0, 255, 0)
    image = add_to_image.main(image, rFoot, 0, 0, 255)
    image = add_to_image.main(image, lFoot, 0, 0, 255)

    image = add_to_image.main(image, pole, 0, 0, 0)

    image = add_to_image.main(image, flagFill, 255, 0, 255)
    image = add_to_image.main(image, flag, 0, 0, 0)

    write_ppm.main(image, 'amos')
    print('Finish')
            #solve for corresponding x values using Eq. 2.4
            x_value = m_inverse * y - m_inverse * y1 + x1

            #Round x values to nearest integer value
            x_value = round(x_value)
            temp.x = int(x_value)

            #add x and y values to data structure
            points.append(copy.deepcopy(temp))

    del points[0]  # remove unused location
    return points


image = one_color.main(150, 350, 245, 245, 245)
image = add_to_image.main(image, fill_polygon(vertexes), 255, 0, 255)

for i in range(0, len(vertexes)):
    if i == len(vertexes) - 1:
        image = add_to_image.main(
            image,
            line(vertexes[i][0], vertexes[i][1], vertexes[0][0],
                 vertexes[0][1]), 0, 0, 0)
    else:
        image = add_to_image.main(
            image,
            line(vertexes[i][0], vertexes[i][1], vertexes[i + 1][0],
                 vertexes[i + 1][1]), 0, 0, 0)

write_ppm.main(image, 'Chap2_Exercise8')
# translate end and start pts to origin using translation algorithm
for i in range(0, len(vertexes)):
    vertexes[i][0] = vertexes[i][0] - rotation_point[0]
    vertexes[i][1] = vertexes[i][1] - rotation_point[1]

# Rotate x values, y values, round them
for i in range(0, len(vertexes)):
    x = vertexes[i][0]
    y = vertexes[i][1]
    vertexes[i][0] = int(round((x)*(math.cos(math.radians(rotation_angle))) - (y)*(math.sin(math.radians(rotation_angle)))))
    vertexes[i][1] = int(round((y)*(math.cos(math.radians(rotation_angle))) + (x)*(math.sin(math.radians(rotation_angle)))))

# translate end and start pts back
for i in range(0, len(vertexes)):
    vertexes[i][0] = vertexes[i][0] + rotation_point[0]
    vertexes[i][1] = vertexes[i][1] + rotation_point[1]

# fill the polygon
image = add_to_image.main(image,fill_polygon(vertexes),255,0,0)

# re-draw the polygon
for i in range(0, len(vertexes)):
    if i == len(vertexes)-1:
        image = add_to_image.main(image,line(vertexes[i][0],vertexes[i][1],vertexes[0][0],vertexes[0][1]),255,0,0)
    else:
        image = add_to_image.main(image,line(vertexes[i][0],vertexes[i][1],vertexes[i+1][0],vertexes[i+1][1]),255,0,0)

write_ppm.main(image,'Chap3_Exercise8')

print 'printing done'
        #if x > 0, keep looping through looking to compute y values
        if temp.x == 0:
            biglist.append([temp.x, temp.y])
            biglist.append([temp.x, -(temp.y)])
        else:
            biglist.append([temp.x, temp.y])
            biglist.append([-(temp.x), temp.y])
            biglist.append([-(temp.x), -(temp.y)])
            biglist.append([temp.x, -(temp.y)])

        if temp.x <= 0:
            break

    #add center point to all points
    for i in range(0, len(biglist)):
        temp.x = biglist[i][0] + center_x
        temp.y = biglist[i][1] + center_y

        biglist[i][0] = biglist[i][0] + center_x
        biglist[i][1] = biglist[i][1] + center_y

        #add updated/finalized points to data structure
        points.append(copy.deepcopy(temp))

    del points[0]   # remove unused location
    return points

image = one_color.main(320,240,245,245,245)
image = add_to_image.main(image,ellipse(50,100,160,120),0,0,0)
write_ppm.main(image,'Chap2_Exercise3')
            #add x and y values to data structure
            points.append(copy.deepcopy(temp))

    #compare x length, y length, if y length is longer...
    elif y_length > x_length:
        m_inverse = float(x2 - x1) / float(y2 - y1)  # slope inverse

        #Find integer values from y1 to y2

        for y in range(y1, y2 + 1):
            temp.y = y

            #solve for corresponding x values using Eq. 2.4
            x_value = m_inverse * y - m_inverse * y1 + x1

            #Round x values to nearest integer value
            x_value = round(x_value)
            temp.x = int(x_value)

            #add x and y values to data structure
            points.append(copy.deepcopy(temp))

    del points[0]  # remove unused location
    return points


image = one_color.main(320, 240, 245, 245, 245)
image = add_to_image.main(image, line(60, 120, 160, 120), 255, 0, 0)
image = add_to_image.main(image, line(160, 120, 160, 220), 0, 255, 0)
write_ppm.main(image, 'Chap2_Exercise1')
        else:

            # compute other points on the circle  by symmetry
            biglist.append([temp.x, temp.y])
            biglist.append([temp.y, temp.x])
            biglist.append([-(temp.y), temp.x])
            biglist.append([-(temp.x), temp.y])
            biglist.append([-(temp.x), -(temp.y)])
            biglist.append([-(temp.y), -(temp.x)])
            biglist.append([temp.y, -(temp.x)])
            biglist.append([temp.x, -(temp.y)])

        if temp.x <= temp.y:
            break

    # add center point to all points
    for i in range(0, len(biglist)):
        temp.x = biglist[i][0] + center_x
        temp.y = biglist[i][1] + center_y

        # add updated/finalized points to data structure
        points.append(copy.deepcopy(temp))

    del points[0]  # remove unused location
    return points


image = one_color.main(320, 240, 245, 245, 245)
image = add_to_image.main(image, circle(100, 160, 120), 0, 0, 255)
write_ppm.main(image, "Chap2_Exercise2")