def __init__(self, motions=None, mass=1): """Create a physical object using its motions, by default a physical has 2 motions but it can have more. By default a physical object has a motion and a moment that are both nulls and 2 dimensionals.""" if motions is None: motions = [Motion.null(n=3, d=2), Motion.null(n=2, d=1)] self.motions = motions self.mass = mass
def __init__(self,form,position,velocity,max_duration=3): """Create body using form and optional name.""" motion=Motion(position,velocity) moment=Motion.null(n=1,d=1) super().__init__(form,motion,moment) self.to=time.time() self.alive=True self.max_duration=max_duration
def delMotion(self): """Set the motion to null.""" self.motion = Motion.null()
def __init__(self, motion=Motion.null(), mass=1, color=mycolors.WHITE): """Create a material point.""" self.motion = motion self.mass = mass self.color = color
def null(n=3, d=2): """Return the neutral material point.""" return MaterialPoint(Motion.null(n=n, d=d))
def __init__(self,position): """Create body using form and optional name.""" form=Form([Point(x,y) for (x,y) in [(0,1),(-1,-1),(1,-1)]]) motion=Motion(position,Vector.null(d=2),Vector.null(d=2)) moment=Motion.null(d=1,n=2) super().__init__(form,motion,moment)
def directUpdate(self, dt=1): """Update all the objects without accounting for their collisions.""" for object in self.objects: object.update(dt) def collideWithGroup(self, group): """Deal with the collisions of the object of the group with another group.""" pass if __name__ == "__main__": from mysurface import Context context = Context(name="Material Group Test", fullscreen=True) f1 = MaterialForm.random(corners=[-10, -10, 10, 10]) f1.motion = Motion(Vector(0, 20), Vector(0, -5, 0), Vector(0, -1)) f2 = MaterialForm.random(corners=[-10, -10, 10, 10]) #f2.fill=True f2.motion = Motion.null() g = MaterialGroup(f1, f2) t = g.getCollisionInstant(1) print(t) while context.open: context.check() context.control() context.clear() context.show() g.update(dt=0.01) g.show(context) context.flip()
def createFromNumber(cls, n, nm=3, d=2): """Create n motions.""" return cls([Motion.null(n=nm, d=d) for i in range(n)])