A far-away light with a given direction.
| 49 | |
| 50 | |
| 51 | class DirectionalLight(Light): |
| 52 | """A far-away light with a given direction. |
| 53 | """ |
| 54 | |
| 55 | def __init__(self, direction, color, strength): |
| 56 | """Initialize a directional light with the given direction, color, and strength. |
| 57 | |
| 58 | Parameters |
| 59 | ---------- |
| 60 | direction : (3,) float |
| 61 | A unit vector indicating the direction of the light. |
| 62 | color : (3,) float |
| 63 | The RGB color of the light in (0,1). |
| 64 | strength : float |
| 65 | The strength of the light. |
| 66 | """ |
| 67 | self._direction = direction |
| 68 | if np.linalg.norm(direction) > 0: |
| 69 | self._direction = direction / np.linalg.norm(direction) |
| 70 | super(DirectionalLight, self).__init__(color, strength) |
| 71 | |
| 72 | @property |
| 73 | def direction(self): |
| 74 | """(3,) float: A unit vector indicating the direction of the light. |
| 75 | """ |
| 76 | return self._direction |
| 77 | |
| 78 | @direction.setter |
| 79 | def direction(self, d): |
| 80 | self._direction = d |
| 81 | |
| 82 | class PointLight(Light): |
| 83 | """A nearby point light source that shines in all directions. |
no outgoing calls
no test coverage detected