Chiplotle Tools

HPGL Tools

chiplotle.tools.hpgltools.convert_coordinates_to_hpgl_absolute_path(coords)
Converts an iterator of lists of coordinates e.g., [<x1, y1>, <x2, y2>, <x3, y3>, ...] into a list of PA, PD and PU HPGL commands.
chiplotle.tools.hpgltools.convert_relatives_to_absolutes(lst)
chiplotle.tools.hpgltools.get_all_coordinates(arg)

Returns all absolute coordinates for a given list of Chiplotle-HPGL commands.

Example:

>>> t = [PA((1, 2)), PR((1, 1)), ER((1, 1)), CI(100)]
>>> c = hpgltools.get_all_coordinates(t)
>>> print c
[CP(1, 2), CP(2, 3), CP(3, 4)]
chiplotle.tools.hpgltools.get_bounding_box(arg)
Returns the pair of coordinate pairs outlining the bounding box of the given HPGL drawing.
chiplotle.tools.hpgltools.get_centroid(arg)
Returns the centroid of the given Chiplotle-HPGL shapes.
chiplotle.tools.hpgltools.inflate_hpgl_string(string, filter_commands=None)

Reads a text string and “inflates” it by creating Chiplotle-HPGL class instances of the found HPGL commands.

Example:

chiplotle> sp = inflate_hpgl_string('SP1;')
chiplotle> sp
[SP(1)]

Example:

chiplotle> move = inflate_hpgl_string('IN;SP1;PA10,10;', ['IN'])
chiplotle> move
[SP(1), PA((10, 10))]
chiplotle.tools.hpgltools.inflate_hpgl_string_command(cmd_string)
Converts a string representing a single HPGL command into a Chiplotle HPGL instance. e.g., ‘PD1,2,3,4’ –> PD((1,2,3,4)).
chiplotle.tools.hpgltools.is_primitive_absolute(command)
Returns True of command is a primitive HPGL with absolute position, False if command is a non-absolute position primitive HPGL. Otherwise the function raises a TypeError exception.
chiplotle.tools.hpgltools.parse_hpgl_string(arg)
The function takes a string arg of HPGL commands, parses them (separates them) and returns them in a list.
chiplotle.tools.hpgltools.pens_updown_to_papr(lst)
Converts all PU((x1, y1, x2, y2) and PD(x1, y1, x2, y2) found in lst into (PU( ), PA(x1, y1, x2, y2)) pair sequences. The function removes the coordinates from PU and PD and places them in PR or PA, whatever was last found in lst prior to a PU or PD.
chiplotle.tools.hpgltools.pr_to_pa(arg, starting_position=None)

Converts a given PR into PA starting at starting_position.

  • arg is a PR object.
  • starting_position is a coordinate pair. Default is (0, 0).
chiplotle.tools.hpgltools.relativize(data)
Converts all absolute coordinate commands (PA, RA, EA, AA) into relative commands (PR, RR, ER, AR), so that everything has in realtive coordinate values.
chiplotle.tools.hpgltools.rotate_hpglprimitives(arg, angle)
chiplotle.tools.hpgltools.scale(obj, val)
chiplotle.tools.hpgltools.transpose(arg, val)

Input-output tools

chiplotle.tools.io.export(expr, filename, fmt='eps')

Export Chiplotle-HPGL objects to an image file format via hp2xx.

  • expr can be an iterable (e.g., list) of Chiplotle-HPGL objects or a

    single Chiplotle-HPGL object.

  • filename the file name, including path but without extension.

  • fmt is a string describing the format of the file to which the

    Chiplotle-HPGL objects will be exported. Default is ‘eps’. Valid formats are: jpg, png, tiff and many others. Please see the hp2xx documentation for details.

Note

You must have hp2xx installed before you can export Chiplote-HPGL objects to image files.

chiplotle.tools.io.import_hpgl_file(filename, filter_commands=None)

Reads a text HPGL file and “inflates” it by creating Chiplotle-HPGL class instances of the found HPGL commands.

Example:

chiplotle> square = import_hpgl_file('examples/square.hpgl')
chiplotle> square
[SP(pen=1), PU(xy=[ 100.  100.]), PD(xy=[ 200.  100.]), 
PD(xy=[ 200.  200.]), PD(xy=[ 100.  200.]), 
PD(xy=[ 100.  100.]), SP(pen=0)]
chiplotle.tools.io.save_hpgl(expr, filename)

Save text HPGL from Chiplotle-HPGL.

  • expr can be an iterable (e.g., list) or a Chiplotle-HPGL object.
  • filename the full file name, including path and extension (usually .hpgl or .plt)
chiplotle.tools.io.view(expr, fmt='eps')

Displays Chiplotle-HPGL objects for prevewing.

  • expr can be an iterable (e.g., list) or a Chiplotle-HPGL object.

  • fmt is the file format to which the given expr will be

    converted for viewing. The default is ‘eps’.

Math tools

chiplotle.tools.mathtools.bezier_interpolation(control_points, points_to_compute, weight)

Computes Bezier interpolations from given control_points. This uses the generalized formula for bezier curves: http://en.wikipedia.org/wiki/B%C3%A9zier_curve#Generalization

  • control_points : A list of (x, y) control points.
  • points_to_compute: An int of the number of points to compute.
  • weight: A list of weights for control points.
chiplotle.tools.mathtools.catmull_interpolation(control_points, points_to_compute)
Computes Catmull-Rom interpolations from given control_points. first and last point are not on the curve, but define initial and final tangent - control_points : A list of (x, y) control points. - points_to_compute: An int of the number of points to compute.
chiplotle.tools.mathtools.cumsum(lst)
Returns the cumulative sum of the values in lst.
chiplotle.tools.mathtools.difference(seq)
Returns the difference between consecutive elements in seq. i.e., first derivative.
chiplotle.tools.mathtools.factors(n)

Return factors of positive n in increasing order:

>>> mathtools.factors(84)
[1, 2, 2, 3, 7]
>>> for n in range(10, 20):
...   print n, mathtools.factors(n)
... 
10 [1, 2, 5]
11 [1, 11]
12 [1, 2, 2, 3]
13 [1, 13]
14 [1, 2, 7]
15 [1, 3, 5]
16 [1, 2, 2, 2, 2]
17 [1, 17]
18 [1, 2, 3, 3]
19 [1, 19]
chiplotle.tools.mathtools.interpolate_cosine(y1, y2, mu)

Cosine interpolate y1 and y2 with mu normalized [0, 1].

Example:

>>> mathtools.interpolate_cosine(0, 1, 0.5) 
0.49999999999999994
chiplotle.tools.mathtools.interpolate_exponential(y1, y2, mu, exp=1)

Exponential interpolate y1 and y2 with mu normalized [0, 1].

Example:

>>> mathtools.interpolate_exponential(0, 1, 0.5, 4)
0.0625

Set exp to the exponent of interpolation.

chiplotle.tools.mathtools.interpolate_linear(y1, y2, mu)

Linear interpolate y1 and y2 with mu normalized [0, 1].

Example:

>>> mathtools.interpolate_linear(0, 1, 0.5)
0.5
chiplotle.tools.mathtools.lcm(a, b)
returns the lowest common multiple of a & b
chiplotle.tools.mathtools.pascal_row(n)
Returns the nth row of Pascal’s Triangle.
chiplotle.tools.mathtools.polar_to_xy(args)
Converts polar (r, A) to Cartesian (x y) coordinates, where r is the radius and A is the angle in radians.
chiplotle.tools.mathtools.rotate_2d(xy, angle, pivot=(0, 0))

2D rotation.

  • xy is an (x, y) coordinate pair or a list of coordinate pairs.
  • angle is the angle of rotation in radians.
  • pivot the point around which to rotate xy.

Returns a Coordinate or a CoordinateArray.

chiplotle.tools.mathtools.rotate_3d(xyz, xyzrot)

3D rotation.

  • xyz is a triple (x, y, z) of coordinates.
  • xyzrot is a triple (xr, yr, zr) of angles of roation.
chiplotle.tools.mathtools.rotate_coordinate_2d(xy, angle, pivot)

Coordinate 2D rotation.

  • xy is an (x, y) coordinate pair.
  • angle is the angle of rotation in radians.
  • pivot the point around which to rotate xy.

Returns a Coordinate.

chiplotle.tools.mathtools.rotate_coordinatearray_2d(xylst, angle, pivot)

2D rotation of list of coordinate pairs (CoordinateArray).

  • xylst list of (x, y) coordinate pairs.
  • angle is the angle of rotation in radians.
  • pivot the point around which to rotate xy.

Returns a CoordinateArray.

chiplotle.tools.mathtools.superformula(a, b, m, n1, n2, n3, phi)
Computes the position of the point on a superformula curve. Superformula has first been proposed by Johan Gielis and is a generalization of superellipse. see: http://en.wikipedia.org/wiki/Superformula
chiplotle.tools.mathtools.xy_to_polar(args)

Converts cartesian to polar coordinates. Argument may be two coordinates x, y, a tuple (x, y), or a Coordinate(x, y).

Returns an (r, a) tuple, where r is the magnitude, a is the angle in radians.

Table Of Contents

Previous topic

Chiplotle Known Plotters

Next topic

Coding Guidelines and Standards