virtual_knitting_machine.visualizer.visualizer_elements.diagram_elements.carriage_element module
Module containing the Carriage Trapezoid diagram element.
- class Carriage_Element(last_direction, needle_index, render_sliders, diagram_settings, **shape_kwargs)[source]
Bases:
Polygon_Element- __init__(last_direction, needle_index, render_sliders, diagram_settings, **shape_kwargs)[source]
- Parameters:
points (list[tuple[float, float]]) – The ordered coordinates of the vertices of the polygon element.
name (str) – The name-id of the shape.
stroke_width (int) – The width of the outline of the shape.
orientation (int | tuple[int, int], optional) – If given a tuple, the vertices will be oriented from the given coordinate x, y point (e.g., a center point). If given an integer, the vertices will be oriented from the vertex at that index. Defaults to orienting around the first point in the points list.
fill (str | int, optional) – The fill color of the shape or the factor to lighten the stroke color by. Defaults to no fill color.
stroke (str | float, optional) – The color of the outline of the shape or the factor to darken the fill color by. Defaults to darkening the fill color by a factor of 0.7.
**shape_kwargs (Any) – Additional keyword arguments to pass to the shape.
- property carriage_origin: tuple[float, float]
- Returns:
The origin of the carriage derived from its current position.
- Return type:
Notes
The x origin of the carriage is derived from the needle position that the carriage sits at. The Y origin of the carriage is positioned below the needle bed and labels. When transferring, the carriage is shown as a box with ambiguous direction. When not transferring, the carriage is shown as an arrow with origin as the point of the direction it is moving.
- property carriage_vertices: list[tuple[float, float]]
Returns: list[tuple[float, float]]: The vertices that draw the carriage in its current state.
- __getitem__(item)
- add_to_drawing(drawing)
Adds this element to the given svg drawing. :param drawing: The drawing to add. :type drawing: Drawing
- static darken_color(color='none', factor=0.7)
Darken a hex or named color.
- Parameters:
- Returns:
The color-string of the darkened color. If “none” color is given, this will return “black”.
- Return type:
- static fill_from_stroke(stroke, lighten_factor=0.3)
- property global_points: list[tuple[float, float]]
Returns: list[tuple[float, float]]: The global coordinates of the polygon vertices.
- property global_x: float
Returns: float: The global x coordinate of this element based on its parent’s coordinates.
- global_x_position(x)
- property global_y: float
Returns: float: The global y coordinate of this element based on its parent’s coordinates.
- global_y_position(y)
- static lighten_color(color='none', factor=0.3)
Lighten a hex or named color.
- Parameters:
- Returns:
The color-string of the lightened color. If “none” color is given, this will return “black”.
- Return type:
- property name: str
Returns: str: The unique name of this element. This will match the id of the svg element being wrapped.
- static stroke_from_fill(fill, darken_factor=0.7)
- property x: float
Returns: float: The x coordinate of this element relative to its parent (or globally).
- property x_coordinates: list[float]
Returns: list[float]: The x coordinate values for each vertex in the polygon.