(radius, segments=(True, True, True, True))
return {'Outline': outline, 'Area': area}
Get the area and outline of a circle as pixels.
    Optionally pass in which segment is needed, as a tuple or number.
    
    Modified the bresenham complete circle algorithm from
    daniweb.com/programming/software-development/threads/321181
Get the area and outline of a circle as pixels.
    Optionally pass in which segment is needed, as a tuple or number.
    
    Modified the bresenham complete circle algorithm from
    daniweb.com/programming/software-development/threads/321181
Get the area and outline of a circle as pixels . Optionally pass in which segment is needed as a tuple or number . Modified the bresenham complete circle algorithm from daniweb . com / programming / software - development / threads / 321181
def calculate_circle(radius, segments=(True, True, True, True)):
    """Get the area and outline of a circle as pixels.
    Optionally pass in which segment is needed, as a tuple or number.
    
    Modified the bresenham complete circle algorithm from
    daniweb.com/programming/software-development/threads/321181
    """

    if isinstance(segments, int):
        segments = [i == segments for i in range(4)]
        
    #Parse text input
    elif isinstance(segments, str):
        option = segments.lower()
        count = [0, 0, 0, 0]
        if 'top' in option:
            count[0] += 1
            count[3] += 1
        if 'bottom' in option:
            count[1] += 1
            count[2] += 1
        if 'left' in option:
            count[2] += 1
            count[3] += 1
        if 'right' in option:
            count[0] += 1
            count[1] += 1
        count_max = max(count)
        segments = [i == count_max for i in count]
    
    #Calculate the circle
    switch = 3 - (2 * radius)
    outline = set()
    area = set()
    x = 0
    y = radius
    last_y = None
    last_x = None
    while x <= y:
        
        #Calculate outline
        if segments[0]:
            outline.add((x, -y))
            outline.add((y, -x))
        if segments[1]:
            outline.add((y, x))
            outline.add((x, y))
        if segments[2]:
            outline.add((-x, y))
            outline.add((-y, x))
        if segments[3]:
            outline.add((-y, -x))
            outline.add((-x, -y))
        
        #Add to area
        if y != last_y:
            last_y = y
            if segments[0]:
                for i in range(0, x):
                    area.add((i, -y))
            if segments[1]:
                for i in range(0, x):
                    area.add((i, y))
            if segments[2]:
                for i in range(1-x, 1):
                    area.add((i, y))
            if segments[3]:
                for i in range(1-x, 1):
                    area.add((i, -y))
                    
        if x != last_x:
            last_x = x
            if segments[0]:
                for i in range(0, y):
                    area.add((i, -x))
            if segments[1]:
                for i in range(0, y):
                    area.add((i, x))
            if segments[2]:
                for i in range(1-y, 1):
                    area.add((i, x))
            if segments[3]:
                for i in range(1-y, 1):
                    area.add((i, -x))

        if switch < 0:
            switch += 4 * x + 6
        else:
            switch += 4 * (x - y) + 10
            y = y - 1
        x = x + 1
        
    return {'Outline': outline, 'Area': area}
def calculate_circle ( radius , segments = ( True , True , True , True ) ) : if isinstance ( segments , int ) : segments = [ i == segments for i in range ( 4 ) ] #Parse text input elif isinstance ( segments , str ) : option = segments . lower ( ) count = [ 0 , 0 , 0 , 0 ] if 'top' in option : count [ 0 ] += 1 count [ 3 ] += 1 if 'bottom' in option : count [ 1 ] += 1 count [ 2 ] += 1 if 'left' in option : count [ 2 ] += 1 count [ 3 ] += 1 if 'right' in option : count [ 0 ] += 1 count [ 1 ] += 1 count_max = max ( count ) segments = [ i == count_max for i in count ] #Calculate the circle switch = 3 - ( 2 * radius ) outline = set ( ) area = set ( ) x = 0 y = radius last_y = None last_x = None while x <= y : #Calculate outline if segments [ 0 ] : outline . add ( ( x , - y ) ) outline . add ( ( y , - x ) ) if segments [ 1 ] : outline . add ( ( y , x ) ) outline . add ( ( x , y ) ) if segments [ 2 ] : outline . add ( ( - x , y ) ) outline . add ( ( - y , x ) ) if segments [ 3 ] : outline . add ( ( - y , - x ) ) outline . add ( ( - x , - y ) ) #Add to area if y != last_y : last_y = y if segments [ 0 ] : for i in range ( 0 , x ) : area . add ( ( i , - y ) ) if segments [ 1 ] : for i in range ( 0 , x ) : area . add ( ( i , y ) ) if segments [ 2 ] : for i in range ( 1 - x , 1 ) : area . add ( ( i , y ) ) if segments [ 3 ] : for i in range ( 1 - x , 1 ) : area . add ( ( i , - y ) ) if x != last_x : last_x = x if segments [ 0 ] : for i in range ( 0 , y ) : area . add ( ( i , - x ) ) if segments [ 1 ] : for i in range ( 0 , y ) : area . add ( ( i , x ) ) if segments [ 2 ] : for i in range ( 1 - y , 1 ) : area . add ( ( i , x ) ) if segments [ 3 ] : for i in range ( 1 - y , 1 ) : area . add ( ( i , - x ) ) if switch < 0 : switch += 4 * x + 6 else : switch += 4 * ( x - y ) + 10 y = y - 1 x = x + 1 return { 'Outline' : outline , 'Area' : area }