def run(self):
    
        assert drawing.dist_point_to_point(Point(0,0),Point(10,0)) == 10
        assert drawing.dist_point_to_point(Point(0,0),Point(3,4)) == 5

        curves = []

        curves.append(drawing.BezierCubic(Point(10,10),Point(10,10),Point(90,10),Point(90,10)))
        curves.append(drawing.BezierCubic(Point(10,10),Point(10,10),Point(90,20),Point(90,20)))        
        curves.append(drawing.BezierCubic(Point(10,10),Point(10,40),Point(90,60),Point(90,20)))

        for curve in curves:
            drawing.bezier_cubic(self,curve,5)

        debug.pause()
        self.clear()
            
        for curve in curves:
            drawing.bezier_cubic(self,curve,2)
            
        debug.pause()
        self.clear()
            
        for curve in curves:
            drawing.bezier_cubic(self,curve,1)
Exemple #2
0
def triangle_clipper(wb,box,triangle,division=0):

    if division > 3:
        return

    print "triangle_clipper({0},{1},{2})".format(box,triangle,division)
    
    triangle.draw(wb,colour="green")
    
    debug.pause()
    
    # Test whether triangle lies wholy inside, outside or staddles.
    p0 = triangle.p0
    p1 = triangle.p1
    p2 = triangle.p2
    
    (a0,b0,c0,d0) = evaluate_point_against_box_inequalities(box,p0)
    (a1,b1,c1,d1) = evaluate_point_against_box_inequalities(box,p1)
    (a2,b2,c2,d2) = evaluate_point_against_box_inequalities(box,p2)
    
    if a0 | b0 | c0 | d0 | a1 | b1 | c1 | d1 | a2 | b2 | c2 | d2 == False:
        # Wholy inside box.
        fill(wb,triangle.as_polygon(),colour="red")
    elif ((a0&a1&a2) | (b0&b1&b2) | (c0&c1&c2) | (d0&d1&d2)) == False:
        # There is no boundary for which all the points are on the side
        # that it outside of the box.
        # Need to clip.
        
        if a0:
            if a1 == False:
                (t1,t2) = subdivide_triangle_0_1(triangle)
            else:
                (t1,t2) = subdivide_triangle_2_0(triangle)
        elif a1 | a2:
            (t1,t2) = subdivide_triangle_1_2(triangle)
        elif b0:
            if b1 == False:
                (t1,t2) = subdivide_triangle_0_1(triangle)
            else:
                (t1,t2) = subdivide_triangle_2_0(triangle)
        elif b1 | b2:
            (t1,t2) = subdivide_triangle_1_2(triangle)
        elif c0:
            if c1 == False:
                (t1,t2) = subdivide_triangle_0_1(triangle)
            else:
                (t1,t2) = subdivide_triangle_2_0(triangle)
        elif c1 | c2:
            (t1,t2) = subdivide_triangle_1_2(triangle)
        elif d0:
            if d1 == False:
                (t1,t2) = subdivide_triangle_0_1(triangle)
            else:
                (t1,t2) = subdivide_triangle_2_0(triangle)
        elif d1 | d2:
            (t1,t2) = subdivide_triangle_1_2(triangle)
                
        triangle_clipper(wb,box,t1,division=division+1)
        triangle_clipper(wb,box,t2,division=division+1)
    def run(self):
    
        colours = itertools.cycle(["red","blue","green"])
    
        ps = [
            drawing_filling.Polygon([Point(5,5),Point(40,5),Point(20,50)]),
            drawing_filling.Polygon([Point(50,20),Point(70,40),Point(10,50)]),
            drawing_filling.Polygon([Point(10,10),Point(20,10),Point(60,40),Point(40,70)]),
            drawing_filling.Polygon([Point(30,30),Point(50,70),Point(20,90),Point(10,50)]),
            drawing_filling.Polygon([Point(50,10),Point(70,10),Point(60,30),Point(40,70)])
        ]

        for p in ps:
            drawing_filling.fill(self,p,colour=colours.next())
            debug.pause()
    def run(self):
    
        colours = itertools.cycle(["red","blue","green"])
    
        ps = [
            supervision_2.Polygon([Point(5,5),Point(40,5),Point(20,50)]),
            supervision_2.Polygon([Point(50,20),Point(70,40),Point(10,50)]),
            supervision_2.Polygon([Point(10,10),Point(20,10),Point(60,40),Point(40,70)]),
            supervision_2.Polygon([Point(30,30),Point(50,70),Point(20,90),Point(10,50)]),
            supervision_2.Polygon([Point(50,10),Point(70,10),Point(60,30),Point(40,70)])
        ]

        for p in ps:
            p.draw(self,colour=colours.next())
            debug.pause()
            supervision_2.fill(self,p,colour=colours.next())
            debug.pause()
 def run(self):
 
     colours = itertools.cycle(["red","blue","green","purple","orange","yellow"])
         
     boundingPolygon = supervision_2.Polygon([Point(20,20),Point(70,30),Point(80,80),Point(30,70)])
     boundingPolygon.draw(self,colour=colours.next())
     
     ps = [
         supervision_2.Polygon([Point(10,10),Point(50,90),Point(90,10)]),
         supervision_2.Polygon([Point(10,20),Point(50,50),Point(90,10)]),
         supervision_2.Polygon([Point(11,11),Point(91,11),Point(51,91)]), # interesting, order of vertices does not seem to matter?
         supervision_2.Polygon([Point(5,40),Point(95,30),Point(96,60),Point(60,70)]),
         supervision_2.Polygon([Point(15,15),Point(50,15),Point(50,50),Point(30,30),Point(20,50)])
     ]
     
     for p in ps:
         colour=colours.next()
         p.draw(self,colour)
         debug.pause()
         supervision_2.sutherland_hodgman_clipper(self,boundingPolygon,p,colour)
         debug.pause()