# Reference¶

class TurksHead(bights, leads, inner, outer, line, colorer=None)

Parameters: bights – the number of times the string touches the outised of the knot. leads – the number of times the string turns around the center. inner – the radius of the empty area inside the knot. outer – the radius of the knot. line – the width of the string. colorer – a Colorer instance. If None or not provided, a DefaultColorer will be used.
p

The number of bights.

q

d

The greatest common divisor of p and q.

p_prime

p divided by d.

q_prime

q divided by d.

inner_radius

The radius of the empty area inside the knot.

outer_radius

line_width

The width of the string.

draw(ctx)

Draw the knot on a cairo.Context. See documentation of PyCairo.

class Colorer

Objects passed as the colorer argument of TurksHead must implement this interface. More precisely, they must implement one of the following methods:

compute_color_hsv(knot, k, theta, altitude):

Return a tuple (h, s, v) of the color to be applied to the k-th string of the knot, at angle theta, at the given altitude.

h must be between 0 and 360 s and v must be between 0 and 1.

Parameters: knot – the TurksHead instance. k – the index of the current string. Between 0 and knot.d. theta – the angle on the current string. Between 0 and 2 * knot.q_prime * math.pi. altitude – the altitude of the string at this point. Between -1 and 1.
compute_color_rgb(knot, k, theta, altitude):

Return a tuple (r, g, b) of the color to be applied to the k-th string of the knot, at angle theta, at the given altitude.

r, g and b must be between 0 and 1.

Parameters: knot – the TurksHead instance. k – the index of the current string. Between 0 and knot.d. theta – the angle on the current string. Between 0 and 2 * knot.q_prime * math.pi. altitude – the altitude of the string at this point. Between -1 and 1.
class DefaultColorer

The Colorer used when you don’t provide one explicitly to TurksHead.

It uses one color per string (spread on the spectrum) and makes it darker when the string goes down.