csirmaz.openscad-py/openscad_py/color.py

22 lines
597 B
Python
Raw Normal View History

2024-11-30 22:11:59 +00:00
from typing import Union as TUnion
from typing import List
import math
from openscad_py.object_ import Object
class Color(Object):
2024-12-01 15:51:43 +00:00
"""Represents a color applied to an object.
See https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Transformations#color
"""
2024-11-30 22:11:59 +00:00
2024-12-01 15:51:43 +00:00
def __init__(self, child: Object, r: float, g: float, b: float, a: float = 1.):
2024-11-30 22:11:59 +00:00
self.color = [r, g, b, a]
self.child = child
def render(self) -> str:
2024-11-30 22:45:02 +00:00
"""Render the object into OpenSCAD code"""
2024-11-30 22:11:59 +00:00
return f"color(c=[{','.join([str(c) for c in self.color])}]){{ {self.child.render()} }}"