def show(self, surface, p=50): """Show the bezier curve on the surface.""" points = [self(i / p) for i in range(p + 1)] segments = [Segment(points[i], points[i + 1]) for i in range(p)] self.showPoints(surface, points) self.showSegments(surface, segments)
def getSegments(self): """Return the segments of the trajectory of the curve.""" return [ Segment(points[i], points[i + 1]) for i in range(len(self.points) - 1) ]
def random(cls, **kwargs): """Return a random slider.""" s = Segment.random(**kwargs) return cls(*s.points)
def __contains__(self, position): """Determine if the position is on the slider.""" b1 = Segment.__contains__(self, position, e=self.error) b2 = (position in self.cursor) return b1 or b2
from myabstract import Segment,Point,Vector from mysurface import Surface import mycolors p1=Point(-1,-1) p2=Point(1,1) p3=Point(0,1) s1=Segment(p1,p2,width=3) s2=Segment(p2,p3,width=3) e=10e-10 surface=Surface() while surface.open: surface.check() surface.control() surface.clear() surface.show() p=Point(list(surface.point())) #if p in surface: s1.p2=p if s1.crossSegment(s2): s1.color=mycolors.RED s2.color=mycolors.RED else: s1.color=mycolors.WHITE s2.color=mycolors.WHITE l1=s1.getLine()
from myabstract import Segment s = Segment.random() print(s) print(s(0)) print(s(1))
def getSegments(self): """Return the segments that connect the points with their connections.""" return [Segment(self.points[c[0]], self.points[c[1]],\ color=self.segment_color) for c in self.connections]