Пример #1
0
    def test_RemoteControl(self):
        remote_control = RemoteControl()

        living_room_light = Light('Living Room')
        kitchen_light = Light('Kitchen')
        stereo = Stereo('Living Room')

        living_room_light_on = LightOnCommand(living_room_light)
        living_room_light_off = LightOffCommand(living_room_light)
        kitchen_light_on = LightOnCommand(kitchen_light)
        kitchen_light_off = LightOffCommand(kitchen_light)
        stereo_on_with_CD = StereoOnWithCDCommand(stereo)
        stereo_off = StereoOffCommand(stereo)

        remote_control.set_command(0, living_room_light_on, living_room_light_off)
        remote_control.set_command(1, kitchen_light_on, kitchen_light_off)
        remote_control.set_command(2, stereo_on_with_CD, stereo_off)

        print(remote_control)

        remote_control.on_button_was_pushed(0)
        remote_control.off_button_was_pushed(0)
        remote_control.on_button_was_pushed(1)
        remote_control.off_button_was_pushed(1)
        remote_control.undo_button_was_pushed()
        remote_control.on_button_was_pushed(2)
        remote_control.off_button_was_pushed(2)
        remote_control.undo_button_was_pushed()
Пример #2
0
 def discover_devices(self):
     self.lights = []
     self.devices = []
     responses = self.broadcast_with_resp(
         GetService,
         StateService,
     )
     for r in responses:
         device = Device(r.target_addr, r.ip_addr, r.service, r.port,
                         self.source_id, self.verbose)
         try:
             if device.is_light():
                 if device.supports_multizone():
                     device = MultiZoneLight(r.target_addr, r.ip_addr,
                                             r.service, r.port,
                                             self.source_id, self.verbose)
                 elif device.supports_chain():
                     device = TileChain(r.target_addr, r.ip_addr, r.service,
                                        r.port, self.source_id,
                                        self.verbose)
                 else:
                     device = Light(r.target_addr, r.ip_addr, r.service,
                                    r.port, self.source_id, self.verbose)
                 self.lights.append(device)
         except WorkflowException:
             # cheating -- it just so happens that all LIFX devices are lights right now
             device = Light(r.target_addr, r.ip_addr, r.service, r.port,
                            self.source_id, self.verbose)
             self.lights.append(device)
         self.devices.append(device)
Пример #3
0
def led_blink(color, count):
    if color == "red":
        led = Light(17)
    elif color == "green":
        led = Light(18)
    else:
        led = Light(17)
    for i in range(count):
        led.blink()
        time.sleep(1)
Пример #4
0
def render_random_spheres(scene):
    total_sphere = random.randint(1, 15)

    light = Light(Color(1.0, 1.0, 1.0, 1.0), 1.0)
    light.transform.position = Vector3(0.0, 2.0, -2.0)
    scene.set_light(light)

    for i in range(0, total_sphere):
        s = Sphere(random.randint(10, 200) / 100.0)
        s.transform.position = Vector3(random.randint(-3, 3),
                                       random.randint(-3, 3),
                                       random.randint(2, 10))
        s.albedo = Color(
            float(random.randint(20, 255)) * 1.0 / 255.0,
            float(random.randint(20, 255)) * 1.0 / 255.0,
            float(random.randint(20, 255)) * 1.0 / 255.0, 1.0)
        print("Sphere got color " + str(s.albedo))
        scene.add_objects(s)

    v1 = Vector3(8.0, 0.0, -1.0)
    v2 = Vector3(0.0, 8.0, -3.0)

    animation_velocity = 0.5

    def update_method(t):
        p = Vector3(0.0, 2.0, -2.0)
        p = p.add(v1.multiply(np.cos(animation_velocity * t * np.pi)))
        p = p.add(v2.multiply(np.sin(animation_velocity * t * np.pi)))

        light.transform.position = p

    return update_method
Пример #5
0
def main():
    remote_control = RemoteControl()
    
    light = Light()
    light_on_command = LightOnCommand(light)
    light_off_command = LightOffCommand(light)

    fan = CellingFan()
    celling_fan_high_command = CellingFanHighCommand(fan)
    celling_fan_low_command = CellingFanLowCommand(fan)
    celling_fan_off_command = CellingFanOffCommand(fan)

    remote_control.set_command(2, light_on_command, light_off_command)
    remote_control.set_command(5, celling_fan_high_command, celling_fan_off_command)
    remote_control.set_command(6, celling_fan_low_command, celling_fan_off_command)

    remote_control.on_button_pushed(1) 
    remote_control.off_button_pushed(1)
    remote_control.undo_button_pushed()

    remote_control.on_button_pushed(2) 
    remote_control.off_button_pushed(2)
    remote_control.undo_button_pushed()

    remote_control.on_button_pushed(6) 
    remote_control.off_button_pushed(6)
    remote_control.undo_button_pushed()

    remote_control.on_button_pushed(5)
    remote_control.undo_button_pushed() 
Пример #6
0
def handle_events():
    global see_right, skeletons, items, click, bonfire_ready, background, bonfire, light, stone, wood
    events = get_events()
    for event in events:
        if event.type == SDL_QUIT:
            game_framework.quit()
        elif event.type == SDL_MOUSEMOTION:
            mousecursor.position(x=event.x, y=VIEW_HEIGHT - 1 - event.y)
        elif event.type == SDL_KEYDOWN and event.key == SDLK_ESCAPE:
            del (skeletons)
            del (items)
            del light
            game_framework.change_state(title_state)
        elif event.type == SDL_KEYDOWN and event.key == SDLK_p:
            game_framework.push_state(pause_state)
        elif event.type == SDL_MOUSEBUTTONDOWN and event.button == SDL_BUTTON_RIGHT:
            if collision(ui, mousecursor):
                if stone >= 2 and wood >= 2:
                    game_world.remove_object(bonfire)
                    game_world.remove_object(light)
                    bonfire = Bonfire(player.x, player.y)
                    game_world.add_object(bonfire, 3)
                    bonfire.set_background(background)
                    light = Light(bonfire.x, bonfire.y)
                    game_world.add_object(light, 3)
                    light.set_background(background)
                    stone -= 2
                    wood -= 2
        else:
            player.handle_event(event)
Пример #7
0
    def build_flat_plane(self):
        scene = Scene(self.screen, self.camera_position, COLOUR_WHITE, self.scale)

        count = 1
        for x in range(count):
            for y in range(count):
                s = int(self.screen.width / count)
                cube_material = Material(
                    (0 + int(random.random() * 100), 150 + int(random.random() * 100), int(1 * random.random())),
                    # (0,0,255),
                    (0.5, 0.5, 0.5),
                    (0.8, 0.8, 0.8),
                    (0.5, 0.5, 0.5),
                    50
                )
                rectangle = Rectangle(
                    Point(x * s - self.screen.width/2, -self.screen.height / 2, self.screen.distance + y * s),
                    Point(x * s - self.screen.width/2, -self.screen.height / 2, self.screen.distance + (y+1) * s),
                    Point((x+1) * s - self.screen.width/2, -self.screen.height / 2, self.screen.distance + y * s),
                    cube_material
                )
                scene.add_object(rectangle)

        light_position = Point(-self.screen.width/4,-self.screen.height/2 + 50, self.screen.width * 4 + self.screen.distance)
        light = Light(light_position)
        scene.add_light(light)

        return scene
Пример #8
0
 def __init__(self, color=None, nickName=None, owner=None):
     self.wheels = []
     self.light = Light()
     self.color = color
     self.nickName = nickName
     self.owner = owner
     self.direction = 0
Пример #9
0
    def test_casting_with_obstacles(self):
        block = Block((0, 0, 0), 10, 10, 10, 10)
        light = Light(10, 10, 50, [block])
        light.update()
        visibitlity = light.visibility

        self.assertEqual(visibitlity, self.result)
Пример #10
0
def _decode_light(d):
    """
	Creates a Light instance from a dictionary containing the guts of a Light
	instance.
	
	Parameters:
		d (Dictionary): The dictionary that contains the organs and ideas of
		the Light we are trying to coax into existence.
		
	Returns:
		A cultivated Light.
	
	Preconditions:
		The dictionary actually does specify a light. (i.e. it was encoded
		using _encode_light().)
		
	Postconditions:
		A Light is created.
	"""
    # Create the three different ColorChannels from members of the dictionary.
    r = ColorChannel(d['r_t'], d['r_v'], d['r_c'])
    g = ColorChannel(d['g_t'], d['g_v'], d['g_c'])
    b = ColorChannel(d['b_t'], d['b_v'], d['b_c'])
    # Construct and return the Light instance that wraps the ColorChannels.
    return Light(r, g, b, d['name'], d['id'])
Пример #11
0
def post_lights():
    """
    Füge eine neue Lampe hinzu
    :body name: Name der Lampe
    :body ip_address: IP Adresse der Lampe
    :body port: Port des HTTP-Servers der Lampe
    """
    json = request.get_json()

    if not json:
        return jsonify({'message': 'no data received'}), 400

    name = json.get('name')
    ip_address = json.get('ip_address')
    port = json.get('port')

    if not name or not ip_address or not port:
        return jsonify({'message': 'information is missing'}), 400

    light = Light(None,
                  name,
                  ip_address,
                  port,
                  r=json.get('r', 0),
                  g=json.get('g', 0),
                  b=json.get('b', 0))

    light.save()

    return jsonify({'message': 'Light saved'}), 200
def main():
    remote = SimpleRemoteControl()
    light = Light()
    light_on = LightOnCommand(light)

    remote.set_command(light_on)
    remote.button_was_pressed()
Пример #13
0
 def __init__(self, refPath, dataPath, dbFilename):
     GPIO.cleanup()
     GPIO.setmode(GPIO.BCM)
     GPIO.setup(self.AUTO_START_GPIO_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP)
     self.__i2c = I2C(2)
     self.__analog = Analog(sel.__i2c.getLock(), 0x49)
     self.default = Default()
     self.database = Database(dataPath, dbFilename)
     self.waterlevel = Waterlevel(debug, self.database)
     self.light = Light(self.database)
     self.curtain = Curtain(self.database)
     self.pressure = Pressure(self.database, self.default, self.__analog)
     self.temperature = Temperature("28-0417716a37ff", self.database)
     self.redox = Redox(debug, self.database, self.default, self.__analog)
     self.ph = PH(debug, self.database, self.default, self.__analog,
                  self.temperature)
     self.robot = Robot(debug, self.database)
     self.pump = Pump(debug, self.database, self.default, self.robot,
                      self.redox, self.ph, self.temperature)
     self.panel = Panel(debug, self.database, self.default, self.pump,
                        self.redox, self.ph, self.__i2c)
     self.statistic = Statistic(debug, self.pump, self.robot, self.redox,
                                self.ph, self.temperature, self.pressure,
                                self.waterlevel)
     self.refPath = refPath
     self.__autoSaveTick = 0
     self.__today = date.today().day - 1
     debug.TRACE(debug.DEBUG, "Initialisation done (Verbosity level: %s)\n",
                 debug)
Пример #14
0
def render_moon(scene):

    light = Light(Color(1.0, 1.0, 1.0, 1.0), 1.0)
    light.transform.position = Vector3(0.0, 2.0, -2.0)
    scene.set_light(light)

    lambertianTintMaterial = Material()
    lambertianTintMaterial.albedo = Color(1.0, 1.0, 1.0, 1.0)
    lambertianTintMaterial.shader = LambertianTintShader()

    s1_earth = Sphere(0.6)
    s1_earth.transform.position = Vector3(0, 0, 1.5)
    s1_earth.material = lambertianTintMaterial.clone()
    scene.add_objects(s1_earth)

    s2_moon = Sphere(0.4)
    s2_moon.transform.position = Vector3(-0.2, -0.5, 1.2)
    s2_moon.material = lambertianTintMaterial.clone()
    s2_moon.material.set_texture(Texture("images/moon.jpg"))
    scene.add_objects(s2_moon)

    v1 = Vector3(0.0, 1.5, 0.5)
    v2 = Vector3(0.5, -1.0, 0.0)
    animation_velocity = 0.4

    def update_method(t):
        p = Vector3(-0.2, -0.5, 1.2)
        p = p.add(v1.multiply(np.cos(animation_velocity * t * np.pi)))
        p = p.add(v2.multiply(np.sin(animation_velocity * t * np.pi)))

        s2_moon.transform.position = p
        s2_moon.transform.rotation = Vector3(
            0.0, np.mod(0.5 * animation_velocity * t, 360), 0.0)

    return update_method
Пример #15
0
def scene2():
    scene = Scene()

    obj = GameObject('0')
    obj.load_mesh('../data/camero.obj')
    obj.load_texture('../data/camero.png', 256)
    obj.set_scale(20)
    obj.rotate_y(-45)
    scene.objects += [obj]

    scene.light = Light()
    scene.light.shadow_map_dim = 512
    scene.light.shadow_map_bias = 1
    scene.light.translate_z(1000)
    scene.light.translate_y(1500)
    scene.light.translate_x(2000)
    scene.light.rotate_y(100)
    scene.light.rotate_x(45)

    image_width = 640
    image_height = 480

    scene.camera = Camera(0.98, 0.735, image_width, image_height, 1, 10000, 20,
                          np.eye(4))
    scene.camera.translate_y(40)
    scene.camera.translate_z(60)
    scene.camera.rotate_x(35)

    return scene
Пример #16
0
    def test_SimpleRemoteControl(self):
        remote = SimpleRemoteControl()
        light = Light()
        light_on_command = LightOnCommand(light)

        remote.set_command(light_on_command)
        remote.button_was_pressed()
Пример #17
0
 def __init__(self):
     #
     # instantiate all our classes
     self.comms = Comms(config.ORIGIN_NUM, config.TARGET_NUMS)
     self.light = Light(config.CITY_NAME, config.LATITUDE, config.LONGITUDE,
                        config.SUNRISE_DELAY, config.SUNSET_DELAY)
     self.door = Door(config.REVS)
     self.camera = Camera(config.MAX_HORZ, config.MAX_VERT)
Пример #18
0
 def addLight(self, name, status=0):
     if not self.repository.isConnected(name):
         self.repository.add(Light(name, status))
         logging.info("Added new light \"{0}\"".format(name))
     else:
         e = ComponentAlreadyConnectedError(name)
         logging.exception("addLight -" + e.__str__())
         raise e
Пример #19
0
 def setLightStatus(self, name, value):
     if self.repository.isConnected(name):
         self.repository.update(Light(name, value))
         logging.info("Set light \"{0}\" to {1}".format(name, value))
     else:
         e = ComponentNotConnectedError(name)
         logging.exception("setLightStatus - " + e.__str__())
         raise e
Пример #20
0
    def __init__(self, device, user):
        from config import Config
        from light import Light

        self.config = Config(device, user)
        self.light = Light(device, user)

        # After create Light object, search for new lights.
        self.light.findNewLights()
 def test_shadow7(self):
     eyev = Vector(0, 0, -1)
     normalv = Vector(0, 0, -1)
     light = Light(Point(0, 0, -10), Color(1, 1, 1))
     in_shadow = True
     m = Material()
     result = m.lighting(Sphere(), light, Point(0, 0, 0), eyev, normalv,
                         in_shadow)
     self.assertTrue(result.equals(Color(0.1, 0.1, 0.1)))
Пример #22
0
def main():
    WIDTH = 1000
    HEIGHT = 1000
    camera = point(0, 0, -1)
    objects = [
        sphere(point(0, 0, 0), 0.5,
               Material(color.from_hex("#FFFFFF"), 0.05, 0.1))
    ]
    lights = [
        Light(point(10.0 * -1.14, 10 * 1.14, 0), color.from_hex("#FF0000")),
        Light(point(0, -10, 0), color.from_hex("#00FF00")),
        Light(point(10.0 * 1.14, 10.0 * 1.14, 0), color.from_hex("#0000FF")),
    ]
    scene_1 = scene(camera, objects, lights, WIDTH, HEIGHT)
    engine = RenderEngine()
    im = engine.render(scene_1)
    with open("render.ppm", "w") as img_file:
        im.write_ppm(img_file)
Пример #23
0
 def __init__(self, x, y, rope_length, obstacles=[]):
     """expects that set_up_surface for Light has been called"""
     self.x = x
     self.y = y
     self.obstacles = obstacles
     self.rope_length = rope_length
     self.bob = Pendulum(BOB_ANGLE, self.rope_length, (self.x, self.y))
     self.light = Light(self.x, self.y + self.rope_length,
                        SWINGING_LIGHT_RADIUS, self.obstacles)
     self.light.update()
def main():
    print('Reading ...')
    start = datetime.datetime.now()

    # data source name
    data_source_name = 'better-ball.d'
    # shading type:
    #   0 - no shading (framework)
    #   1 - constant shading
    #   2 - Gouraud shading
    #   3 - Phong shading
    shading = 3

    world_space = Space()
    world_space.append_by_file(data_source_name + '.txt')  # geometry data

    camera = Camera()
    camera.set_by_file(data_source_name + '.camera.txt')  # camera profile

    light = Light()
    light.set_by_file(data_source_name + '.light.txt')  # light profile

    material = Material()
    material.set_by_file(data_source_name +
                         '.material.txt')  # material profile

    illumination = Illumination()
    illumination.set(camera, light, material, shading)

    display = Display()
    display.set(800)  # change window size

    cost = datetime.datetime.now() - start
    print('Finish. (cost = ' + str(cost) + ')\n')

    print('Calculating: transform ...')
    start = datetime.datetime.now()

    view_space = copy.deepcopy(world_space)
    view_space.transform(world_to_view, camera)

    screen_space = copy.deepcopy(view_space)
    screen_space.transform(view_to_screen, camera)

    device_space = copy.deepcopy(screen_space)
    device_space.transform(screen_to_device, display)

    cost = datetime.datetime.now() - start
    print('Finish. (cost = ' + str(cost) + ')\n')

    window = Window()
    window.set(world_space, device_space, illumination, display)

    window.show()
Пример #25
0
def createLights(LIGHTS, lightColors, lightPos):
    i = 0
    for color in lightColors:
        x = (lightPos[i][0] * 3.5 / 700) - 1.75  # Gets a scale por the x axis
        y = (lightPos[i][1] * 3.5 / 394) - 1.75  # Gets a scale por the y axis
        print("X pos:", x, "Y pos: ", y)
        LIGHTS.append(
            Light(Point(x, y, random.randint(-5, 0)), Color.from_hex(color)))
        i += 1

    pass
Пример #26
0
    def test_azimut_symetry(self):
        azimut = 53
        symetric_azimut = -azimut
        elevation = 10

        reader = LdtReader(LDT_PATH)
        light = Light(reader.azimuts, reader.elevations, reader.intenzities)

        intenzity = light.intenzity(azimut, elevation)
        symetric_intenzity = light.intenzity(symetric_azimut, elevation)
        self.assertEqual(intenzity, symetric_intenzity)
Пример #27
0
    def test_different(self):
        azimut = 53
        other_azimut = 180
        elevation = 10

        reader = LdtReader(LDT_PATH)
        light = Light(reader.azimuts, reader.elevations, reader.intenzities)

        intenzity = light.intenzity(azimut, elevation)
        other_intenzity = light.intenzity(other_azimut, elevation)
        self.assertNotEqual(intenzity, other_intenzity)
Пример #28
0
    def __init__(self, light=Light(Point(-10, 10, -10), Color(1, 1, 1))):
        self.light = light
        s1 = Sphere()
        s1.material.color = Color(0.8, 1.0, 0.6)
        s1.material.diffuse = 0.7
        s1.material.specular = 0.2

        s2 = Sphere()
        t2 = scale(0.5, 0.5, 0.5)
        s2.set_transform(t2)
        self.objs = [s1, s2]
    def test_material6(self):
        position = Point(0, 0, 0)
        m = Material()

        eyev = Vector(0, 0, -1)
        normalv = Vector(0, 0, -1)
        light = Light(Point(0, 0, 10), Color(1, 1, 1))
        in_shadow = False
        result = m.lighting(Sphere(), light, position, eyev, normalv,
                            in_shadow)
        self.assertTrue(Color(0.1, 0.1, 0.1).equals(result))
Пример #30
0
    def from_config(cls, city_config_path):
        cars_filepath = Path(city_config_path) / cls.CARS_FILE
        with open(cars_filepath, 'r') as f:
            car_records = json.load(f)

        layout_filepath = Path(city_config_path) / cls.LAYOUT_FILE
        with open(layout_filepath, 'r') as f:
            layout = json.load(f)

        schedule_filepath = Path(city_config_path) / cls.SCHEDULE_FILE
        with open(schedule_filepath, 'r') as f:
            schedule = json.load(f)

        lights = {}
        roads = {}
        cars = {}

        for road_record in layout['roads']:
            id = road_record['id']
            length = road_record['length']
            roads[id] = Road(id, length)

        for light_record in layout['lights']:
            id = light_record['id']
            roads_in_ids = light_record['roads_in']
            roads_out_ids = light_record['roads_out']
            for road_in in roads_in_ids:
                roads[road_in].light_out = id
            for road_out in roads_out_ids:
                roads[road_out].light_in = id
            lights[id] = Light(id, roads_in_ids, roads_out_ids)

        for car_record in car_records:
            id = car_record['id']
            road_ids = car_record['roads']

            # TODO: Check that the order of roads is possible

            cars[id] = Car(id, road_ids)

        time_allocated = layout['time_allocated']

        for light_record in schedule:
            light_id = light_record['light']
            signals = []
            for signal_record in light_record['signals']:
                road_id = signal_record['road']
                time = signal_record['time']
                signal = Signal(road_id, time)
                signals.append(signal)
            lights[light_id].signals = signals

        return cls(roads, lights, cars, time_allocated)