Пример #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)
Пример #11
0
 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