Esempio n. 1
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)
Esempio n. 2
0
    def events(self):
        """Deal with the user input."""
        cursor = copy.deepcopy(Point(*self.context.point()))
        click = self.context.click()
        for event in pygame.event.get():
            if event.type == QUIT:
                self.context.open = False

            if event.type == KEYDOWN:
                if event.key == K_ESCAPE:
                    self.context.open = False

            if event.type == MOUSEBUTTONDOWN:

                if event.button == 1:
                    self.focus_index = None
                    for body in self.bodies:
                        if cursor in body.absolute:
                            self.focus_index = self.bodies.index(body)
                    if self.focus_index:
                        self.bodies[self.focus_index].position = Vector(
                            *cursor)

                if event.button == 3:
                    c = copy.deepcopy(cursor)
                    if self.focus_index == None:
                        self.focus_index = len(self.bodies)
                        f = Form([c])
                        self.bodies.append(Body.createFromForm(f))
                    else:
                        fa = copy.deepcopy(
                            self.bodies[self.focus_index].absolute)
                        fa.points.append(c)
                        self.bodies[self.focus_index].absolute = fa

            if event.type == MOUSEMOTION:
                if self.focus and click:
                    self.focus.position = Vector(*cursor)

        keys = pygame.key.get_pressed()

        if keys[K_DOWN]:
            self.context.draw.plane.position[1] -= 1
        if keys[K_UP]:
            self.context.draw.plane.position[1] += 1
        if keys[K_LEFT]:
            self.context.draw.plane.position[0] -= 1
        if keys[K_RIGHT]:
            self.context.draw.plane.position[0] += 1

        if keys[K_LSHIFT]:
            self.context.draw.plane.zoom([0.9, 0.9])
        if keys[K_RSHIFT]:
            self.context.draw.plane.zoom([1.1, 1.1])
Esempio n. 3
0
from mycontext import Surface
from mybody import Body
from myabstract import Form,Point,Vector
from mymotion import Motion

import mycolors

surface=Surface()


dt=1

form=Form([Point(0,1),Point(0,0),Point(1,0),Point(1,1)],area_color=mycolors.BLUE,fill=True)
#form=Circle(copy.deepcopy(Point.origin()),radius=1,fill=True,color=mycolors.BLUE)
body=Body(form)
missile=None

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)

n=10
bodies=[createRandomBody() for i in range(n)]


Esempio n. 4
0
from myabstract import Form,Point
from mybody import Body
from mycontext import Context

import copy
import mycolors

ps=[Point(10,2),Point(12,5),Point(15,-2)]
f=Form(ps)
b=Body.createFromAbsolute(f)

context=Context()
while context.open:
    context.check()
    context.control()
    context.clear()
    context.show()

    p=Point(*context.point())

    nb=copy.deepcopy(b)
    nba=copy.deepcopy(nb.absolute)
    nba.points.append(p)
    for point in nba.points:
        point.show(context,color=mycolors.BLUE)
    nb.absolute=nba

    nb.show(context)
    nb.absolute.center.show(context,color=mycolors.RED)

    context.flip()
Esempio n. 5
0
from myconnection import Client, getIP
from mybody import Body

b = Body.random()

IP = "172.16.0.39."
#IP = "MacBook-Pro-de-Olivier.local"
PORT = 1235

c = Client(IP, PORT)
c.send(b)

del c
Esempio n. 6
0
    def getBorn(self):
        return float('inf')

    def setBorn(self):
        pass

    born = property(getBorn, setBorn)


if __name__ == "__main__":
    from mymanager import BodyManager
    from mybody import Body

    ta = TrajectoryAnatomy.random()
    ca = CircleAnatomy.random()
    fa = FormAnatomy.random()
    sa = SegmentAnatomy.random()
    la = LineAnatomy.random()

    tb = Body.createFromRandomMotions(ta)
    cb = Body.createFromRandomMotions(ca)
    fb = Body.createFromRandomMotions(fa)
    sb = Body.createFromRandomMotions(sa)
    lb = Body.createFromRandomMotions(la)

    print(sa.born)

    m = BodyManager(tb, cb, fb, sb, lb)
    m()
Esempio n. 7
0
        for body in self.bodies:
            body.showMotion(context)

    def anyColliding(self):
        l = len(self.bodies)
        for i in range(l):
            for j in range(i + 1, l):
                self.colliding()

    def __len__(self):
        """Return the number of bodies."""
        return len(self.bodies)


if __name__ == "__main__":
    from mysurface import Context
    context = Context()
    bl = [Body.random(), Body.random()]
    bg = BodyGroup(bl)
    while context.open:
        context.clear()
        context.show()
        context.control()
        for event in context.events():
            context.checking(event)
            bg.react(event)
        bg.update(dt=0.01)
        bg.show(context)
        bg.showMotion(context)
        context.flip()