示例#1
0
 def random(corners=[-1, -1, 1, 1], n=5):
     """Create a random body."""
     form = Form.random(corners, n)
     motion = Motion.random(n=2, d=3)
     moment = Motion.random(n=2, d=3)
     print(motion.acceleration)
     return Body(form, motion, moment)
示例#2
0
 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
示例#3
0
def createRandomBody():
    form=5*Form.random(n=5)
    form.side_color=mycolors.RED
    form.area_color=mycolors.BLACK
    form.fill=True
    motion=Motion(10*Vector.random(),Vector.random(),Vector.null())
    moment=Motion(Vector([1]),Vector([0.1]))
    return Body(form,motion,moment)
示例#4
0
 def __init__(self,position,size=5):
     """Create an asteroid."""
     form=size*Form.random(n=5)
     form.side_color=mycolors.RED
     form.area_color=mycolors.DARKGREY
     form.fill=True
     motion=Motion(Vector(*position),Vector.random(),Vector.null())
     moment=Motion(Vector([0]),Vector([random.uniform(-1,1)]))
     super().__init__(form,motion,moment)
示例#5
0
 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
示例#6
0
 def __init__(self, form, motion=Motion(d=2), moment=Motion(d=1)):
     """Create body using its anatomy, its motion and its angular moment.
     #Attributes:
     #self.form,self.motion,self.moment
     #Properties:
     #self.absolute"""
     self.form = form
     self.motion = motion
     self.moment = moment
示例#7
0
 def update(self, dt, mates, friction, born):
     """Update with friction."""
     super().update(dt)
     v = self.updateFriction(friction)
     a = self.updateRules(mates)
     p = self.updateLimit(born)
     return Motion(p, v, a)
示例#8
0
 def __init__(self, name="Unnamed", radius=1, mass=1, motion=Motion(), color=mycolors.WHITE):
     """"Create an astre using its name, radius, mass, motion and colors."""
     self.name = name
     self.mass = mass
     self.radius = radius
     self.motion = motion
     self.color = color
示例#9
0
 def __init__(self):
     """Create the Sun with its physical data."""
     self.name = "Sun"
     self.mass = 1.989 * 1e30 * um
     self.radius = 695510 * 1e3 * ud
     self.motion = Motion()
     self.color = mycolors.YELLOW
示例#10
0
 def random(cls, p=100, v=10):
     """Create a boid with a random motion."""
     p = p * Vector.random()
     v = v * Vector.random()
     a = Vector.null()
     m = Motion(p, v, a)
     return cls(m)
 def random(cls, n=2):
     """Create a random pendulum."""
     angles = [Motion(math.pi*Vector.random(d=1), Vector.null(d=1),
                     Vector.null(d=1)) for i in range(n)]
     lengths = [random.uniform(0, 1) for i in range(n)]
     masses = [random.uniform(0, 1) for i in range(n)]
     return cls(angles, lengths, masses)
示例#12
0
 def random(corners=[-1, -1, 1, 1],
            radius=random.uniform(0, 1),
            color=mycolors.WHITE):
     """Create a random material circle."""
     p = Vector.random()
     v = Vector.random()
     a = Vector.random()
     m = Motion([p, v, a])
     return MaterialCircle(m, radius, color)
示例#13
0
 def __call__(self, position, velocity, born):
     """Return a missile with the same motion."""
     s = SegmentAnatomy.createFromTuples((0, 0), (1, 0))
     s.angle = velocity.angle
     m = Motion(copy.deepcopy(position), copy.deepcopy(velocity))
     m.position += Vector.createFromPolar(born + 1, velocity.angle)
     m.velocity.norm += self.speed
     self.shooting = False
     return [self.type(s, [m], damage=self.damage, duration=self.duration)]
示例#14
0
 def computeMotion(self):
     """Find the motion of a planet with its distance and its mass."""
     angle = random.uniform(0, 2 * math.pi)
     norm = self.distance
     position = Vector.createFromPolar(norm, angle)
     angle = (angle + math.pi / 2) % (2 * math.pi)
     norm = self.speed  # in m/s-1
     velocity = Vector.createFromPolar(norm, angle)
     acceleration = Vector.null()
     return Motion(position, velocity, acceleration)
示例#15
0
 def random(cls, n=5, size=5, life_factor=1 / 10, **kwargs):
     """Create a random asteroid."""
     a = FormAnatomy.random(n)
     mt = Motion.random(n=2, d=2)
     mm = Moment.random(n=2, d=1)
     a.enlarge(size)
     return cls(a, [mt, mm],
                alive=True,
                max_life=a.area * life_factor,
                **kwargs)
 def getCenter(self):
     """Return the center of the material form."""
     center=MaterialPoint.createFromform.center
     x,y=center
     position=Vector(x,y,color=mycolors.GREEN)
     point_motion=Motion()
     for point in self.points:
         point_motion+=point.getMotion()
     material_center=MaterialPoint(point_motion)
     material_center.setPosition(position)
     return material_center
 def showMotion(self,surface):
     """Show the motion on a surface."""
     form=self.getForm()
     center=form.center()
     x,y=center
     position=Vector(x,y,color=mycolors.GREEN)
     point_motion=Motion()
     for point in self.points:
         point_motion+=point.getMotion()
     material_center=MaterialPoint(point_motion)
     material_center.setPosition(position)
     material_center.showMotion(surface)
示例#18
0
 def shoot(self):
     """Return a missile with the same motion."""
     shooted = []
     for i in range(self.n):
         anatomy = SegmentAnatomy.createFromTuples((0, 0), (1, 0))
         angle = self.shooting_view * i / self.n
         anatomy.rotate(self.velocity.angle + angle)
         m = Motion(copy.deepcopy(self.position),
                    copy.deepcopy(self.velocity))
         m.position += Vector.createFromPolar(self.born + 1,
                                              m.velocity.angle)
         m.velocity.norm += self.shooting_speed
         shooted.append(SegmentMissile(a, m))
     return shooted
示例#19
0
 def __call__(self, position, velocity, born):
     """Return a missile with the same motion."""
     self.shooting = False
     shooted = []
     for i in range(self.n):
         s = SegmentAnatomy.createFromTuples((0, 0), (1, 0))
         s.angle = velocity.angle
         angle = self.view * i / self.n
         s.rotate(velocity.angle + angle)
         m = Motion(copy.deepcopy(position), copy.deepcopy(velocity))
         m.position += Vector.createFromPolar(born + 1, m.velocity.angle)
         m.velocity.norm += self.speed
         shooted.append(self.type(s, [m]))
     return shooted
示例#20
0
 def __init__(self, n=10, s=5, g=10, radius_borns=[1, 10], **kwargs):
     super().__init__(**kwargs)
     # entities = [Entity(FormAnatomy.random(),
     #             [Motion(s * Vector.random(), 10 * Vector.random(), Vector(0, -g)),
     #              Moment(Vector.random(), 5*Vector.random())], friction=0)
     #             for i in range(n)]
     self.group = Group(*[Entity(CircleAnatomy.random(radius_borns=radius_borns), \
                         [Motion(s*Vector.random(), Vector(0,0), Vector(0, -g))], friction=0.1) \
                         for i in range(n)])
     self.collider = Collider(elasticity=0.9)
     self.born = s
     self.born_elasticity = 0.5
     self.square = Square(0, 0, 2 * self.born)
     self.correctMasses()
示例#21
0
 def random(cls, na=5, sparse=1e10):
     """Create a random astre."""
     c = "bcdfghjklmnpqrstvwxyz"
     v = "aeiou"
     def rd(n): return c[random.randint(0, len(c) - 1)
                         ] if n % 2 == 0 else v[random.randint(0, len(v) - 1)]
     name = "".join([rd(i) for i in range(na)])
     radius = random.uniform(0, 1)
     mass = random.uniform(1e20, 1e26)
     position = 1e12 * Vector.random()
     velocity = 1e6 * Vector.random()
     velocity.angle = (position.angle + math.pi / 2) % (2 * math.pi)
     acceleration = Vector.null()
     motion = Motion(position, velocity, acceleration)
     color = mycolors.random()
     return cls(name, radius, mass, motion, color)
示例#22
0
 def getMotion(self):
     """Return the motion of the object."""
     return Motion.average([point.motion for point in self.points])
示例#23
0
 def __init__(self, motion=Motion.null(), mass=1, color=mycolors.WHITE):
     """Create a material point."""
     self.motion = motion
     self.mass = mass
     self.color = color
示例#24
0
 def random(corners=[-1, -1, 1, 1], **kwargs):
     """Create a random material point using optional minimum and maximum."""
     motion = Motion.random(corners)
     return MaterialPoint(motion, **kwargs)
示例#25
0
 def null(n=3, d=2):
     """Return the neutral material point."""
     return MaterialPoint(Motion.null(n=n, d=d))
示例#26
0
 def random(min=-1,max=1):
     """Create a random material point using optional minimum and maximum."""
     motion=Motion.random()
     return MaterialPoint(motion)
示例#27
0
 def __init__(self,motion=Motion(),forces=[],mass=1):
     """Create a material point."""
     self.motion=motion
     self.mass=mass
     self.forces=forces
示例#28
0
 def delMotion(self):
     """Set the motion to null."""
     self.motion = Motion.null()
示例#29
0
 def random(cls, **kwargs):
     """Create a random particle using its motions' dimensions."""
     return cls([Motion.random(n=3, d=2), Motion.random(n=2, d=1)], **kwargs)
示例#30
0
 def createFromAbstract(point, n=3, d=2):
     """Create a material point from a Point instance."""
     motion = Motion(Vector(point), n=n,
                     d=d)  #Initializing a motion instance
     return MaterialPoint(motion)  #Initializing a material point instance