Beispiel #1
0
    def setup(self):

        boundary = RectangleRange(WINDOW_WIDTH // 2, WINDOW_HEIGHT // 2,
                                  WINDOW_WIDTH // 2, WINDOW_HEIGHT // 2)
        self.qt = QuadTree(boundary)

        for i in range(2000):
            px = random.randint(5, WINDOW_WIDTH - 5)
            py = random.randint(50, WINDOW_HEIGHT - 5)
            v = Vehicle(Vector2(px, py), Vector2(0, 0))
            p = QuadTreePoint(px, py, v)
            self.qt.insert(p)

        self.r1 = RectangleRange(WINDOW_WIDTH // 2 - 100,
                                 WINDOW_HEIGHT // 2 + 100, 200, 100)
        self.r2 = CircleRange(WINDOW_WIDTH // 2 + 220,
                              WINDOW_HEIGHT // 2 - 100, 90)

        self.r1dx = 1
        self.r1dy = 2

        self.r2dx = 2
        self.r2dy = 1

        print(self.qt)
Beispiel #2
0
    def setup(self):
        self.points = []
        for i in range(500):
            px = random.randint(5, WINDOW_WIDTH - 5)
            py = random.randint(5, WINDOW_HEIGHT - 5)
            p = Vehicle(Vector2(px, py), Vector2(0, 0))
            self.points.append(p)

        self.targets = []
        t = Rotator(0, 0.05, (WINDOW_WIDTH - 100) / 2,
                    (WINDOW_HEIGHT - 100) / 2)
        self.targets.append(t)
        t = Rotator(0.1, 0.04, (WINDOW_WIDTH - 350) / 2,
                    (WINDOW_HEIGHT - 150) / 2)
        self.targets.append(t)
        t = Rotator(0.2, 0.03, (WINDOW_WIDTH - 300) / 2,
                    (WINDOW_HEIGHT - 150) / 2)
        self.targets.append(t)

        self.repulsors = []
        t = Rotator(0, 0.05, (WINDOW_WIDTH - 300) / 2,
                    (WINDOW_HEIGHT - 200) / 2)
        self.repulsors.append(t)
        t = Rotator(0.2, -0.045, (WINDOW_WIDTH - 200) / 2,
                    (WINDOW_HEIGHT - 300) / 2)
        self.repulsors.append(t)
        t = Rotator(0.4, 0.04, (WINDOW_WIDTH - 110) / 2,
                    (WINDOW_HEIGHT - 100) / 2)
        self.repulsors.append(t)
        t = Rotator(0.6, 0.035, (WINDOW_WIDTH - 110) / 2,
                    (WINDOW_HEIGHT - 200) / 2)
        self.repulsors.append(t)
Beispiel #3
0
    def setup(self):
        p = Particle(Vector2(100, 100), Vector2(95, 95))
        self.particles.append(p)
        p = Particle(Vector2(200, 100), Vector2(150, 100))
        self.particles.append(p)
        p = Particle(Vector2(200, 200), Vector2(200, 200))
        self.particles.append(p)
        p = Particle(Vector2(100, 200), Vector2(100, 200))
        self.particles.append(p)

        a = self.particles[0]
        b = self.particles[1]
        s = Stick(a, b, a.distance_to(b))
        self.sticks.append(s)

        a = self.particles[1]
        b = self.particles[2]
        s = Stick(a, b, a.distance_to(b))
        self.sticks.append(s)

        a = self.particles[2]
        b = self.particles[3]
        s = Stick(a, b, a.distance_to(b))
        self.sticks.append(s)

        a = self.particles[3]
        b = self.particles[0]
        s = Stick(a, b, a.distance_to(b))
        self.sticks.append(s)

        a = self.particles[0]
        b = self.particles[2]
        s = Stick(a, b, a.distance_to(b), True)
        self.sticks.append(s)
Beispiel #4
0
 def setup(self):
     self.points = []
     for i in range(10):
         x = random.randint(5, WINDOW_WIDTH - 5)
         y = random.randint(5, WINDOW_HEIGHT - 5)
         dx = random.randint(-2, 2)
         dy = random.randint(-2, 2)
         p = Point(Vector2(x, y), dx, dy)
         self.points.append(p)
Beispiel #5
0
    def setup(self):
        count = 15
        for i in range(count):
            p = Particle(f"{len(self.particles)}", Vector2(50 + i * 50, WINDOW_HEIGHT // 2), Vector2(50 + i * 50, WINDOW_HEIGHT // 2), True if i == count - 1 or i == 0 else False)
            self.particles.append(p)

        for i in range(count - 1):
            a = self.find_particle(f"{i}")
            b = self.find_particle(f"{i + 1}")
            s = Stick(a, b, a.distance_to(b))
            self.sticks.append(s)
Beispiel #6
0
    def setup(self):
        cols = 20
        rows = 15
        for xx in range(cols):
            for yy in range(rows):
                x = 100 + xx * 30
                y = 20 + yy * 30
                p = Particle(f"{xx}-{yy}", Vector2(x, y), Vector2(x - 5, y - 10), True if y == 20 else False)
                self.particles.append(p)

        for x in range(cols):
            for y in range(rows - 1):
                a = self.find_particle(f"{x}-{y}")
                b = self.find_particle(f"{x}-{y + 1}")
                s = Stick(a, b, a.distance_to(b))
                self.sticks.append(s)

        for y in range(rows):
            for x in range(cols - 1):
                a = self.find_particle(f"{x}-{y}")
                b = self.find_particle(f"{x + 1}-{y}")
                s = Stick(a, b, a.distance_to(b))
                self.sticks.append(s)
Beispiel #7
0
 def update(self, delta):
     if self.pinned:
         return
     self.velocity = (self.pos - self.oldpos) * Particle.friction
     self.oldpos = Vector2(self.pos)
     self.pos += self.velocity
Beispiel #8
0
 def add_particle(self, x, y) -> Particle:
     p = Particle(f"{len(self.particles)}", Vector2(x, y), Vector2(x, y))
     self.particles.append(p)
     return p
 def to_angle(self, v: Vector2):
     vn = v.normalize()
     return math.atan2(vn.y, vn.x)
Beispiel #10
0
 def __init__(self, pos, vel):
     self.pos = pos
     self.vel = vel
     self.acc = Vector2(0, 0)
Beispiel #11
0
    def setup(self):
        p = Particle(f"{len(self.particles)}", Vector2(50, 50),
                     Vector2(50, 50))
        self.particles.append(p)
        p = Particle(f"{len(self.particles)}", Vector2(100, 50),
                     Vector2(100, 50))
        self.particles.append(p)
        p = Particle(f"{len(self.particles)}", Vector2(100, 100),
                     Vector2(100, 100))
        self.particles.append(p)
        p = Particle(f"{len(self.particles)}", Vector2(50, 100),
                     Vector2(50, 100))
        self.particles.append(p)

        self.add_stick(0, 1)
        self.add_stick(1, 2)
        self.add_stick(2, 3)
        self.add_stick(3, 0)
        self.add_stick(0, 2)

        p = Particle(f"{len(self.particles)}", Vector2(150, 50),
                     Vector2(150, 50))
        self.particles.append(p)
        p = Particle(f"{len(self.particles)}", Vector2(200, 50),
                     Vector2(200, 50))
        self.particles.append(p)
        p = Particle(f"{len(self.particles)}", Vector2(250, 50),
                     Vector2(250, 50))
        self.particles.append(p)
        p = Particle(f"{len(self.particles)}", Vector2(300, 50),
                     Vector2(300, 50))
        self.particles.append(p)
        p = Particle(f"{len(self.particles)}", Vector2(350, 50),
                     Vector2(350, 50))
        self.particles.append(p)
        p = Particle(f"{len(self.particles)}", Vector2(400, 50),
                     Vector2(400, 50), True)
        self.particles.append(p)

        self.add_stick(2, 4)
        self.add_stick(4, 5)
        self.add_stick(5, 6)
        self.add_stick(6, 7)
        self.add_stick(7, 8)
        self.add_stick(8, 9)
Beispiel #12
0
 def __init__(self, angle, speed, radiusx, radiusy):
     self.angle = angle
     self.speed = speed
     self.radiusx = radiusx
     self.radiusy = radiusy
     self.pos = Vector2(0, 0)
Beispiel #13
0
 def add_particle(self, x, y, ox=None, oy=None) -> Particle:
     p = Particle(f"{len(self.particles)}", Vector2(x, y),
                  Vector2(x if ox == None else ox, y if oy == None else oy))
     self.particles.append(p)
     return p
Beispiel #14
0
 def add_particle(self):
     p = Particle(f"{len(self.particles)}", Vector2(150, 100),
                  Vector2(140, 95))
     self.particles.append(p)