def main():
    if len(sys.argv[1:])!=3:
        exit(print('Wrong Number of Arguments','\nUsage :python3 drawCircle.py <xc> <yc> <r>'))
    if(input('Defualt viewPort is (-400 -400, 400 400). Change?(y/Y)')in ('y','Y')):
        x,y=map(int,input('viewPort\'s xMax yMax : ').split())
        new_view = ViewPort(-x,-y,x,y)
    else:
        new_view =ViewPort(-400,-400,400,400)
    if(input('Defualt Window is (-200 -200, 200 200). Change?(y/Y)')in ('y','Y')):
        x,y=map(int,input('Window\'s xMax yMax : ').split())
        new_win = Window(-x,-y,x,y)
    else:
        new_win = Window(-200,-200,200,200)
    x1,y1,r = int(sys.argv[1]),int(sys.argv[2]),int(sys.argv[3])   
    print('ViewPort :',new_view)
    print("Window :",new_win)
    x,y = new_win.map_to(x1,y1,new_view)
    _,y_r = new_win.map_to(x1,y1+r,new_view)
    r=y_r - y
    print("Given points after mapping to viewPort.. ",x,y,r)	
    win = new_view.init_view()	
    pixel=bresenham(x,y,r)
    for i in pixel:
        x,y= i
        win.plot(*i)
    input('Exit?')
def main():
    if(input('Defualt viewPort is (-400 -400, 400 400). Change?(y/Y)')in ('y','Y')):
        x,y=map(int,input('viewPort\'s xMax yMax : ').split())
        new_view = ViewPort(-x,-y,x,y)
    else:
        new_view =ViewPort(-400,-400,400,400)	
        print('ViewPort :',new_view)
        
    win = new_view.init_view()
    print('Enter vertices of Clipping Window')
    clipw=[]
    while(1):
        try:
            x,y=map(int,input('Next vert(N)?').split())
            clipw.append((x,y))
        except:
            print(clipw)
            break
    
    vert = []
    print('Enter Polygon to be clipped-')
    while(1):
        try:
            x,y=map(int,input('Next vert(N)?').split())
            vert.append((x,y))
        except:
            print(vert)
            break
    temp = PolyClip(vert,clipw)
    print('clipped vert:',temp)
    drawPoly(vert,win,'yellow')
    drawPoly(clipw,win,'red3')
    drawPoly(temp,win,'green')

    input('Exit?')	
def main():
    if len(sys.argv[1:]) != 4:
        exit(
            print('Wrong Number of Arguments',
                  '\nUsage :python3 drawEllipse.py <xc> <yc> <rx> <ry>'))
    if (input('Defualt viewPort is (-400 -400, 400 400). Change?(y/Y)')
            in ('y', 'Y')):
        x, y = map(int, input('viewPort\'s xMax yMax : ').split())
        new_view = ViewPort(-x, -y, x, y)
    else:
        new_view = ViewPort(-400, -400, 400, 400)
    if (input('Defualt Window is (-200 -200, 200 200). Change?(y/Y)')
            in ('y', 'Y')):
        x, y = map(int, input('Window\'s xMax yMax : ').split())
        new_win = Window(-x, -y, x, y)
    else:
        new_win = Window(-200, -200, 200, 200)
    x1, y1, rx, ry = int(sys.argv[1]), int(sys.argv[2]), int(sys.argv[3]), int(
        sys.argv[4])
    print('ViewPort :', new_view)
    print("Window :", new_win)
    x, y = new_win.map_to(x1, y1, new_view)
    _, yr = new_win.map_to(x1, y1 + ry, new_view)
    ry = yr - y
    xr, _ = new_win.map_to(x1 + rx, y1, new_view)
    rx = xr - x
    print("Given points(xc,yc) and radius(rx,ry) after mapping to viewPort.. ",
          x, y, rx, ry)
    win = new_view.init_view()
    pixel = bresenham_for_ellipse(rx, ry, x, y)
    for i in pixel:
        x, y = i
        win.plot(*i)
    input('Exit?')
def main():
    vert = []

    while (1):
        try:
            x, y = map(int, input('Next vert?').split())
            vert.append((x, y))
        except:
            print(vert)
            break
    if (input('Defualt viewPort is (-400 -400, 400 400). Change?(y/Y)')
            in ('y', 'Y')):
        x, y = map(int, input('viewPort\'s xMax yMax : ').split())
        new_view = ViewPort(-x, -y, x, y)
    else:
        new_view = ViewPort(-400, -400, 400, 400)
    print('ViewPort :', new_view)

    pixel = []
    filled = []
    pixel_dict = {}
    vert += [vert[0]]
    win = new_view.init_view()

    for i in range(len(vert) - 1):
        pixel += bresenham(*vert[i], *vert[i + 1])

    for i in pixel:
        x, y = i
        win.plot(*i)
        pixel_dict[(x, y)] = 1
    stack = [(0, 0)]

    input('Exit?')
def main():
    if (input('Defualt viewPort is (-400 -400, 400 400). Change?(y/Y)')
            in ('y', 'Y')):
        x, y = map(int, input('viewPort\'s xMax yMax : ').split())
        new_view = ViewPort(-x, -y, x, y)
    else:
        new_view = ViewPort(-400, -400, 400, 400)
    print('ViewPort :', new_view)

    win = new_view.init_view()
    x, y, x1, y1 = drawLine(win)
    xmin, ymin, xmax, ymax = map(
        int,
        input(
            'Enter Cliping Window\'s Endpoints <xmin> <ymin> <xmax> <ymax>  :'
        ).split())
    drawPoly([(xmin, ymin), (xmax, ymin), (xmax, ymax), (xmin, ymax)], win)

    temp = cohenSutherlandClip(x, y, x1, y1, xmin, ymin, xmax, ymax)
    if not temp: return
    pixel = bresenham(*temp)
    for i in pixel:
        x, y = i
        win.plot(*i, 'green')
    input('Exit?')
Beispiel #6
0
def main():
    vert = []

    while (1):
        try:
            x, y = map(int, input('Next vert?').split())
            vert.append((x, y))
        except:
            print(vert)
            break
    if (input('Defualt viewPort is (-400 -400, 400 400). Change?(y/Y)')
            in ('y', 'Y')):
        x, y = map(int, input('viewPort\'s xMax yMax : ').split())
        new_view = ViewPort(-x, -y, x, y)
    else:
        new_view = ViewPort(-400, -400, 400, 400)
    print('ViewPort :', new_view)

    vert += [vert[0]]
    win = new_view.init_view()
    edge_table = dd(list)
    for i in range(len(vert) - 1):
        #Edge table
        x, y, x1, y1 = *vert[i], *vert[i + 1]
        if y > y1:
            x, y, x1, y1 = x1, y1, x, y
        if y == y1:
            continue
        if x1 == x:
            slope_inv = 0
        else:
            slope_inv = (x1 - x) / (y1 - y)

        edge_table[y].append([x, x, y1, slope_inv])
    #edge_table.sort()

    y_max = max(v[1] for v in vert)
    y_min = min(v[1] for v in vert)

    scanLine(edge_table, y_min, y_max, win)

    input('Exit?')
def main():
    vert = []

    while (1):
        try:
            x, y = map(int, input('Next vert?').split())
            vert.append((x, y))
        except:
            print(vert)
            break
    if (input('Defualt viewPort is (-400 -400, 400 400). Change?(y/Y)')
            in ('y', 'Y')):
        x, y = map(int, input('viewPort\'s xMax yMax : ').split())
        new_view = ViewPort(-x, -y, x, y)
    else:
        new_view = ViewPort(-400, -400, 400, 400)
    print('ViewPort :', new_view)

    pixel = []
    filled = []
    pixel_dict = {}
    vert += [vert[0]]
    win = new_view.init_view()

    for i in range(len(vert) - 1):
        pixel += bresenham(*vert[i], *vert[i + 1])

    for i in pixel:
        x, y = i
        win.plot(*i)
        pixel_dict[(x, y)] = 1
    point = win.getMouse()
    stack = [(int(point.getX()), int(point.getY()))]

    #Comment this line for just polygon
    boundaryFill(pixel_dict, stack, filled, win)

    input('Exit?')
        n1, n2, n3 = 1, 1, 1
        a, b, c = 150, 150, 150
        return self.perspective(l, x0, y0, z0, n1, n2, n3, a, b, c)


def convert_to_2d(l):
    l2d = []
    for i in l:
        l2d.append((i[0] - int(i[2] * (math.cos(math.pi / 4))),
                    i[1] - int(i[2] * (math.sin(math.pi / 4)))))
    return l2d


if __name__ == "__main__":
    port = ViewPort(-400, -400, 400, 400)
    win = port.init_view()
    win = drawAxis(win, port)
    __3d = _3D_helper(port, win)

    cube_size = 80
    l = [[40, 0, 0], [80, 0, 40], [40, 0, 80], [0, 0, 40], [40, 40, 0],
         [80, 40, 40], [40, 40, 80], [0, 40, 40]]
    '''l = [[0,0,0],
            [cube_size,0,0],
            [cube_size,cube_size,0],
            [0,cube_size,0],
            [0,0,cube_size],
            [cube_size,0,cube_size],
            [cube_size,cube_size,cube_size],
            [0,cube_size,cube_size]]'''
    l2d = convert_to_2d(l)
def main(): 
    vert=[]
    while(1):
        try:
            x,y=map(int,input('Next vert?').split())
            vert.append([x,y])
        except:
            print(vert)
            break
    if(input('Defualt viewPort is (-400 -400, 400 400). Change?(y/Y)')in ('y','Y')):
        x,y=map(int,input('viewPort\'s xMax yMax : ').split())
        new_view = ViewPort(-x,-y,x,y)
    else:
        new_view =ViewPort(-400,-400,400,400)	
    print('ViewPort :',new_view)
    win = new_view.init_view()
    drawPoly(vert,win)
    
    while 1:
        k=win.getKey()
        #print(k,vert)
        if k=="Left":
            drawPoly(vert,win,color_rgb(44,44,44))
            drawAxis(win,new_view)
            vert = translation(vert,10,0,win) 
            drawPoly(vert,win,"red")
        elif k=="Right":
            drawPoly(vert,win,color_rgb(44,44,44))
            drawAxis(win,new_view)
            vert = translation(vert,-10,0,win) 
            drawPoly(vert,win,"red")
        elif k=="Up":
            drawPoly(vert,win,color_rgb(44,44,44))
            drawAxis(win,new_view)
            vert = translation(vert,0,-10,win) 
            drawPoly(vert,win,"red")
        elif k=="Down":
            drawPoly(vert,win,color_rgb(44,44,44))
            drawAxis(win,new_view)
            vert = translation(vert,0,10,win) 
            drawPoly(vert,win,"red")
        elif k=="s":
            drawPoly(vert,win,color_rgb(44,44,44))
            drawAxis(win,new_view)
            vert = only_scale(vert,0,0,2,2,win) 
            drawPoly(vert,win,"red")
        elif k=="S":
            drawPoly(vert,win,color_rgb(44,44,44))
            drawAxis(win,new_view)
            vert = only_scale(vert,0,0,0.5,0.5,win) 
            drawPoly(vert,win,"red")
        elif k=="r":
            drawPoly(vert,win,color_rgb(44,44,44))
            drawAxis(win,new_view)
            vert = only_rotation(vert,0,0,15,win) 
            drawPoly(vert,win,"red")
        elif k=="R":
            drawPoly(vert,win,color_rgb(44,44,44))
            drawAxis(win,new_view)
            vert = only_rotation(vert,0,0,-15,win) 
            drawPoly(vert,win,"red")
        elif k=="f":
            drawPoly(vert,win,color_rgb(44,44,44))
            drawAxis(win,new_view)
            vert = reflection(vert,0,0,45,win) 
            drawPoly(vert,win,"red")
        elif k=="F":
            drawPoly(vert,win,color_rgb(44,44,44))
            drawAxis(win,new_view)
            vert = reflection(vert,0,0,-45,win) 
            drawPoly(vert,win,"red")        
        elif k=="x":
            drawPoly(vert,win,color_rgb(44,44,44))
            drawAxis(win,new_view)
            vert = shear_x(vert,1,win) 
            drawPoly(vert,win,"red")        
        elif k=="X":
            drawPoly(vert,win,color_rgb(44,44,44))
            drawAxis(win,new_view)
            vert = shear_x(vert,-1,win) 
            drawPoly(vert,win,"red")        
        elif k=="y":
            drawPoly(vert,win,color_rgb(44,44,44))
            drawAxis(win,new_view)
            vert = shear_y(vert,1,win) 
            drawPoly(vert,win,"red")        
        elif k=="Y":
            drawPoly(vert,win,color_rgb(44,44,44))
            drawAxis(win,new_view)
            vert = shear_y(vert,-1,win) 
            drawPoly(vert,win,"red")