def create_light(x,y, value, owner=None): light=lights.Light(x,y, value, owner) light.fov_map=fov_init() register_light(light) if owner: #light follows owner if applicable owner.observer_add(light) return light
def test_shadows__full_scene(self): """Test that we identify a shadow in a full scene""" # First sphere is at z=10 s1 = shapes.Sphere() s1.set_transform(transforms.Translate(0, 0, 10)) # Second sphere is at the origin s2 = shapes.Sphere() s2.material = materials.Material() # Light is at z=-10 l1 = lights.Light(position=points.Point(0, 0, -10), intensity=colors.Color(1, 1, 1)) scene = scenes.Scene(objects=[s1, s2], lights=[l1]) # The ray is at z=5 (i.e. between the spheres), pointing at the further # out sphere ray = rays.Ray(points.Point(0, 0, 5), vectors.Vector(0, 0, 1)) isection = intersections.Intersection(s2, 4) comps = isection.precompute(ray) result, _ = scene.shade_hit(comps) self.assertEqual(result, colors.Color(0.1, 0.1, 0.1))
def test_render_scene(self): """Test we can render a pixel in a simple scene""" # Inner sphere size 0.5, centered on the origin s1 = shapes.Sphere() s1.set_transform(transforms.Scale(0.5,0.5,0.5)) # Outer sphere centered on the origin, size 1.0 s2 = shapes.Sphere() s2.material = materials.Material( color=colors.Color(0.8, 1.0, 0.6), diffuse=0.7, specular=0.2) l1 = lights.Light( position=points.Point(-10, 10, -10), intensity=colors.Color(1, 1, 1) ) scene = scenes.Scene( objects = [s1, s2], lights = [l1] ) cam = cameras.Camera(11, 11, math.pi/2) from_point = points.Point(0, 0, -5) to_point = points.Point(0, 0, 0) up = vectors.Vector(0, 1, 0) cam.transform = transforms.ViewTransform(from_point, to_point, up) image = cam.render(scene) self.assertEqual(image.get(5, 5), colors.Color(0.3807, 0.4758, 0.2855))
def test_init_color(): light = lights.Light(BRIDGE_IP, USERNAME, 1, LIGHTS['1']) assert light.hue == light.init_hue == 17738 assert light.sat == light.init_sat == 100 assert light.bri == light.init_bri == 254 assert light.on is light.init_on is True assert light.livingwhite is False
def test_set_state(m): light = lights.Light(BRIDGE_IP, USERNAME, 1, LIGHTS['1']) m.register_uri('PUT', 'http://127.0.0.1/api/fake/lights/1/state') light.set_state(hue=47) assert light.hue == 47 assert light.sat == 100 assert light.bri == 254 assert light.on is True assert m.last_request.json() == {'hue': 47} light.set_state(hue=47, sat=12, on=False) assert light.hue == 47 assert light.sat == 12 assert light.bri == 254 assert light.on is False assert m.last_request.json() == {u'on': False, u'sat': 12} light.set_state(hue=47, sat=99, bri=15, on=False, transition_time=321) assert light.hue == 47 assert light.sat == 99 assert light.bri == 15 assert light.on is False assert m.last_request.json() == { u'bri': 15, u'sat': 99, u'transitiontime': 321 } assert light.init_hue == 17738 assert light.init_sat == 100 assert light.init_bri == 254 assert light.init_on is True light.restore_initial_state() assert light.hue == 17738 assert light.sat == 100 assert light.bri == 254 assert light.on is True assert m.last_request.json() == { u'bri': 254, u'hue': 17738, u'on': True, u'sat': 100, u'transitiontime': 0 }
def get_lights_by_ids(bridge_ip, username, light_ids=None): req = requests.get('http://{}/api/{}/lights'.format(bridge_ip, username)) res = req.json() if light_ids is None: light_ids = res.keys() if light_ids == ['']: return {} found = {} for light_id in light_ids: found[light_id] = lights.Light(bridge_ip, username, light_id, res[light_id]) return found
def setUp(self): """Set up a default scene for quick testing""" # Inner sphere size 0.5, centered on the origin self.s1 = shapes.Sphere() self.s1.set_transform(transforms.Scale(0.5, 0.5, 0.5)) # Outer sphere centered on the origin, size 1.0 self.s2 = shapes.Sphere() self.s2.material = materials.Material(color=colors.Color( 0.8, 1.0, 0.6), diffuse=0.7, specular=0.2) self.l1 = lights.Light(position=points.Point(-10, 10, -10), intensity=colors.Color(1, 1, 1)) self.default_scene = scenes.Scene(objects=[self.s1, self.s2], lights=[self.l1])
def test_text_init(self): "Test the Lights object creation from text" # 1. Create Lights object from text myobj = lights.Light(text="position=<-3, 11> velocity=< 1, -2>") # 2. Make sure it has the expected values self.assertEqual(myobj.part2, False) self.assertEqual(myobj.text.startswith('position'), True) self.assertEqual(myobj.posX, -3) self.assertEqual(myobj.posY, 11) self.assertEqual(myobj.velX, 1) self.assertEqual(myobj.velY, -2) # 3. Move forward a step myobj.step() self.assertEqual(myobj.posX, -2) self.assertEqual(myobj.posY, 9) self.assertEqual(myobj.velX, 1) self.assertEqual(myobj.velY, -2)
def test_empty_init(self): "Test the default Light creation" # 1. Create default Light object myobj = lights.Light() # 2. Make sure it has the default values self.assertEqual(myobj.part2, False) self.assertEqual(myobj.text, None) self.assertEqual(myobj.posX, 0) self.assertEqual(myobj.posY, 0) self.assertEqual(myobj.velX, 0) self.assertEqual(myobj.velY, 0) # 3. Move forward a step myobj.step() self.assertEqual(myobj.posX, 0) self.assertEqual(myobj.posY, 0) self.assertEqual(myobj.velX, 0) self.assertEqual(myobj.velY, 0)
def test_reflection__infinite_recursion(self): """Test that we don't break if there is infinite recursion""" # Two parallel planes s1 = shapes.Plane(material=materials.Material(reflective=1)) s1.set_transform(transforms.Translate(0, -1, 0)) # Second sphere is at the origin s2 = shapes.Plane(material=materials.Material(reflective=1)) s2.set_transform(transforms.Translate(0, 1, 0)) # Light is at z=-10 l1 = lights.Light(position=points.Point(0, 0, 0), intensity=colors.Color(1, 1, 1)) scene = scenes.Scene(objects=[s1, s2], lights=[l1]) r = rays.Ray(points.Point(0, 0, 0), vectors.Vector(0, 1, 0)) # If this is working the following will NOT cause a stack trace scene.color_at(r)
def eval_light(env, stack): color, stack = pop(stack) d, stack = pop(stack) return env, push(stack, lights.Light(get_point(d), get_point(color)))
def test_init_white(): light = lights.Light(BRIDGE_IP, USERNAME, 2, LIGHTS['2']) assert light.bri == light.init_bri == 254 assert light.on is light.init_on is True assert light.livingwhite is True