Bot

class shoebot.grammar.NodeBot(canvas=None, namespace=None, vars=None)
color_mode = 'rgb'
color_range = 1
image(path, x, y, width=None, height=None, alpha=1.0, data=None, draw=True, **kwargs)

Draws a image with (x,y) as the top left corner.

If width and height are specified, resize the image to fit.

form path, in x,y and resize it to width, height dimensions.

Parameters
  • path (filename) – location of the image on disk

  • x (float) – x-coordinate of the top left corner

  • y (float) – y-coordinate of the top left corner

  • width (float or None) – image width (leave blank to use its original width)

  • height (float or None) – image height (leave blank to use its original height)

  • alpha (float) – opacity

  • data (binary data) – image data to load. Use this instead of path if you want to load an image from memory or have another source (e.g. using the web library)

  • draw (bool) – whether to place the image immediately on the canvas or not

imagesize(path)
Parameters

path – Path to image file.

Returns

image size as a (width, height) tuple

rect(x, y, width, height, roundness=0.0, draw=True, **kwargs)

Draw a rectangle.

Parameters
  • x – top left x-coordinate

  • y – top left y-coordinate

  • width – rectangle width

  • height – rectangle height

  • roundness – rounded corner radius

  • draw (boolean) – whether to draw the shape on the canvas or not

  • fill – fill color

Returns

BezierPath representing the rectangle

rectmode(mode=None)

Get or set the current rectmode.

Parameters

mode (CORNER, CENTER or CORNERS) – the mode to draw new rectangles in

Returns

current rectmode value

ellipse(x, y, width, height, draw=True, **kwargs)

Draw an ellipse.

Parameters
  • x – top left x-coordinate

  • y – top left y-coordinate

  • width – ellipse width

  • height – ellipse height

  • draw (boolean) – whether to draw the shape on the canvas or not

Returns

BezierPath representing the ellipse

oval(x, y, width, height, draw=True, **kwargs)

Draw an ellipse.

Parameters
  • x – top left x-coordinate

  • y – top left y-coordinate

  • width – ellipse width

  • height – ellipse height

  • draw (boolean) – whether to draw the shape on the canvas or not

Returns

BezierPath representing the ellipse

circle(x, y, diameter, draw=True, **kwargs)

Draw a circle :param x: x-coordinate of the top left corner :param y: y-coordinate of the top left corner :param diameter: circle diameter :param boolean draw: whether to draw the shape on the canvas or not :return: BezierPath representing the circle

ellipsemode(mode=None)

Set the current ellipse drawing mode.

Parameters

mode – CORNER, CENTER, CORNERS

Returns

ellipsemode if mode is None or valid.

line(x1, y1, x2, y2, draw=True, **kwargs)

Draw a line from (x1,y1) to (x2,y2).

Parameters
  • x1 – x-coordinate of the first point

  • y1 – y-coordinate of the first point

  • x2 – x-coordinate of the second point

  • y2 – y-coordinate of the second point

  • draw (boolean) – whether to draw the shape on the canvas or not

Returns

BezierPath representing the line

arc(x, y, radius, angle1, angle2, type='chord', draw=True, **kwargs)

Draw an arc with center (x,y) between two angles in degrees.

Parameters
  • x1 – start x-coordinate

  • y1 – start y-coordinate

  • radius – arc radius

  • angle1 – start angle

  • angle2 – end angle

arrow(x, y, width, type='1', draw=True, **kwargs)

Draw an arrow.

Parameters
  • x – arrow tip x-coordinate

  • y – arrow tip y-coordinate

  • width – arrow width (also sets height)

  • type (NORMAL or FORTYFIVE) – arrow type

  • draw (boolean) – whether to draw the shape on the canvas or not

Returns

BezierPath object representing the arrow

star(x, y, points=20, outer=100, inner=50, draw=True, **kwargs)

Draws a star.

Parameters
  • x – center x-coordinate

  • y – center y-coordinate

  • points – amount of points

  • outer – outer radius

  • inner – inner radius

  • draw (boolean) – whether to draw the shape on the canvas or not

beginpath(x=None, y=None, **kwargs)

Start a new Bézier path.

This command is needed before any other path drawing commands.

Parameters
  • x (float or None) – x-coordinate of the starting point

  • y (float or None) – y-coordinate of the starting point

moveto(x, y)

Move the Bézier “pen” to the specified point without drawing.

Parameters
  • x (float) – x-coordinate of the point to move to

  • y (float) – y-coordinate of the point to move to

lineto(x, y)

Draw a line from the pen’s current point.

Parameters
  • x (float) – x-coordinate of the point to draw to

  • y (float) – y-coordinate of the point to draw to

curveto(x1, y1, x2, y2, x3, y3)
arcto(x, y, radius, angle1, angle2)
closepath()
endpath(draw=True, closed=None)
drawpath(path, **kwargs)
drawimage(image, x=None, y=None)
Parameters
  • image – Image to draw

  • x – optional, x coordinate (default is image.x)

  • y – optional, y coordinate (default is image.y)

Returns

autoclosepath(close=True)
relmoveto(x, y)

Move relatively to the last point.

rellineto(x, y)

Draw a line using relative coordinates.

relcurveto(h1x, h1y, h2x, h2y, x, y)

Draws a curve relatively to the last point.

findpath(points, curvature=1.0)

Constructs a path between the given list of points.

Interpolates the list of points and determines a smooth bezier path betweem them.

The curvature parameter offers some control on how separate segments are stitched together: from straight angles to smooth curves. Curvature is only useful if the path has more than three points.

beginclip(path)

Use a path as a clipping mask.

All drawing commands between beginclip() and endclip() will be drawn inside the clipping mask set by beginclip().

Parameters

path (BezierPath) – the path to be used as a clipping mask

endclip()

Finish a clipping mask and render the result.

transform(mode=None)

Set the current transform mode.

Parameters

mode (CORNER or CENTER) – the mode to base new transformations on

translate(xt, yt)

Translate the canvas origin point by (xt, yt).

Parameters
  • xt – Amount to move horizontally

  • yt – Amount to move vertically

rotate(degrees=0, radians=0)

Set the current rotation in degrees or radians.

Parameters
  • degrees – Degrees to rotate

  • radians – Radians to rotate

scale(x=1, y=None)

Set a scale at which to draw objects.

1.0 draws objects at their natural size.

Parameters
  • x – Scale on the horizontal plane

  • y – Scale on the vertical plane

skew(x=1, y=0)
push()
pop()
reset()
outputmode()

NOT IMPLEMENTED

colormode(mode=None, range=None)

Set the current colormode (can be RGB or HSB) and eventually the color range.

If called without arguments, it returns the current colormode.

Parameters
  • mode (RGB or HSB) – Color mode to use

  • crange (float) – Maximum value for the new color range to use

Returns

Current color mode

colorrange(crange=None)

Sets the current color range.

The default is 0-1; for a range of 0-255, use colorrange(256).

Parameters

crange (float) – maximum value for new color range

Returns

current range value

fill(*args)

Sets a fill color, applying it to new paths.

Parameters

args – color in supported format

nofill()

Stop applying fills to new paths.

Returns

fill color before nofill() was called

fillrule(r=None)

Set the fill rule to use in new paths.

Parameters

r (WINDING or EVENODD) – fill rule to apply

Returns

current fill rule value

stroke(*args)

Set a stroke color, applying it to new paths.

Parameters

args – color in supported format

Returns

new stroke color

nostroke()

Stop applying strokes to new paths.

Returns

stroke color before nostroke() was called

strokewidth(w=None)

Set the stroke width to be used by stroke().

Parameters

w – width of the stroke to use

Returns

current stroke width value

strokedash(dashes=None, offset=0)

Sets the dash pattern to be used by stroke().

Parameters
  • dashes (list) – a sequence specifying alternate lengths of on and off stroke portions

  • offset (float) – an offset into the dash pattern at which the stroke should start

Returns

tuple with dashes value and offset

strokecap(cap=None)

Set the stroke cap.

Parameters

w – new stroke cap value

Returns

current stroke cap value

strokejoin(join=None)

Set the stroke join.

Parameters

w – new stroke join value

Returns

current line join value

background(*args)

Set the canvas background color.

Parameters

color – background color to apply

Returns

new background color

blendmode(mode=None)

Set the current blending mode.

Parameters

mode – mode name (e.g. “multiply”)

font(fontpath=None, fontsize=None, vars=None, *args, **kwargs)

Set the font to be used with new text instances.

Parameters
  • fontpath – font name (can include styles like “Bold”)

  • fontsize – font size

  • vars – font variant values, as a dict of axis/value pairs (variable fonts only)

  • var_XXXX – set variant value (variable fonts only)

Returns

current fontpath (if fontpath param not set)

Accepts TrueType and OpenType files. Depends on FreeType being installed.

fontsize(fontsize=None)

Sets and/or returns the current font size.

Parameters

fontsize – Font size in pt

Returns

the current font size value

text(txt, x, y, width=None, height=1000000, outline=False, draw=True, **kwargs)

Draws a string of text according to the current font settings.

Parameters
  • txt – Text to output

  • x – x-coordinate of the top left corner

  • y – y-coordinate of the top left corner

  • width – text width

  • height – text height

  • outline – If True, draws a path instead of a text object (defaults to False)

  • draw – Set to False to inhibit immediate drawing (defaults to True)

Returns

Path object representing the text.

textpath(txt, x, y, width=None, height=1000000, draw=False, **kwargs)

Generates an outlined path of the input text.

Parameters
  • txt – Text to output

  • x – x-coordinate of the top left corner

  • y – y-coordinate of the top left corner

  • width – text width

  • height – text height

  • draw – Set to False to inhibit immediate drawing (defaults to False)

Returns

BezierPath representing the text

textmetrics(txt, width=None, height=None, **kwargs)

Returns the dimensions of the text box of a string of text, according to the current font settings.

Returns

(width, height) tuple

textbounds(txt, width=None, height=None, **kwargs)

Returns the dimensions of the actual shapes (inked part) of a string of text, according to the current font settings.

Returns

(width, height) tuple

textwidth(txt, width=None)

Returns the width of a string of text according to the current font settings.

Returns

textheight(txt, width=None)

Returns the height of a string of text according to the current font settings.

Parameters
  • txt – string to measure

  • width – width of a line of text in a block

lineheight(height=None)

Set text lineheight.

Parameters

height – line height.

align(align='left')

Set text alignment

Parameters

align – Text alignment (LEFT, CENTER, RIGHT)

fontoptions(hintstyle=None, hintmetrics=None, subpixelorder=None, antialias=None)

Set font rendering options.

Parameters
  • hintstyle – Hinting style (NONE, SLIGHT, MEDIUM, FULL)

  • hintmetrics – Quantize font metrics (ON, OFF)

  • antialias – Antialiasing type (NONE, GRAY, SUBPIXEL, FAST, GOOD, BEST)

  • subpixelorder – Order of pixels when antialiasing in SUBPIXEL mode (RGB, BGR, VRGB, VBGR)

fontnames()
autotext(sourceFile)
property canvas

Not entirely sure compatible the Shoebot ‘canvas’ is with Nodebox but there you go. :return:

angle(x0, y0, x1, y1)
distance(x0, y0, x1, y1)
coordinates(x0, y0, distance, angle)
property FRAME
MOUSEX = -1

The x-value of the mouse cursor coordinates.

MOUSEY = -1

The y-value of the mouse cursor coordinates.

choice(seq)

Choose a random element from a non-empty sequence.

cm = 28.3465
color(*args)
Parameters

args – color in a supported format.

Returns

Color object containing the color.

draw()

For override by user sketch

files(path='*')

Returns a list of files.

Use wildcards to specify which files to pick, e.g. f = files('*.gif').

Parameters

path – wildcard to use in file list

Returns

list of file names

finish()
grid(cols, rows, colSize=1, rowSize=1, shuffled=False)

Returns an iterator that contains coordinate tuples.

This command can be used to quickly create grid-like structures. A common usage pattern is:

for x, y in grid(10,10,12,12):
    rect(x,y, 10,10)
inch = 72
key = '-'
keycode = 0
keydown = False
mm = 2.8346
mousedown = False

Is True if the mouse button is pressed.

random(v1=None, v2=None)
run(inputcode, iterations=None, run_forever=False, frame_limiter=False, verbose=False)

Executes the contents of a Nodebox/Shoebot script in current surface’s context.

Parameters
  • inputcode – Path to shoebot source or string containing source

  • iterations – None or Maximum amount of frames to run

  • run_forever – If True then run until user quits the bot

  • frame_limiter – If True then sleep between frames to respect speed() command.

setup()

For override by user sketch

show(format='png', as_data=False)

Returns an Image object of the current surface. Used for displaying output in Jupyter notebooks. Adapted from the cairo-jupyter project.

size(w=None, h=None)

Set the canvas size

Only the first call will actually be effective.

Parameters
  • w – Width

  • h – height

snapshot(target=None, defer=None, autonumber=False)

Save the contents of current surface into a file or cairo surface/context.

Parameters
  • filename – Can be a filename or a Cairo surface.

  • defer – When to snapshot, if set to True waits until the frame has finished rendering.

  • autonumber – If true then a number will be appended to the filename.

speed(framerate=None)

Set animation framerate.

Parameters

framerate – Frames per second to run bot.

Returns

Current framerate of animation.

var(name, type, default=None, min=0, max=255, value=None, step=None)
ximport(libName)

Import Nodebox libraries.

The libraries get _ctx, which provides them with the nodebox API.

Parameters

libName – Library name to import