Classes¶
HexColor ¶
HexColor(hex_code)
Represents a hexadecimal color code.
Initialize a HexColor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
hex_code
|
str
|
Hex color string, e.g., "#FFF" or "#FFFFFF". |
required |
Raises:
Type | Description |
---|---|
ValueError
|
If hex_code is not valid. |
Source code in opencatwebjson/classes.py
10 11 12 13 14 15 16 17 18 19 20 21 22 |
|
Range01 ¶
Range01(value)
Represents a float value restricted to the range [0, 1].
Source code in opencatwebjson/classes.py
31 32 33 34 |
|
ScaleOffset ¶
ScaleOffset(scale, offset)
Represents a scale (0-1) with an offset for positioning or sizing.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
scale
|
Number
|
Scale factor (0 to 1). |
required |
offset
|
Number
|
Pixel offset. |
required |
Raises:
Type | Description |
---|---|
ValueError
|
If scale is not between 0 and 1. |
Source code in opencatwebjson/classes.py
46 47 48 49 50 51 52 53 54 55 56 57 58 |
|
Vector2 ¶
Vector2(x, y)
Represents a 2D vector using scale + offset for x and y axes.
Source code in opencatwebjson/classes.py
67 68 69 |
|
to_pixels ¶
to_pixels(parent_width, parent_height)
Convert scale+offset to absolute pixel coordinates.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
parent_width
|
Number
|
Width of parent container in pixels. |
required |
parent_height
|
Number
|
Height of parent container in pixels. |
required |
Returns:
Type | Description |
---|---|
tuple[Number, Number]
|
tuple[Number, Number]: Pixel coordinates (x, y). |
Source code in opencatwebjson/classes.py
74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
|
Size2 ¶
Size2(width, height)
Represents a 2D size using scale + offset for width and height.
Source code in opencatwebjson/classes.py
93 94 95 |
|
to_pixels ¶
to_pixels(parent_width, parent_height)
Convert scale+offset to absolute pixel size.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
parent_width
|
Number
|
Width of parent container in pixels. |
required |
parent_height
|
Number
|
Height of parent container in pixels. |
required |
Returns:
Type | Description |
---|---|
tuple[Number, Number]
|
tuple[Number, Number]: Size in pixels (width, height). |
Source code in opencatwebjson/classes.py
100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
|
Rotation ¶
Rotation(degrees)
Represents a rotation in degrees.
Source code in opencatwebjson/classes.py
119 120 |
|
set ¶
set(degrees)
Set the rotation to a specific angle.
Source code in opencatwebjson/classes.py
125 126 127 |
|
add ¶
add(delta)
Add delta degrees to the current rotation.
Source code in opencatwebjson/classes.py
129 130 131 |
|
normalized_360 ¶
normalized_360()
Return rotation normalized to [0, 360) degrees.
Source code in opencatwebjson/classes.py
133 134 135 |
|
normalized_180 ¶
normalized_180()
Return rotation normalized to [-180, 180) degrees.
Source code in opencatwebjson/classes.py
137 138 139 140 141 142 |
|
to_radians ¶
to_radians()
Convert rotation to radians.
Source code in opencatwebjson/classes.py
144 145 146 |
|
GradientStop ¶
GradientStop(position, value)
Represents a stop in a gradient with a position and a value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
position
|
float
|
Position along gradient (0 to 1). |
required |
value
|
Value at this stop (float for transparency, str for color). |
required |
Raises:
Type | Description |
---|---|
ValueError
|
If position is not between 0 and 1. |
Source code in opencatwebjson/classes.py
152 153 154 155 156 157 158 159 160 161 162 163 164 |
|
TransparencyGradient ¶
TransparencyGradient(stops)
Represents a gradient of transparency values (0-1).
Source code in opencatwebjson/classes.py
173 174 175 176 177 |
|
get_value_at ¶
get_value_at(position)
Get interpolated transparency at a given position.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
position
|
float
|
Position along gradient (0 to 1). |
required |
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
Interpolated transparency value. |
Source code in opencatwebjson/classes.py
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
|
ColorGradient ¶
ColorGradient(stops)
Represents a gradient of color values (hex strings).
Source code in opencatwebjson/classes.py
208 209 210 211 212 |
|
get_value_at ¶
get_value_at(position)
Get color at a given position.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
position
|
float
|
Position along gradient (0 to 1). |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
Hex color at the given position. |
Source code in opencatwebjson/classes.py
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 |
|