def main( x, y, r ):
    border = draw_circle.main( x, y, r )
    

    temp = one_color.struc()
    points = [ copy.deepcopy( one_color.struc ) ]
    length = len( border )

    for i in range( length - 1 ):
        for t in range( 1, length ):
            if border[ i ].y == border[ t ].y:
                fill = draw_line.main( border[ i ].x, border[ i ].y, border[ t ].x, border[ t ].y )
                length2 = len( fill )
                for e in range( length2 ):
                    temp.x = fill[ e ].x
                    temp.y = fill[ e ].y
                    points.append( copy.deepcopy( temp ) )
                #end e for loop
            #end of if-else statement
        #end of t for loop
    #end of i for loop
    
    del points[ 0 ]
    return points
                
        
Beispiel #2
0
def main(*args):
    temp = one_color.struc()
    points = [copy.deepcopy(one_color.struc)]

    length = len(args)
    for x1 in range(0, length - 3, 2):
        y1 = x1 + 1
        x2 = y1 + 1
        y2 = x2 + 1
        line = draw_line.main(args[x1], args[y1], args[x2], args[y2])
        length2 = len(line)
        for i in range(length2):
            temp.x = line[i].x
            temp.y = line[i].y
            points.append(copy.deepcopy(temp))

    line = draw_line.main(args[length - 2], args[length - 1], args[0], args[1])
    length2 = len(line)
    for i in range(length2):
        temp.x = line[i].x
        temp.y = line[i].y
        points.append(copy.deepcopy(temp))

    del points[0]
    return points
def main( *args ):
    temp = one_color.struc()
    points = [ copy.deepcopy( one_color.struc ) ]

    length = len( args )
    for x1 in range( 0, length - 3, 2 ):
        y1 = x1 + 1
        x2 = y1 + 1
        y2 = x2 + 1
        line = draw_line.main( args[ x1 ], args[ y1 ], args[ x2 ], args[ y2 ] )
        length2 = len( line )
        for i in range( length2 ):
            temp.x = line[ i ].x
            temp.y = line[ i ].y
            points.append( copy.deepcopy( temp ) )

    line = draw_line.main( args[ length - 2 ], args[ length - 1 ], args[ 0 ], args[ 1 ] )
    length2 = len( line )
    for i in range( length2 ):
            temp.x = line[ i ].x
            temp.y = line[ i ].y
            points.append( copy.deepcopy( temp ) )
    


    del points[ 0 ]         
    return points
def main(x1, y1, x2, y2, x3, y3, xt, yt, xf, yf, d, xs, ys):

    points = []
    temp = one_color.struc()

    line1 = translation.main(x1, y1, x2, y2, xt, yt)
    line2 = translation.main(x2, y2, x3, y3, xt, yt)
    line3 = translation.main(x3, y3, x1, y1, xt, yt)

    line1 = rotation.main(line1[0].x, line1[0].y, line1[1].x, line1[1].y, xf,
                          yf, d)
    line2 = rotation.main(line2[0].x, line2[0].y, line2[1].x, line2[1].y, xf,
                          yf, d)
    line3 = rotation.main(line3[0].x, line3[0].y, line3[1].x, line3[1].y, xf,
                          yf, d)

    line1 = scale.main(line1[0].x, line1[0].y, line1[1].x, line1[1].y, xf, yf,
                       xs, ys)
    line2 = scale.main(line2[0].x, line2[0].y, line2[1].x, line2[1].y, xf, yf,
                       xs, ys)
    line3 = scale.main(line3[0].x, line3[0].y, line3[1].x, line3[1].y, xf, yf,
                       xs, ys)

    line = draw_polygon.main(line1[0].x, line1[0].y, line2[0].x, line2[0].y,
                             line3[0].x, line3[0].y)

    return line
Beispiel #5
0
def main(d, xl, yl, sf, args):

    display = []
    transP = []
    scaleP = []
    temp = one_color.struc()

    #get projection points
    line = projection.main(d, args)
    length = len(line)

    #Find center point and max values
    xMax = line[0].x
    xMin = line[0].x
    yMax = line[0].y
    yMin = line[0].y
    for i in range(length):
        if line[i].x > xMax:
            xMax = line[i].x
        if line[i].x < xMin:
            xMin = line[i].x
        if line[i].y > yMax:
            yMax = line[i].y
        if line[i].x < xMin:
            yMin = line[i].y

    xc = (xMax + xMin) / 2
    yc = (yMax + yMin) / 2

    #Find translation amount based on center
    xt = xl - xc
    yt = yl - yc

    #Composite
    #translate, scale, and draw a line based on the points found

    for i in range(0, len(line) - 1, 2):
        point = translation.main(line[i].x, line[i].y, line[i + 1].x,
                                 line[i + 1].y, xt, yt)
        for i in range(len(point)):
            temp.x = point[i].x
            temp.y = point[i].y
            transP.append(copy.deepcopy(temp))
    for i in range(0, len(transP) - 1, 2):
        point = scale.main(transP[i].x, transP[i].y, transP[i + 1].x,
                           transP[i + 1].y, xl, yl, sf, sf)
        for i in range(len(point)):
            temp.x = point[i].x
            temp.y = point[i].y
            scaleP.append(copy.deepcopy(temp))
    for i in range(0, len(scaleP) - 1, 2):
        point = draw_line.main(scaleP[i].x, scaleP[i].y, scaleP[i + 1].x,
                               scaleP[i + 1].y)
        for i in range(len(point)):
            temp.x = point[i].x
            temp.y = point[i].y
            display.append(copy.deepcopy(temp))

    return display
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')
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')
def main(x1, y1, x2, y2, xt, yt):
    temp = one_color.struc()
    points = []

    temp.x = x1 + xt
    temp.y = y1 + yt
    points.append(copy.deepcopy(temp))

    temp.x = x2 + xt
    temp.y = y2 + yt
    points.append(copy.deepcopy(temp))

    return points
def line(x1, y1, x2, y2):

    temp = one_color.struc()
    points = [copy.deepcopy(one_color.struc)]

    increment = 1

    #Find absolute value of x length, y length
    x_length = abs(x1 - x2)
    y_length = abs(y1 - y2)

    #compare x length, y length, if x length is longer...
    if x_length >= y_length:
        m = float(y2-y1)/float(x2-x1)               # slope
        b = (-(float(y2-y1)/float(x2-x1)))*x1 + y1  # y-intercept

        #Find integer values from x1 to x2
        for x in range(x1, x2+1):
            temp.x = x

            #solve for corresponding y values using Eq. 2.1
            y_value = m * x + b

            #Round y values to nearest integer value
            y_value = round(y_value)
            temp.y = int(y_value)

            #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
def line(x1, y1, x2, y2):

    temp = one_color.struc()
    points = [copy.deepcopy(one_color.struc)]

    increment = 1

    #Find absolute value of x length, y length
    x_length = abs(x1 - x2)
    y_length = abs(y1 - y2)

    #compare x length, y length, if x length is longer...
    if x_length >= y_length:
        m = float(y2 - y1) / float(x2 - x1)  # slope
        b = (-(float(y2 - y1) / float(x2 - x1))) * x1 + y1  # y-intercept

        #Find integer values from x1 to x2
        for x in range(x1, x2 + 1):
            temp.x = x

            #solve for corresponding y values using Eq. 2.1
            y_value = m * x + b

            #Round y values to nearest integer value
            y_value = round(y_value)
            temp.y = int(y_value)

            #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
Beispiel #11
0
def main( d, args ):
    temp = one_color.struc()
    points = []

    #Turns every XYZ coordinate to its 2D equivalent
    length = len( args )
    for i in range( 0, length - 2, 3 ):
        yAP1 = ( args[ i + 1 ] * d ) / args[ i + 2 ]
        xAP1 = ( args[ i ] * d ) / args[ i + 2 ]
        temp.x = xAP1
        temp.y = yAP1
        points.append( copy.deepcopy( temp ) )

    return points
Beispiel #12
0
def main(line, scan):
    temp = one_color.struc()
    points = [copy.deepcopy(one_color.struc)]
    lineMax = 0

    length = len(line)
    if line[0].y < line[length - 1].y:
        start = line[0].y
        end = line[length - 1].y
    else:
        start = line[length - 1].y
        end = line[0].y

    #Line
    if line[length - 1].y - line[0].y == 0:
        #This is a horizontal line
        del points[0]
        return points

    #If scan line is not within the edge
    if scan not in range(start, end):
        del points[0]
        return points
    else:
        if line[0].y >= line[length - 1].y:
            #y1 is maximum
            lineMax = line[0].y
        elif line[0].y < line[length - 1].y:
            #y2 is maximum
            lineMax = line[length - 1].y

        if scan == lineMax:
            #Max vertex point, no intersection
            del points[0]
            return points
        elif scan in range(start, end) and scan != lineMax:
            frac = (line[length - 1].x - line[0].x) / (line[length - 1].y -
                                                       line[0].y)
            first = frac * scan
            second = (frac * line[0].y)
            third = first - second
            newX = third + line[0].x
            temp.x = round(newX)
            temp.y = scan
            points.append(copy.deepcopy(temp))

    del points[0]
    return points
def main( line, scan ):
    temp = one_color.struc()
    points = [ copy.deepcopy( one_color.struc ) ]
    lineMax = 0

    length = len( line )
    if line[ 0 ].y < line[ length - 1 ].y:
        start = line[ 0 ].y
        end = line[ length - 1 ].y
    else:
        start = line[ length - 1 ].y
        end = line[ 0 ].y

    
    #Line
    if line[ length - 1 ].y - line[ 0 ].y == 0:
        #This is a horizontal line
        del points[ 0 ]
        return points

    #If scan line is not within the edge
    if scan not in range( start, end ):
        del points[ 0 ]
        return points
    else:
        if line[ 0 ].y >= line[ length - 1 ].y:
            #y1 is maximum
            lineMax = line[ 0 ].y
        elif line[ 0 ].y < line[ length - 1 ].y:
            #y2 is maximum
            lineMax = line[ length - 1 ].y

        if scan == lineMax:
            #Max vertex point, no intersection
            del points[ 0 ]
            return points
        elif scan in range( start, end ) and scan != lineMax:
            frac = ( line[ length - 1 ].x - line[ 0 ].x ) / ( line[ length - 1 ].y - line[ 0 ].y )
            first = frac * scan
            second = ( frac * line[ 0 ].y )
            third = first - second
            newX = third + line[ 0 ].x
            temp.x = round( newX )
            temp.y = scan
            points.append( copy.deepcopy( temp ) )
            
    del points[ 0 ]
    return points
def main( x1, y1, x2, y2, x3, y3, xt, yt, xf, yf, d, xs, ys ):

    points = []
    temp = one_color.struc()

    line1 = translation.main( x1, y1, x2, y2, xt, yt )
    line2 = translation.main( x2, y2, x3, y3, xt, yt )
    line3 = translation.main( x3, y3, x1, y1, xt, yt )

    line1 = rotation.main( line1[ 0 ].x, line1[ 0 ].y, line1[ 1 ].x, line1[ 1 ].y, xf, yf, d )
    line2 = rotation.main( line2[ 0 ].x, line2[ 0 ].y, line2[ 1 ].x, line2[ 1 ].y, xf, yf, d )
    line3 = rotation.main( line3[ 0 ].x, line3[ 0 ].y, line3[ 1 ].x, line3[ 1 ].y, xf, yf, d )

    line1 = scale.main( line1[ 0 ].x, line1[ 0 ].y, line1[ 1 ].x, line1[ 1 ].y, xf, yf, xs, ys )
    line2 = scale.main( line2[ 0 ].x, line2[ 0 ].y, line2[ 1 ].x, line2[ 1 ].y, xf, yf, xs, ys )
    line3 = scale.main( line3[ 0 ].x, line3[ 0 ].y, line3[ 1 ].x, line3[ 1 ].y, xf, yf, xs, ys )

    
    line = fill_polygon.main( line1[ 0 ].x, line1[ 0 ].y, line2[ 0 ].x, line2[ 0 ].y, line3[ 0 ].x, line3[ 0 ].y )
    
    return line
def main( x, y, majA, minB ):
    border = draw_ellipse.main( x, y, majA, minB )
    

    temp = one_color.struc()
    points = [ copy.deepcopy( one_color.struc ) ]
    length = len( border )

    for i in range( length - 1 ):
        for t in range( 1, length ):
            if border[ i ].y == border[ t ].y:
                fill = draw_line.main( border[ i ].x, border[ i ].y, border[ t ].x, border[ t ].y )
                length2 = len( fill )
                for e in range( length2 ):
                    temp.x = fill[ e ].x
                    temp.y = fill[ e ].y
                    points.append( copy.deepcopy( temp ) )
                #end e for loop
            #end of if-else statement
        #end of t for loop
    #end of i for loop
    
    del points[ 0 ]
    return points
def fill_polygon(vertex_array):

    temp = one_color.struc()
    points = [copy.deepcopy(one_color.struc)]

    #find min y-value (ymin) and max y-value (y-max)
    smallest = vertex_array[0][1]
    smallest_index = 0
    largest = vertex_array[0][1]
    largest_index = 0
    
    for i in range(0, len(vertex_array)):
        if vertex_array[i][1] < smallest:
            smallest = vertex_array[i][1]
            smallest_index = i
        if vertex_array[i][1] > largest:
            largest = vertex_array[i][1]
            largest_index = i
    
    smallest_holder = smallest

    #For all the scan lines from ymin to ymax:
    for k in range(smallest, largest+1):

        intersections = []

        #For each edge:
        for j in range(0, len(vertex_array)):

            x_one = vertex_array[j][0]
            y_one = vertex_array[j][1]

            if j == len(vertex_array)-1:
                x_two = vertex_array[0][0]
                y_two = vertex_array[0][1]
            else:
                x_two = vertex_array[j+1][0]
                y_two = vertex_array[j+1][1]

            if y_two - y_one != 0:
                if (y_two <= smallest_holder <= y_one) or (y_one <= smallest_holder <= y_two):
                    y_max = y_one

                    # Find the y-value of the maximal vertex point

                    if y_one >= y_two :
                        y_max = y_one
                    elif y_one < y_two :
                        y_max = y_two

                    if (smallest_holder != y_max) and ((y_two <= smallest_holder <= y_one) or (y_one <= smallest_holder <= y_two)):
                        m_inverse = float(x_two-x_one)/float(y_two-y_one)       # slope inverse

                        x_value = m_inverse*smallest_holder - m_inverse*y_one + x_one
                        x_value = int(round(x_value))

                        temp.x = x_value
                        temp.y = smallest_holder

                        intersections.append([temp.x, temp.y])

        sorted(intersections, key=lambda x: x[0])
        
        for i in range(0, len(intersections), 2):
            
            counter = 0

            big_x = 0
            small_x = 0
            
            if intersections[i][0] > intersections[i+1][0]:
                big_x = intersections[i][0]
                small_x = intersections[i+1][0]
            else:
                big_x = intersections[i+1][0]
                small_x = intersections[i][0]
            
            for x in range(small_x, big_x+1):
                temp.x = small_x + counter
                temp.y = intersections[i][1]

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

                counter = counter + 1

        smallest_holder = smallest_holder + 1

    del points[0]   # remove unused location
    return points
def circle(radius, center_x, center_y):

    biglist = []  # data structure to hold points

    temp = one_color.struc()
    points = [copy.deepcopy(one_color.struc)]

    # initialize starting point to (r,0)
    temp.x = radius
    temp.y = 0

    # add points to temporary data structure
    biglist.append([temp.x, temp.y])
    biglist.append([temp.y, temp.x])
    biglist.append([-(temp.x), temp.y])
    biglist.append([temp.y, -(temp.x)])

    while True:

        # compute next y location for the first octant
        temp.y = temp.y + 1

        # compute the corresponding x value for y + 1 using Eq. 2.6
        temp.x = math.sqrt((pow(radius, 2.0)) - (pow(temp.y, 2.0)))

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

        # Check to see if points are still in first octant
        if temp.x == temp.y:

            # compute other points on the circle  by symmetry
            # Don't compute duplicate coordinates
            biglist.append([temp.x, temp.y])
            biglist.append([-(temp.x), temp.y])
            biglist.append([-(temp.x), -(temp.y)])
            biglist.append([temp.x, -(temp.y)])
        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
def fill_polygon(vertex_array):

    temp = one_color.struc()
    points = [copy.deepcopy(one_color.struc)]

    #find min y-value (ymin) and max y-value (y-max)
    smallest = vertex_array[0][1]
    smallest_index = 0
    largest = vertex_array[0][1]
    largest_index = 0

    for i in range(0, len(vertex_array)):
        if vertex_array[i][1] < smallest:
            smallest = vertex_array[i][1]
            smallest_index = i
        if vertex_array[i][1] > largest:
            largest = vertex_array[i][1]
            largest_index = i

    smallest_holder = smallest

    #For all the scan lines from ymin to ymax:
    for k in range(smallest, largest + 1):
        ##        print 'Scan line, y =', k

        intersections = []

        #For each edge:
        for j in range(0, len(vertex_array)):

            x_one = vertex_array[j][0]
            y_one = vertex_array[j][1]

            if j == len(vertex_array) - 1:
                x_two = vertex_array[0][0]
                y_two = vertex_array[0][1]
            else:
                x_two = vertex_array[j + 1][0]
                y_two = vertex_array[j + 1][1]

            if y_two - y_one != 0:
                if (y_two <= smallest_holder <=
                        y_one) or (y_one <= smallest_holder <= y_two):
                    y_max = y_one

                    # Find the y-value of the maximal vertex point

                    if y_one >= y_two:
                        y_max = y_one
                    elif y_one < y_two:
                        y_max = y_two

                    if (smallest_holder != y_max) and (
                        (y_two <= smallest_holder <= y_one) or
                        (y_one <= smallest_holder <= y_two)):
                        m_inverse = float(x_two - x_one) / float(
                            y_two - y_one)  # slope inverse

                        x_value = m_inverse * smallest_holder - m_inverse * y_one + x_one
                        x_value = int(round(x_value))

                        temp.x = x_value
                        temp.y = smallest_holder

                        intersections.append([temp.x, temp.y])

##        print 'intersections before sorting', intersections

# TODO: sorted algorthim/function not working

        intersections = sorted(intersections, key=lambda x: x[0])

        ##        print 'intersections', intersections, '\n'

        for i in range(0, len(intersections), 2):

            counter = 0
            for m in range(intersections[i][0], intersections[i + 1][0]):

                temp.x = intersections[i][0] + counter
                temp.y = intersections[i][1]

                #DEBUG
                ##                print 'temp x', temp.x, 'temp y', temp.y, '\n'

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

                counter = counter + 1

        smallest_holder = smallest_holder + 1

    del points[0]  # remove unused location
    return points
def ellipse(a,b, center_x, center_y):
    # a == major axis
    # b == minor axis
    
    biglist = []        #data structure to hold points

    temp = one_color.struc()
    points = [copy.deepcopy(one_color.struc)]

    #initialize starting point to (a,0)
    temp.x = a
    temp.y = 0
    
    biglist.append([temp.x, temp.y])
    biglist.append([-(temp.x), temp.y])

    while True:

        #check to see if in region 2
        if ((pow(a, 2.0))*(temp.y +1)) < ((pow(b, 2.0))*(temp.x - 0.5)):

            #compute next y location for region 2
            temp.y = temp.y +1

            #compute the corresponding x value for y + 1 using Eq. 2.8
            temp.x = math.sqrt( (pow(a, 2.0)) * ( 1 - ((pow(temp.y, 2.0))/(pow(b, 2.0)))  ) )

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

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

            #check if still in region 2, if not move on
            if ((pow(a, 2.0))*(temp.y+1)) >= ((pow(b, 2.0))*(temp.x-.5)):
                break
        #if not in region 2, move on to region 1
        else:
            break

    while True:

        #compute next x location for region 1
        temp.x = temp.x - 1

        #compute the y value for x - 1 using Eq. 2.9
        temp.y = math.sqrt( (pow(b, 2.0)) * ( 1 - ((pow(temp.x, 2.0))/(pow(a, 2.0)))  ) )

        #Round to the nearest integer
        temp.y = int(round(temp.y))

        #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
def fill_polygon(vertex_array):

    temp = one_color.struc()
    points = [copy.deepcopy(one_color.struc)]

    #find min y-value (ymin) and max y-value (y-max)
    smallest = vertex_array[0][1]
    smallest_index = 0
    largest = vertex_array[0][1]
    largest_index = 0
    
    for i in range(0, len(vertex_array)):
        if vertex_array[i][1] < smallest:
            smallest = vertex_array[i][1]
            smallest_index = i
        if vertex_array[i][1] > largest:
            largest = vertex_array[i][1]
            largest_index = i

    #DEBUG print 'smallest', smallest, '||| largest', largest
    
    smallest_holder = smallest

    #For all the scan lines from ymin to ymax:
    for k in range(smallest, largest+1):

        intersections = []

        #For each edge:
        for j in range(0, len(vertex_array)):

            x_one = vertex_array[j][0]
            y_one = vertex_array[j][1]

            if j == len(vertex_array)-1:
                x_two = vertex_array[0][0]
                y_two = vertex_array[0][1]
            else:
                x_two = vertex_array[j+1][0]
                y_two = vertex_array[j+1][1]

            if y_two - y_one != 0:
                if (y_two <= smallest_holder <= y_one) or (y_one <= smallest_holder <= y_two):
                    y_max = y_one

                    # Find the y-value of the maximal vertex point

                    if y_one >= y_two :
                        y_max = y_one
                    elif y_one < y_two :
                        y_max = y_two

                    if (smallest_holder != y_max) and ((y_two <= smallest_holder <= y_one) or (y_one <= smallest_holder <= y_two)):
                        m_inverse = float(x_two-x_one)/float(y_two-y_one)       # slope inverse

                        x_value = m_inverse*smallest_holder - m_inverse*y_one + x_one
                        x_value = int(round(x_value))

                        temp.x = x_value
                        temp.y = smallest_holder

                        intersections.append([temp.x, temp.y])

        sorted(intersections, key=lambda x: x[0])
        
        for i in range(0, len(intersections), 2):
            
            counter = 0

            big_x = 0
            small_x = 0
            
            if intersections[i][0] > intersections[i+1][0]:
                big_x = intersections[i][0]
                small_x = intersections[i+1][0]
            else:
                big_x = intersections[i+1][0]
                small_x = intersections[i][0]
            
            for x in range(small_x, big_x+1):
                temp.x = small_x + counter
                temp.y = intersections[i][1]

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

                counter = counter + 1

        smallest_holder = smallest_holder + 1

    del points[0]   # remove unused location
    return points
Beispiel #21
0
def main( *args ):
    temp = one_color.struc()
    points = [ copy.deepcopy( one_color.struc ) ]
    fillpoints = [ copy.deepcopy( one_color.struc ) ]
    del points[ 0 ]
    del fillpoints[ 0 ]

    
    #find the smallest and largest y values
    #will be used as the limit of scan line
    minY = args[ 0 ]
    maxY = args[ 0 ]
    length = len( args )
    for i in range( 1, length, 2 ):
        if args[ i ] < minY:
            minY = args[ i ]
        elif args[ i ] > maxY:
            maxY = args[ i ]
        #end of if-else statement
    #end of i for loop
    print( 'Found scan borders' )
    print( 'minY = ', minY )
    print( 'maxY = ', maxY )

    scan = minY + 1
    start = 0
    while scan < maxY:
        while start <= length - 4:
            #find scan intersection with all sides except last side
            y1 = start + 1
            x2 = y1 + 1
            y2 = x2 + 1
            line = draw_line.main( args[ start ], args[ y1 ], args[ x2 ], args[ y2 ] )
                
            point = scan_line.main( line, scan )
            if len( point ) == 0:
                start = start + 2
            else:
                points = points + point
                start = start + 2
        
        #If on the last side find its scan intersection
        line = draw_line.main( args[ length - 2 ], args[ length - 1 ], args[ 0 ], args[ 1 ] )
        point = scan_line.main( line, scan )            
        if len( point ) == 0:
            pass
        else:
            points = points + point

                
        #Begin of sort
        lengthp = len( points )
        done = False
        head = 0
        tail = 1
        while done == True:
            check = 0
            if check == lengthp - 1:
                done = False
                    
            if tail >= lengthp:
                head = 0
                tail = 1
                        
            if points[ head ].x > points[ tail ].x:
                temp = points[ tail ]
                points[ tail ] = points[ head ]
                points[ head ] = temp
                head = head + 1
                tail = tail + 1
            else:
                head = head + 1
                tail = tail + 1
                check = check + 1
        #End of while loop

        #Get pairs of points that need to be filled
        head = 0
        tail = 1
        while head < lengthp - 1:
            fill = draw_line.main( points[ head ].x, points[ head ].y, points[ tail ].x, points[ tail ].y )
            fillpoints = fillpoints + fill
            #end of i for loop
            head = head + 2
            tail = tail + 2

        del points[ : ]
        scan = scan + 1
        start = 0

    

    return fillpoints
Beispiel #22
0
def main( x1, y1, x2, y2 ):
    temp = one_color.struc()
    linepoints = [ copy.deepcopy( one_color.struc ) ]
    xLen = abs( x1 - x2 )
    yLen = abs( y1 - y2 )

    temp.x = x1
    temp.y = y1
    linepoints.append( copy.deepcopy( temp ) )
    
    if xLen > yLen:
        if x2 > x1:
            for i in range( x1 + 1, x2 ):
                temp.x = i
                m = ( y2 - y1 ) / ( x2 - x1 )
                first = -1 * m
                second = first * x1
                b = second + y1
                yPoint = ( m * i ) + b
                temp.y = round( yPoint )
                linepoints.append( copy.deepcopy( temp ) )
            #end for loop on i
        else:
            for i in range( x1 - 1, x2, -1 ):
                temp.x = i
                m = ( y2 - y1 ) / ( x2 - x1 )
                first = -1 * m
                second = first * x1
                b = second + y1
                yPoint = ( m * i ) + b
                temp.y = round( yPoint )
                linepoints.append( copy.deepcopy( temp ) )
            #end for loop on i
            
    else:
        if y2 > y1:
            for t in range( y1 + 1, y2 ):
                temp.y = t
                #break function into smaller parts
                fraction = ( x2 - x1 ) / ( y2 - y1 )
                first = fraction * t
                second = ( fraction * y1 )
                third = first - second
                xPoint = third + x1
                temp.x = round( xPoint )
                linepoints.append( copy.deepcopy( temp ) )
            #end for loop on t
        else:
            for t in range( y1 - 1, y2, -1 ):
                temp.y = t
                #break function into smaller parts
                fraction = ( x2 - x1 ) / ( y2 - y1 )
                first = fraction * t
                second = ( fraction * y1 )
                third = first - second
                xPoint = third + x1
                temp.x = round( xPoint )
                linepoints.append( copy.deepcopy( temp ) )
            #end for loop on t
    #end if else statement
    temp.x = x2
    temp.y = y2
    linepoints.append( copy.deepcopy( temp ) )
    
    del linepoints[ 0 ] #remove ununsed locatation

    length = len( linepoints )

    return linepoints
def fill_ellipse(a,b, center_x, center_y):
    # a == major axis
    # b == minor axis
    
    biglist = []        #data structure to hold points

    temp = one_color.struc()
    points = [copy.deepcopy(one_color.struc)]

    #initialize starting point to (a,0)
    temp.x = a
    temp.y = 0
    
    biglist.append([temp.x, temp.y])
    biglist.append([-(temp.x), temp.y])

    while True:

        #check to see if in region 2
        if ((pow(a, 2.0))*(temp.y +1)) < ((pow(b, 2.0))*(temp.x - 0.5)):

            #compute next y location for region 2
            temp.y = temp.y +1

            #compute the corresponding x value for y + 1 using Eq. 2.8
            temp.x = math.sqrt( (pow(a, 2.0)) * ( 1 - ((pow(temp.y, 2.0))/(pow(b, 2.0)))  ) )

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

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

            #check if still in region 2, if not move on
            if ((pow(a, 2.0))*(temp.y+1)) >= ((pow(b, 2.0))*(temp.x-.5)):
                break
        #if not in region 2, move on to region 1
        else:
            break

    while True:

        #compute next x location for region 1
        temp.x = temp.x - 1

        #compute the y value for x - 1 using Eq. 2.9
        temp.y = math.sqrt( (pow(b, 2.0)) * ( 1 - ((pow(temp.x, 2.0))/(pow(a, 2.0)))  ) )

        #Round to the nearest integer
        temp.y = int(round(temp.y))

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

    smallest = biglist[0][1]
    smallest_index = 0
    largest = biglist[0][1]
    largest_index = 0

    #Find minimum and maximum y values of the circle and their indexes
    for i in range(1, len(biglist)):
        if biglist[i][1]< smallest:
            smallest = biglist[i][1]
            smallest_index = i
        if biglist[i][1] > largest:
            largest = biglist[i][1]
            largest_index = i
            
    left_boundary_index = smallest_index
    right_boundary_index = smallest_index

    smallest_holder = smallest
    
    for k in range(smallest, largest+1):
        
        # list for holding values as we iterate through each row
        rowlist = []


        #find all points in circle with this common y value
        for i in range(0, len(biglist)):
            if biglist[i][1] == (smallest_holder):
                rowlist.append(biglist[i])

        smallest_x = rowlist[0][0]
        smallest_x_index = 0
        largest_x = rowlist[0][0]
        largest_x_index = 0

        #Find points in row that have largest and smallest x values
        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
def main( x, y, majA, minB ):
    temp = one_color.struc()
    points = [ copy.deepcopy( one_color.struc ) ]
    xC = majA
    yC = 0
    quadrant = 2
    half = 1 / 2
    aSquared = pow( majA, 2 )
    bSquared = pow( minB, 2 )

    temp.x = xC
    temp.y = yC
    points.append( copy.deepcopy( temp ) )

    accept1 = True
    accept2 = True
    
    #In region 2
    while accept1:
        if ( aSquared * ( yC + 1 ) ) < ( bSquared * ( xC - half ) ):
            yC = yC + 1
            ySquared = pow( yC, 2 )

            #Find the next x and y values
            frac = ySquared / bSquared
            minusFrac = 1 - frac
            times = aSquared * minusFrac
            xC = math.sqrt( times )
            xC = round( xC )
            temp.x = xC
            temp.y = yC
            points.append( copy.deepcopy( temp ) )
            if ( aSquared * ( yC + 1 ) ) >= ( bSquared * ( xC - half ) ):
                accept1 = False

    #In region 1
    while accept2:
        xC = xC - 1
        xSquared = pow( xC, 2 )

        #Find the next x and y values
        frac = xSquared / aSquared
        minusFrac = 1 - frac
        times = bSquared * minusFrac
        yC = math.sqrt( times )
        yC = round( yC )            
        temp.x = xC
        temp.y = yC
        points.append( copy.deepcopy( temp ) )
        if xC <= 0:
            accept2 = False
            

    length = len( points )
    #Find all other symetric points
    while quadrant <= 4:       
        for c in range( 1, length ):
            if quadrant == 2:
                newVal = points[ c ]
                temp.x = -1 * newVal.x
                temp.y = newVal.y
                points.append( copy.deepcopy( temp ) )
            elif quadrant == 3:
                newVal = points[ c ]
                temp.x = -1 * newVal.x
                temp.y = -1 * newVal.y
                points.append( copy.deepcopy( temp ) )
            elif quadrant == 4:
                newVal = points[ c ]
                temp.x = newVal.x
                temp.y = -1 * newVal.y
                points.append( copy.deepcopy( temp ) )
            else:
                print( 'There was an error' )
            #end inner if-else statements
        #end c for loop
        quadrant = quadrant + 1
    #end of while loop

    length = len( points )              
    for f in range( 1, length ):
        points[ f ].y = points[ f ].y + y
        points[ f ].x = points[ f ].x + x

    del points[ 0 ]
    return points
def main(x1, y1, x2, y2, x3, y3, x4, y4, x5, y5, x6, y6, x7, y7, x8, y8, x9,
         y9):
    temp = one_color.struc()
    points = [copy.deepcopy(one_color.struc)]
    fillpoints = [copy.deepcopy(one_color.struc)]
    del points[0]
    del fillpoints[0]

    #Get all the points in an edge
    line1 = [x1, y1, x2, y2]
    line2 = [x2, y2, x3, y3]
    line3 = [x3, y3, x4, y4]
    line4 = [x4, y4, x5, y5]
    line5 = [x5, y5, x6, y6]
    line6 = [x6, y6, x7, y7]
    line7 = [x7, y7, x8, y8]
    line8 = [x8, y8, x9, y9]
    line9 = [x9, y9, x1, y1]

    border = draw_polygon.main(x1, y1, x2, y2, x3, y3, x4, y4, x5, y5, x6, y6,
                               x7, y7, x8, y8, x9, y9)
    length = len(border)

    #find the smallest and largest y values
    #will be used as the limit of scan line
    minY = border[0].y
    maxY = border[0].y
    for i in range(length):
        if border[i].y < minY:
            minY = border[i].y
        elif border[i].y > maxY:
            maxY = border[i].y
        #end of if-else statement
    #end of i for loop
    print('Found scan borders')
    print('minY = ', minY)
    print('maxY = ', maxY)

    #Find all the intersection points in the edges
    #with the scan line
    scan = minY + 1
    while scan < maxY:

        point1 = scan_line.main(line1, scan)
        point2 = scan_line.main(line2, scan)
        point3 = scan_line.main(line3, scan)
        point4 = scan_line.main(line4, scan)
        point5 = scan_line.main(line5, scan)
        point6 = scan_line.main(line6, scan)
        point7 = scan_line.main(line7, scan)
        point8 = scan_line.main(line8, scan)
        point9 = scan_line.main(line9, scan)

        if len(point1) == 0:
            pass
        else:
            points = points + point1

        if len(point2) == 0:
            pass
        else:
            points = points + point2

        if len(point3) == 0:
            pass
        else:
            points = points + point3

        if len(point4) == 0:
            pass
        else:
            points = points + point4

        if len(point5) == 0:
            pass
        else:
            points = points + point5

        if len(point6) == 0:
            pass
        else:
            points = points + point6

        if len(point7) == 0:
            pass
        else:
            points = points + point7

        if len(point8) == 0:
            pass
        else:
            points = points + point8

        if len(point9) == 0:
            pass
        else:
            points = points + point9

        #Begin of sort
        length = len(points)
        print(length)
        done = False
        head = 0
        tail = 1
        while done == True:
            check = 0
            if check == length - 1:
                done = False

            if tail >= length:
                head = 0
                tail = 1

            if points[head].x > points[tail].x:
                temp = points[tail]
                points[tail] = points[head]
                points[head] = temp
                head = head + 1
                tail = tail + 1
            else:
                head = head + 1
                tail = tail + 1
                check = check + 1
        #End of while loop

        #Get pairs of points that need to be filled
        head = 0
        tail = 1
        while head < length - 1:
            fill = draw_line.main(points[head].x, points[head].y,
                                  points[tail].x, points[tail].y)
            fillpoints = fillpoints + fill
            #end of i for loop
            head = head + 2
            tail = tail + 2

        del points[:]
        scan = scan + 1

    #add border points

    return fillpoints
def main( x1, y1, x2, y2, x3, y3, x4, y4, x5, y5, x6, y6, x7, y7, x8, y8, x9, y9 ):
    temp = one_color.struc()
    points = [ copy.deepcopy( one_color.struc ) ]
    fillpoints = [ copy.deepcopy( one_color.struc ) ]
    del points[ 0 ]
    del fillpoints[ 0 ]

    #Get all the points in an edge
    line1 = [ x1, y1, x2, y2 ]
    line2 = [ x2, y2, x3, y3 ]
    line3 = [ x3, y3, x4, y4 ]
    line4 = [ x4, y4, x5, y5 ]
    line5 = [ x5, y5, x6, y6 ]
    line6 = [ x6, y6, x7, y7 ]
    line7 = [ x7, y7, x8, y8 ]
    line8 = [ x8, y8, x9, y9 ]
    line9 = [ x9, y9, x1, y1 ]
    
    
    border = draw_polygon.main( x1, y1, x2, y2, x3, y3, x4, y4, x5, y5, x6, y6, x7, y7, x8, y8, x9, y9 )
    length = len( border )

    
    #find the smallest and largest y values
    #will be used as the limit of scan line
    minY = border[ 0 ].y
    maxY = border[ 0 ].y
    for i in range( length ):
        if border[ i ].y < minY:
            minY = border[ i ].y
        elif border[ i ].y > maxY:
            maxY = border[ i ].y
        #end of if-else statement
    #end of i for loop
    print( 'Found scan borders' )
    print( 'minY = ', minY )
    print( 'maxY = ', maxY )

    #Find all the intersection points in the edges
    #with the scan line
    scan = minY + 1
    while scan < maxY:
    
        point1 = scan_line.main( line1, scan )
        point2 = scan_line.main( line2, scan )
        point3 = scan_line.main( line3, scan )
        point4 = scan_line.main( line4, scan )
        point5 = scan_line.main( line5, scan )
        point6 = scan_line.main( line6, scan )
        point7 = scan_line.main( line7, scan )
        point8 = scan_line.main( line8, scan )
        point9 = scan_line.main( line9, scan )

        if len( point1 ) == 0:
            pass
        else:
            points = points + point1
            
        if len( point2 ) == 0:
            pass
        else:
            points = points + point2
            
        if len( point3 ) == 0:
            pass
        else:
            points = points + point3

        if len( point4 ) == 0:
            pass
        else:
            points = points + point4

        if len( point5 ) == 0:
            pass
        else:
            points = points + point5

        if len( point6 ) == 0:
            pass
        else:
            points = points + point6
            
        if len( point7 ) == 0:
            pass
        else:
            points = points + point7

        if len( point8 ) == 0:
            pass
        else:
            points = points + point8

        if len( point9 ) == 0:
            pass
        else:
            points = points + point9

    
        #Begin of sort
        length = len( points )
        print( length )
        done = False
        head = 0
        tail = 1
        while done == True:
            check = 0
            if check == length - 1:
                done = False
                
            if tail >= length:
                head = 0
                tail = 1
                    
            if points[ head ].x > points[ tail ].x:
                temp = points[ tail ]
                points[ tail ] = points[ head ]
                points[ head ] = temp
                head = head + 1
                tail = tail + 1
            else:
                head = head + 1
                tail = tail + 1
                check = check + 1
        #End of while loop

        #Get pairs of points that need to be filled
        head = 0
        tail = 1
        while head < length - 1:
            fill = draw_line.main( points[ head ].x, points[ head ].y, points[ tail ].x, points[ tail ].y )
            fillpoints = fillpoints + fill
            #end of i for loop
            head = head + 2
            tail = tail + 2

        del points[ : ]
        scan = scan + 1

    #add border points
    



    return fillpoints
def circle(radius, center_x, center_y):

    biglist = []  #data structure to hold points

    temp = one_color.struc()
    points = [copy.deepcopy(one_color.struc)]

    #initialize starting point to (r,0)
    temp.x = radius
    temp.y = 0

    #add points to temporary data structure
    biglist.append([temp.x, temp.y])
    biglist.append([temp.y, temp.x])
    biglist.append([-(temp.x), temp.y])
    biglist.append([temp.y, -(temp.x)])

    while True:

        #compute next y location for the first octant
        temp.y = temp.y + 1

        #compute the corresponding x value for y + 1 using Eq. 2.6
        temp.x = math.sqrt((pow(radius, 2.0)) - (pow(temp.y, 2.0)))

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

        #Check to see if points are still in first octant
        if temp.x == temp.y:

            #compute other points on the circle  by symmetry
            #Don't compute duplicate coordinates
            biglist.append([temp.x, temp.y])
            biglist.append([-(temp.x), temp.y])
            biglist.append([-(temp.x), -(temp.y)])
            biglist.append([temp.x, -(temp.y)])
        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
Beispiel #28
0
def circle(radius, center_x, center_y):

    biglist = []        #data structure to hold points

    temp = one_color.struc()
    points = [copy.deepcopy(one_color.struc)]

    #initialize starting point to (r,0)
    temp.x = radius
    temp.y = 0

    #add points to temporary data structure
    biglist.append([temp.x, temp.y])
    biglist.append([temp.y, temp.x])
    biglist.append([-(temp.x), temp.y])
    biglist.append([temp.y, -(temp.x)])

    while True:

        #compute next y location for the first octant
        temp.y = temp.y + 1

        #compute the corresponding x value for y + 1 using Eq. 2.6
        temp.x = math.sqrt((pow(radius, 2.0)) - (pow(temp.y, 2.0)))

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

        #Check to see if points are still in first octant
        if temp.x == temp.y:

            #compute other points on the circle  by symmetry
            #Don't compute duplicate coordinates
            biglist.append([temp.x, temp.y])
            biglist.append([-(temp.x), temp.y])
            biglist.append([-(temp.x), -(temp.y)])
            biglist.append([temp.x, -(temp.y)])
        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
        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))

    smallest = biglist[0][1]
    smallest_index = 0
    largest = biglist[0][1]
    largest_index = 0

    #Find minimum and maximum y values of the circle and their indexes
    for i in range(1, len(biglist)):
        if biglist[i][1]< smallest:
            smallest = biglist[i][1]
            smallest_index = i
        if biglist[i][1] > largest:
            largest = biglist[i][1]
            largest_index = i
            
    left_boundary_index = smallest_index
    right_boundary_index = smallest_index

    smallest_holder = smallest
    
    for k in range(smallest, largest+1):
        
        # list for holding values as we iterate through each row
        rowlist = []


        #find all points in circle with this common y value
        for i in range(0, len(biglist)):
            if biglist[i][1] == (smallest_holder):
                rowlist.append(biglist[i])

        smallest_x = rowlist[0][0]
        smallest_x_index = 0
        largest_x = rowlist[0][0]
        largest_x_index = 0

        #Find points in rowlist that have largest and smallest x values
        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
Beispiel #29
0
def main(x, y, majA, minB):
    temp = one_color.struc()
    points = [copy.deepcopy(one_color.struc)]
    xC = majA
    yC = 0
    quadrant = 2
    half = 1 / 2
    aSquared = pow(majA, 2)
    bSquared = pow(minB, 2)

    temp.x = xC
    temp.y = yC
    points.append(copy.deepcopy(temp))

    accept1 = True
    accept2 = True

    #In region 2
    while accept1:
        if (aSquared * (yC + 1)) < (bSquared * (xC - half)):
            yC = yC + 1
            ySquared = pow(yC, 2)

            #Find the next x and y values
            frac = ySquared / bSquared
            minusFrac = 1 - frac
            times = aSquared * minusFrac
            xC = math.sqrt(times)
            xC = round(xC)
            temp.x = xC
            temp.y = yC
            points.append(copy.deepcopy(temp))
            if (aSquared * (yC + 1)) >= (bSquared * (xC - half)):
                accept1 = False

    #In region 1
    while accept2:
        xC = xC - 1
        xSquared = pow(xC, 2)

        #Find the next x and y values
        frac = xSquared / aSquared
        minusFrac = 1 - frac
        times = bSquared * minusFrac
        yC = math.sqrt(times)
        yC = round(yC)
        temp.x = xC
        temp.y = yC
        points.append(copy.deepcopy(temp))
        if xC <= 0:
            accept2 = False

    length = len(points)
    #Find all other symetric points
    while quadrant <= 4:
        for c in range(1, length):
            if quadrant == 2:
                newVal = points[c]
                temp.x = -1 * newVal.x
                temp.y = newVal.y
                points.append(copy.deepcopy(temp))
            elif quadrant == 3:
                newVal = points[c]
                temp.x = -1 * newVal.x
                temp.y = -1 * newVal.y
                points.append(copy.deepcopy(temp))
            elif quadrant == 4:
                newVal = points[c]
                temp.x = newVal.x
                temp.y = -1 * newVal.y
                points.append(copy.deepcopy(temp))
            else:
                print('There was an error')
            #end inner if-else statements
        #end c for loop
        quadrant = quadrant + 1
    #end of while loop

    length = len(points)
    for f in range(1, length):
        points[f].y = points[f].y + y
        points[f].x = points[f].x + x

    del points[0]
    return points
def ellipse(a, b, center_x, center_y):
    # a == major axis
    # b == minor axis

    biglist = []  #data structure to hold points

    temp = one_color.struc()
    points = [copy.deepcopy(one_color.struc)]

    #initialize starting point to (a,0)
    temp.x = a
    temp.y = 0

    biglist.append([temp.x, temp.y])
    biglist.append([-(temp.x), temp.y])

    while True:

        #check to see if in region 2
        if ((pow(a, 2.0)) * (temp.y + 1)) < ((pow(b, 2.0)) * (temp.x - 0.5)):

            #compute next y location for region 2
            temp.y = temp.y + 1

            #compute the corresponding x value for y + 1 using Eq. 2.8
            temp.x = math.sqrt(
                (pow(a, 2.0)) * (1 - ((pow(temp.y, 2.0)) / (pow(b, 2.0)))))

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

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

            #check if still in region 2, if not move on
            if ((pow(a, 2.0)) * (temp.y + 1)) >= ((pow(b, 2.0)) *
                                                  (temp.x - .5)):
                break
        #if not in region 2, move on to region 1
        else:
            break

    while True:

        #compute next x location for region 1
        temp.x = temp.x - 1

        #compute the y value for x - 1 using Eq. 2.9
        temp.y = math.sqrt(
            (pow(b, 2.0)) * (1 - ((pow(temp.x, 2.0)) / (pow(a, 2.0)))))

        #Round to the nearest integer
        temp.y = int(round(temp.y))

        #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