Exemplo n.º 1
0
    def generate(self, step, dumpworld):
        # generate empty world
        world1 = np.zeros([10, 10, 10])
        world2 = np.zeros([10, 10, 10])
        world = np.zeros([3, 10, 10, 10])

        # create new point
        if self.brightness <= 0.0:
            self.counter = 0
            self.pos = [randint(2, 8), randint(2, 8), randint(2, 8)]
            self.dir *= -1
            self.pos1 = [randint(2, 8), randint(2, 8), randint(2, 8)]

        # change direction
        if self.brightness >= 1.0:
            self.dir *= -1
            self.pos2 = [randint(2, 8), randint(2, 8), randint(2, 8)]

        self.brightness = np.clip(self.brightness + self.dir * self.speed, 0,
                                  1)

        world1[:, :, :] = gen_shooting_star(self.pos1[0], self.pos1[1],
                                            self.pos1[2])

        world2[:, :, :] = gen_shooting_star(self.pos2[0], self.pos2[1],
                                            self.pos2[2])

        #        print(self.brightness, 1 - self.brightness)
        world[0, :, :, :] = world1 * self.brightness + world2 * (
            1.0 - self.brightness)
        world[1, :, :, :] = world[0, :, :, :]
        world[2, :, :, :] = world[0, :, :, :]

        return np.clip(world, 0, 1)
    def generate(self, step, dumpworld):
        world = np.zeros([3, 10, 10, 10])

        # every <refresh> frames: generate new vector
        if step == 0 or step % self.speed == 0:
            self.switch *= -1
            if self.switch == -1:

                self.v = gen_line(self.p1, self.p2, self.speed)
                self.p = self.p1
                self.p1 = [10, uniform(-1, 10), uniform(-1, 10)]
            else:
                self.v = gen_line(self.p2, self.p1, self.speed)
                self.p = self.p2
                self.p2 = [-1, uniform(-1, 10), uniform(-1, 10)]

        [sx, sy, sz] = s(self.p, self.v, step % self.speed)

        # switch on leds depending on distance
        world[0, :, :, :] = np.rot90(gen_shooting_star(sx, sy, sz),
                                     axes=[0, 1],
                                     k=0)

        if self.direction == 1:
            world[0, :, :, :] = np.rot90(world[0, :, :, :], k=1, axes=(0, 1))
        elif self.direction == 2:
            world[0, :, :, :] = np.rot90(world[0, :, :, :], k=1, axes=(0, 2))

        world[1, :, :, :] = world[0, :, :, :]
        world[2, :, :, :] = world[0, :, :, :]
        return np.clip(world, 0, 1)
    def generate(self, step, dumpworld):
        world = np.zeros([3, 10, 10, 10])

        # every <refresh> frames: generate new vector
        if step == 1 or step % self.refresh == 0:
            self.s0, self.v = gen_line(self.speed)

        [sx, sy, sz] = s(self.s0, self.v, step % self.refresh)
        # return current position of shooting star

        # switch on leds depending on distance
        world[0, :, :, :] = gen_shooting_star(sx, sy, sz)
        world[1, :, :, :] = world[0, :, :, :]
        world[2, :, :, :] = world[0, :, :, :]

        return np.clip(world, 0, 1)
    def generate(self, step, dumpworld):
        # generate empty world
        world = np.zeros([3, 10, 10, 10])

        # generate current position
        temp_d = self.distance
        temp_theta = sawtooth(self.theta * step) * np.pi
        temp_rho = np.sin(self.rho * step)

        [sx, sy, sz] = polar2z(temp_d, temp_theta, temp_rho)

        # switch on leds depending on distance
        world[0, :, :, :] = gen_shooting_star(sx + 4.5, sy + 4.5, sz + 4.5)
        world[1, :, :, :] = world[0, :, :, :]
        world[2, :, :, :] = world[0, :, :, :]

        return world