virtual_knitting_machine.visualizer.visualizer_elements.visualizer_shapes module
Module containing the Visualizer_Shape class and common shapes used in the diagrams.
- class Visualizer_Shape(x, y, name, stroke_width, fill='none', stroke=0.7, **shape_kwargs)[source]
Bases:
Visualizer_Element- __init__(x, y, name, stroke_width, fill='none', stroke=0.7, **shape_kwargs)[source]
- Parameters:
x (int) – The x coordinate of the shape.
y (int) – The y coordinate of the shape.
name (str) – The name-id of the shape.
stroke_width (int) – The width of the outline of the shape.
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.
- 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_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)
- class Polygon_Element(points, name, stroke_width, orientation=0, fill='none', stroke=0.7, **shape_kwargs)[source]
Bases:
Visualizer_ShapeA wrapper for Polygon SVG elements.
- __init__(points, name, stroke_width, orientation=0, fill='none', stroke=0.7, **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 x_coordinates: list[float]
Returns: list[float]: The x coordinate values for each vertex in the polygon.
- property y_coordinates: list[float]
Returns: list[float]: The y coordinate values for each vertex in the polygon.
- property global_points: list[tuple[float, float]]
Returns: list[tuple[float, float]]: The global coordinates of the polygon vertices.
- 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_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)
- class Triangle_Element(side_length, x, y, name, stroke_width, fill='none', stroke=0.7, **shape_kwargs)[source]
Bases:
Polygon_ElementWrapper class for equilateral Triangle SVG elements. The triangle points downward and is oriented to its bottom index.
- __init__(side_length, x, y, name, stroke_width, fill='none', stroke=0.7, **shape_kwargs)[source]
Initialize the Triangle SVG element.
- Parameters:
side_length (float) – The length of the side of the equilateral triangle.
x (float) – The x coordinate of the bottom vertex of the triangle.
y (float) – The y coordinate of the top vertex of the triangle.
name (str) – The name-id of the shape.
stroke_width (int) – The width of the outline of the shape.
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 top_left_vertex: tuple[float, float]
Returns: tuple[float, float]: The top left vertex of the equilateral triangle pointing downward.
- property top_right_vertex: tuple[float, float]
Returns: tuple[float, float]: The top right vertex of the equilateral triangle pointing downward.
- property bottom_vertex: tuple[float, float]
Returns: tuple[float, float]: The bottom vertex of the equilateral triangle pointing downward.
- __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.
- class Rect_Element(width, height, x, y, name, stroke_width, fill='none', stroke=0.7, **shape_kwargs)[source]
Bases:
Visualizer_ShapeWrapper class for Rectangle SVG elements.
- __init__(width, height, x, y, name, stroke_width, fill='none', stroke=0.7, **shape_kwargs)[source]
Initialize the Rectangle SVG element.
- Parameters:
width (float) – The width of the rectangle in pixels.
height (float) – The height of the rectangle in pixels.
x (float) – The x coordinate of the rectangle’s top left corner.
y (float) – The y coordinate of the rectangle’s top left corner.
name (str) – The name-id of the shape.
stroke_width (int) – The width of the outline of the shape.
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.
- 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_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)
- class Circle_Element(radius, x, y, name, stroke_width, fill='none', stroke=0.7, **shape_kwargs)[source]
Bases:
Visualizer_ShapeWrapper class for Circle SVG elements.
- __init__(radius, x, y, name, stroke_width, fill='none', stroke=0.7, **shape_kwargs)[source]
Initialize the Circle SVG element.
- Parameters:
radius (int) – The radius of the circle in pixels.
x (int) – The x coordinate of the rectangle’s top left corner.
y (int) – The y coordinate of the rectangle’s top left corner.
name (str) – The name-id of the shape.
stroke_width (int) – The width of the outline of the shape.
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.
- 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_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)