sketchkit.core package¶
Submodules¶
sketchkit.core.camera module¶
- class sketchkit.core.camera.Camera(xyz: tuple[float, float, float] | ndarray = array([0, 0, 0]), wxyz: tuple[float, float, float, float] | ndarray = array([1, 0, 0, 0]), fov_x: float = 40, fov_y: float = 40, z_far: float = 1000, z_near: float = 0.1, coordinate_type='RDF')[source]¶
Bases:
Object3D- property extrinsics¶
- property intrinsics¶
- class sketchkit.core.camera.Object3D(xyz: tuple[float, float, float] | ndarray = array([0., 0., 0.]), wxyz: tuple[float, float, float, float] | ndarray = array([1., 0., 0., 0.]))[source]¶
Bases:
object- property pitch¶
- property roll¶
- property rotation_matrix¶
- property transform_matrix¶
- property translation_matrix¶
- property yaw¶
sketchkit.core.sketch module¶
- class sketchkit.core.sketch.Curve(p_start: Vertex, p_end: Vertex, p_crtl1: Point, p_crtl2: Point)[source]¶
Bases:
objectCurve defined by two vertices and two control points.
Connects two vertices (start and end) with optional control points for a curved path. Visual properties (color, pressure, thickness, opacity) are applied to both vertices together.
Notes
When setting properties, the same value is applied to both start and end vertices. Numeric properties are converted to np.float32 automatically.
- property color¶
Colors of the start and end vertices.
- Returns:
A two-element list of RGB colors for the start and end vertices (each as float32 arrays) or None.
- Return type:
list[np.ndarray | None]
- get_division_points(ts: ndarray) ndarray[source]¶
Get points on the curve at specified parameter values.
- Parameters:
ts (np.ndarray) – Array of parameter values between 0 and 1.
- Returns:
Array of points on the curve at the specified parameter values.
- Return type:
np.ndarray
- is_line() bool[source]¶
Check if the curve is a line.
- Returns:
True if the curve is a line, False otherwise.
- Return type:
bool
- property length: float¶
Calculate the length of the curve.
- Returns:
Length of the curve.
- Return type:
float
- property np_points: ndarray¶
Get the points of the curve.
- Returns:
Array of points (shape: [4, 2]).
- Return type:
np.ndarray
- property opacity¶
Opacities of the start and end vertices.
- Returns:
Two-element list of opacities or None.
- Return type:
list[np.float32 | None]
- property pressure¶
Pressures of the start and end vertices.
- Returns:
Two-element list of pressures or None.
- Return type:
list[np.float32 | None]
- svg_length() float[source]¶
Calculate the length of the curve in SVG path units.
- Returns:
Length of the curve in SVG path units.
- Return type:
float
- property thickness¶
Thicknesses of the start and end vertices.
- Returns:
Two-element list of thicknesses or None.
- Return type:
list[np.float32 | None]
- class sketchkit.core.sketch.Path(curves: list[Curve] | None = None)[source]¶
Bases:
objectCollection of curves.
Manages multiple curves and applies common operations to all of them.
Examples
>>> path = Path([curve1, curve2, curve3]) >>> path.color = (1.0, 0.0, 0.0) # Set all curves to red >>> path.thickness = 2.5 # Set all curves to thickness 2.5 >>> path.curve_num 3
- property color¶
Colors for each curve.
- Returns:
For each curve, a two-element list of vertex colors (RGB arrays) or None.
- Return type:
list[list[np.ndarray | None]]
- curve_lengths()[source]¶
Calculate the length of each curve in the path.
- Returns:
Total length of the path.
- Return type:
float
- property curve_num¶
Number of curves in the path.
- Returns:
Count of curves.
- Return type:
int
- get_division_points(ts: ndarray) ndarray[source]¶
Get points on the path at parameters ts.
- Parameters:
ts (np.ndarray) – Array of parameter values between 0 and 1.
- Returns:
Array of points on the path at parameters ts.
- Return type:
np.ndarray
- property length¶
Calculate the total length of all curves in the path.
- Returns:
Total length of the path.
- Return type:
float
- property opacity¶
Opacities for each curve.
- Returns:
For each curve, a two-element list of vertex opacities or None.
- Return type:
list[list[np.float32 | None]]
- property pressure¶
Pressures for each curve.
- Returns:
For each curve, a two-element list of vertex pressures or None.
- Return type:
list[list[np.float32 | None]]
- svg_curve_lengths() list[float][source]¶
Calculate the lengths of each curve in SVG path units.
- Returns:
Array of lengths for each curve in SVG path units.
- Return type:
np.ndarray
- svg_length() float[source]¶
Calculate the total length of all curves in the path in SVG path units.
- Returns:
Total length of the path in SVG path units.
- Return type:
float
- property thickness¶
Thicknesses for each curve.
- Returns:
For each curve, a two-element list of vertex thicknesses or None.
- Return type:
list[list[np.float32 | None]]
- class sketchkit.core.sketch.Point(x: float | float32, y: float | float32)[source]¶
Bases:
object2D point.
Represents a 2D point with x and y coordinates stored as 32-bit floats.
- x¶
X coordinate.
- Type:
np.float32
- y¶
Y coordinate.
- Type:
np.float32
- class sketchkit.core.sketch.Sketch(paths: list[Path] | None = None)[source]¶
Bases:
objectSketch composed of multiple paths.
A Sketch collects Path objects to form a complete drawing and exposes convenient accessors for color, pressure, thickness, and opacity.
Examples
>>> sketch = Sketch([path1, path2, path3]) >>> sketch.color = (1.0, 0.0, 0.0) # Set all paths to red >>> sketch.thickness = 2.5 # Set all paths to thickness 2.5
- property color¶
Colors per path.
- Returns:
For each path, a list of curve colors where each curve has a two-element list of vertex colors.
- Return type:
list[list[list[np.ndarray | None]]]
- property curve_num¶
Total number of curves across all paths.
- Returns:
Sum of curves in all paths.
- Return type:
int
- property opacity¶
Opacities per path.
- Returns:
For each path, a list of curve opacities where each curve has a two-element list of vertex values.
- Return type:
list[list[list[np.float32 | None]]]
- property path_num¶
Number of paths in the sketch.
- Returns:
Count of paths.
- Return type:
int
- property pressure¶
Pressures per path.
- Returns:
For each path, a list of curve pressures where each curve has a two-element list of vertex pressures.
- Return type:
list[list[list[np.float32 | None]]]
- property thickness¶
Thicknesses per path.
- Returns:
For each path, a list of curve thicknesses where each curve has a two-element list of vertex values.
- Return type:
list[list[list[np.float32 | None]]]
- to_svg(size: int = 512, filename: str = None, fit_size: bool = False) str[source]¶
Convert the sketch to an SVG string.
- Parameters:
size – Size of the SVG canvas (width and height in pixels).
filename – Optional filename to save the SVG.
fit_size – If True, scale and center the sketch while preserving aspect ratio.
- Returns:
SVG representation of the sketch.
- Return type:
str
- class sketchkit.core.sketch.Vertex(x: float | float32, y: float | float32, pressure: None | float | float32 = None, thickness: None | float | float32 = None, color: None | tuple[float, float, float] | ndarray = None, opacity: None | float | float32 = None)[source]¶
Bases:
PointVertex point with drawing attributes.
Extends Point with curve-specific properties: pressure, thickness, color, and opacity for rendering.
- pressure¶
Normalized pressure value.
- Type:
np.float32 | None
- thickness¶
Stroke thickness value.
- Type:
np.float32 | None
- color¶
RGB color array with float32 dtype.
- Type:
np.ndarray | None
- opacity¶
Opacity value (0.0-1.0).
- Type:
np.float32 | None
sketchkit.core.sketch3d module¶
Module contents¶
- class sketchkit.core.Curve(p_start: Vertex, p_end: Vertex, p_crtl1: Point, p_crtl2: Point)[source]¶
Bases:
objectCurve defined by two vertices and two control points.
Connects two vertices (start and end) with optional control points for a curved path. Visual properties (color, pressure, thickness, opacity) are applied to both vertices together.
Notes
When setting properties, the same value is applied to both start and end vertices. Numeric properties are converted to np.float32 automatically.
- property color¶
Colors of the start and end vertices.
- Returns:
A two-element list of RGB colors for the start and end vertices (each as float32 arrays) or None.
- Return type:
list[np.ndarray | None]
- get_division_points(ts: ndarray) ndarray[source]¶
Get points on the curve at specified parameter values.
- Parameters:
ts (np.ndarray) – Array of parameter values between 0 and 1.
- Returns:
Array of points on the curve at the specified parameter values.
- Return type:
np.ndarray
- is_line() bool[source]¶
Check if the curve is a line.
- Returns:
True if the curve is a line, False otherwise.
- Return type:
bool
- property length: float¶
Calculate the length of the curve.
- Returns:
Length of the curve.
- Return type:
float
- property np_points: ndarray¶
Get the points of the curve.
- Returns:
Array of points (shape: [4, 2]).
- Return type:
np.ndarray
- property opacity¶
Opacities of the start and end vertices.
- Returns:
Two-element list of opacities or None.
- Return type:
list[np.float32 | None]
- property pressure¶
Pressures of the start and end vertices.
- Returns:
Two-element list of pressures or None.
- Return type:
list[np.float32 | None]
- svg_length() float[source]¶
Calculate the length of the curve in SVG path units.
- Returns:
Length of the curve in SVG path units.
- Return type:
float
- property thickness¶
Thicknesses of the start and end vertices.
- Returns:
Two-element list of thicknesses or None.
- Return type:
list[np.float32 | None]
- class sketchkit.core.Path(curves: list[Curve] | None = None)[source]¶
Bases:
objectCollection of curves.
Manages multiple curves and applies common operations to all of them.
Examples
>>> path = Path([curve1, curve2, curve3]) >>> path.color = (1.0, 0.0, 0.0) # Set all curves to red >>> path.thickness = 2.5 # Set all curves to thickness 2.5 >>> path.curve_num 3
- property color¶
Colors for each curve.
- Returns:
For each curve, a two-element list of vertex colors (RGB arrays) or None.
- Return type:
list[list[np.ndarray | None]]
- curve_lengths()[source]¶
Calculate the length of each curve in the path.
- Returns:
Total length of the path.
- Return type:
float
- property curve_num¶
Number of curves in the path.
- Returns:
Count of curves.
- Return type:
int
- get_division_points(ts: ndarray) ndarray[source]¶
Get points on the path at parameters ts.
- Parameters:
ts (np.ndarray) – Array of parameter values between 0 and 1.
- Returns:
Array of points on the path at parameters ts.
- Return type:
np.ndarray
- property length¶
Calculate the total length of all curves in the path.
- Returns:
Total length of the path.
- Return type:
float
- property opacity¶
Opacities for each curve.
- Returns:
For each curve, a two-element list of vertex opacities or None.
- Return type:
list[list[np.float32 | None]]
- property pressure¶
Pressures for each curve.
- Returns:
For each curve, a two-element list of vertex pressures or None.
- Return type:
list[list[np.float32 | None]]
- svg_curve_lengths() list[float][source]¶
Calculate the lengths of each curve in SVG path units.
- Returns:
Array of lengths for each curve in SVG path units.
- Return type:
np.ndarray
- svg_length() float[source]¶
Calculate the total length of all curves in the path in SVG path units.
- Returns:
Total length of the path in SVG path units.
- Return type:
float
- property thickness¶
Thicknesses for each curve.
- Returns:
For each curve, a two-element list of vertex thicknesses or None.
- Return type:
list[list[np.float32 | None]]
- class sketchkit.core.Point(x: float | float32, y: float | float32)[source]¶
Bases:
object2D point.
Represents a 2D point with x and y coordinates stored as 32-bit floats.
- x¶
X coordinate.
- Type:
np.float32
- y¶
Y coordinate.
- Type:
np.float32
- class sketchkit.core.Sketch(paths: list[Path] | None = None)[source]¶
Bases:
objectSketch composed of multiple paths.
A Sketch collects Path objects to form a complete drawing and exposes convenient accessors for color, pressure, thickness, and opacity.
Examples
>>> sketch = Sketch([path1, path2, path3]) >>> sketch.color = (1.0, 0.0, 0.0) # Set all paths to red >>> sketch.thickness = 2.5 # Set all paths to thickness 2.5
- property color¶
Colors per path.
- Returns:
For each path, a list of curve colors where each curve has a two-element list of vertex colors.
- Return type:
list[list[list[np.ndarray | None]]]
- property curve_num¶
Total number of curves across all paths.
- Returns:
Sum of curves in all paths.
- Return type:
int
- property opacity¶
Opacities per path.
- Returns:
For each path, a list of curve opacities where each curve has a two-element list of vertex values.
- Return type:
list[list[list[np.float32 | None]]]
- property path_num¶
Number of paths in the sketch.
- Returns:
Count of paths.
- Return type:
int
- property pressure¶
Pressures per path.
- Returns:
For each path, a list of curve pressures where each curve has a two-element list of vertex pressures.
- Return type:
list[list[list[np.float32 | None]]]
- property thickness¶
Thicknesses per path.
- Returns:
For each path, a list of curve thicknesses where each curve has a two-element list of vertex values.
- Return type:
list[list[list[np.float32 | None]]]
- to_svg(size: int = 512, filename: str = None, fit_size: bool = False) str[source]¶
Convert the sketch to an SVG string.
- Parameters:
size – Size of the SVG canvas (width and height in pixels).
filename – Optional filename to save the SVG.
fit_size – If True, scale and center the sketch while preserving aspect ratio.
- Returns:
SVG representation of the sketch.
- Return type:
str
- class sketchkit.core.Vertex(x: float | float32, y: float | float32, pressure: None | float | float32 = None, thickness: None | float | float32 = None, color: None | tuple[float, float, float] | ndarray = None, opacity: None | float | float32 = None)[source]¶
Bases:
PointVertex point with drawing attributes.
Extends Point with curve-specific properties: pressure, thickness, color, and opacity for rendering.
- pressure¶
Normalized pressure value.
- Type:
np.float32 | None
- thickness¶
Stroke thickness value.
- Type:
np.float32 | None
- color¶
RGB color array with float32 dtype.
- Type:
np.ndarray | None
- opacity¶
Opacity value (0.0-1.0).
- Type:
np.float32 | None