|
7 | 7 | from .descriptors.color import ColorAttribute |
8 | 8 | from .context import clear |
9 | 9 | from .context import get_sceneobject_cls |
| 10 | +from compas.colors import Color |
10 | 11 | from compas.geometry import Transformation |
11 | 12 | from functools import reduce |
12 | 13 | from operator import mul |
@@ -68,6 +69,7 @@ def __init__(self, item, **kwargs): |
68 | 69 | self._node = None |
69 | 70 | self._frame = kwargs.get("frame", None) |
70 | 71 | self._transformation = kwargs.get("transformation", None) |
| 72 | + self._contrastcolor = None |
71 | 73 | self.name = kwargs.get("name", item.name or item.__class__.__name__) |
72 | 74 | self.color = kwargs.get("color", self.color) |
73 | 75 | self.opacity = kwargs.get("opacity", 1.0) |
@@ -132,6 +134,19 @@ def worldtransformation(self): |
132 | 134 |
|
133 | 135 | return worldtransformation |
134 | 136 |
|
| 137 | + @property |
| 138 | + def contrastcolor(self): |
| 139 | + if not self._contrastcolor: |
| 140 | + if self.color.is_light: |
| 141 | + self._contrastcolor = self.color.darkened(50) |
| 142 | + else: |
| 143 | + self._contrastcolor = self.color.lightened(50) |
| 144 | + return self._contrastcolor |
| 145 | + |
| 146 | + @contrastcolor.setter |
| 147 | + def contrastcolor(self, color): |
| 148 | + self._contrastcolor = Color.coerce(color) |
| 149 | + |
135 | 150 | def add(self, item, **kwargs): |
136 | 151 | """Add a child item to the scene object. |
137 | 152 |
|
|
0 commit comments