Pages

The origin of the drawing board is at the bottom left.

drawBot.newPage(width=None, height=None)

Create a new canvas to draw in. This will act like a page in a pdf or a frame in a mov.

Optionally a width and height argument can be provided to set the size. If not provided the default size will be used.

Alternatively size(‘A4’) can be used.

# loop over a range of 100
for i in range(100):
    # for each loop create a new path
    newPage(500, 500)
    # set a random fill color
    fill(random(), random(), random())
    # draw a rect with the size of the page
    rect(0, 0, width(), height())

All supported papersizes: 10x14, 10x14Landscape, A0, A0Landscape, A1, A1Landscape, A2, A2Landscape, A3, A3Landscape, A4, A4Landscape, A4Small, A4SmallLandscape, A5, A5Landscape, B4, B4Landscape, B5, B5Landscape, Executive, ExecutiveLandscape, Folio, FolioLandscape, Ledger, LedgerLandscape, Legal, LegalLandscape, Letter, LetterLandscape, LetterSmall, LetterSmallLandscape, Quarto, QuartoLandscape, Statement, StatementLandscape, Tabloid, TabloidLandscape.

drawBot.newDrawing()

Reset the drawing stack to the clean and empty stack.

# draw a rectangle
rect(10, 10, width()-20, height()-20)
# save it as a pdf
saveImage("~/Deskopt/aRect.pdf")

# reset the drawing stack to a clear and empty stack
newDrawing()

# draw an oval
oval(10, 10, width()-20, height()-20)
# save it as a pdf
saveImage("~/Deskopt/anOval.pdf")

Size

drawBot.size(width, height=None)

Set the width and height of the canvas. Without calling size() the default drawing board is 1000 by 1000 points.

Alternatively size(‘A4’) can be used.

Afterwards the functions width() and height() can be used for calculations.

It is advised to use size() always at the top of the script and not use size() in a multiple page document as a newPage(w, h) set the correct dimentions directly.

# set a canvas size
size(200, 200)
# print out the size of the page
print width(), height()

# set a color
fill(1, 0, 0)
# use those variables to set a background color
rect(0, 0, width(), height())

All supported papersizes: 10x14, 10x14Landscape, A0, A0Landscape, A1, A1Landscape, A2, A2Landscape, A3, A3Landscape, A4, A4Landscape, A4Small, A4SmallLandscape, A5, A5Landscape, B4, B4Landscape, B5, B5Landscape, Executive, ExecutiveLandscape, Folio, FolioLandscape, Ledger, LedgerLandscape, Legal, LegalLandscape, Letter, LetterLandscape, LetterSmall, LetterSmallLandscape, Quarto, QuartoLandscape, Statement, StatementLandscape, Tabloid, TabloidLandscape.

Page Attributes

drawBot.width()

Returns the width of the current page.

drawBot.height()

Returns the height of the current page.

drawBot.pageCount()

Returns the current page count.

drawBot.frameDuration(seconds)

When exporting to mov or gif each frame can have duration set in seconds.

# setting some varialbes
# size of the pages / frames
w, h = 200, 200
# frame per seconds
fps = 30
# duration of the movie
seconds = 3
# calculate the lenght of a single frame 
duration = 1 / fps
# calculate the amount of frames needed
totalFrames = seconds * fps

# title page
newPage(w, h)
# set frame duration to 1 second
frameDuration(1)
# pick a font and font size
font("Helvetica", 40)
# draw the title text in a box
textBox("Rotated square", (0, 0, w, h * .8), align="center")

# loop over the amount of frames needed
for i in range(totalFrames):
    # create a new page
    newPage(w, h)
    # set the frame duration
    frameDuration(duration)
    # set a fill color
    fill(1, 0, 0)
    # translate to the center of the page
    translate(w / 2, h / 2)
    # rotate around the center
    rotate(i*10)
    # draw the rect
    rect(-50, -50, 50, 50)

# save the image as a mov on the desktop
saveImage('~/Desktop/frameDuration.mov')