AYABPNGBuilder Module

Convert knitting patterns to png files.

These png files are used to be fed into the ayab-desktop software. They only contain which meshes will be knit with a contrast color. They just contain colors.

class knittingpattern.convert.AYABPNGBuilder.AYABPNGBuilder(min_x, min_y, max_x, max_y, default_color='white')[source]

Bases: object

Convert knitting patterns to png files that only contain the color information and (x, y) coordinates.

Througout this class the term color refers to either

  • a valid html5 color name such as "black", "white"
  • colors of the form "#RGB", "#RRGGBB" and "#RRRGGGBBB"
__init__(min_x, min_y, max_x, max_y, default_color='white')[source]

Initialize the builder with the bounding box and a default color.

min_x <= x < max_x and min_y <= y < max_y are the bounds of the instructions. Instructions outside the bounds are not rendered. Any Pixel that is not set has the default_color.

Parameters:
  • min_x (int) – the lower bound of the x coordinates
  • max_x (int) – the upper bound of the x coordinates
  • min_y (int) – the lower bound of the y coordinates
  • max_y (int) – the upper bound of the y coordinates
  • default_color – a valid color
__weakref__

list of weak references to the object (if defined)

default_color
Returns:the color of the pixels that are not set

You can set this color by passing it to the constructor.

is_in_bounds(x, y)[source]
Returns:whether (x, y) is inside the bounds
Return type:bool
set_color_in_grid(color_in_grid)[source]

Set the pixel at the position of the color_in_grid to its color.

Parameters:color_in_grid

must have the following attributes:

  • color is the color to set the pixel to
  • x is the x position of the pixel
  • y is the y position of the pixel
set_colors_in_grid(some_colors_in_grid)[source]

Same as set_color_in_grid() but with a collection of colors in grid.

Parameters:some_colors_in_grid (iterable) – a collection of colors in grid for set_color_in_grid()
set_pixel(x, y, color)[source]

set the pixel at (x, y) position to color

If (x, y) is out of the bounds this does not change the image.

write_to_file(file)[source]

write the png to the file

Parameters:file – a file-like object