Exemple #1
0
print('Context class is %s' % type(context).__name__)

from pagebot.fonttoolbox.objects.font import findFont

font = findFont('Amstelvar-Roman-VF')

TITLE = 'HelloCircleSquare'
EXPORT_PATH = '_export/%s.pdf' % TITLE

W = H = 500
PAGES = 3
RECTS = 150
R = 20  # Diameter of circle or square
M = 20  # Page margin

context.newDocument(w=W, h=H, title=TITLE, pageCount=3)
for p in range(PAGES):
    context.newPage(W, H)
    for n in range(RECTS):
        # Compatible to DrawBot: color values between (0, 1)
        red, green, blue = random(), random(), random()
        #a = 0.5 + random()*0.5
        #context.fill((red, green, blue, a))
        context.fill((red, green, blue))
        ch = random()
        x = M + random() * (W - 2 * M - R)  # Only in available space
        y = M + random() * (H - 2 * M - R)
        if ch < 0.2:
            context.oval(x, y, R, R)
        elif ch < 0.4:
            context.rect(x, y, R, R)
Exemple #2
0
def drawSierpinskiSquare(px, py, w, maxW):
    if w < 1:
        return
    for x in range(3):
        for y in range(3):
            if x == 1 and y == 1:
                c = max(0, 0.5 - 0.5*w/W)
                context.fill((random(), c, c))
                #print(x, y, w, 0.5*w/W)
                context.rect(px+w, py+w, w, w)
            elif px <= maxW and py <= maxW:
                drawSierpinskiSquare(px+x*w, py+y*w, w/3.0, maxW)


context.newDocument(w=W, h=H)
context.newPage(W, H)
context.fill((1, 1, 1))
context.rect(0, 0, W, H)
drawSierpinskiSquare(0, 0, W, W)

# TODO: Check on sensitivity of Flat for color types in relation to document types
# Gray scale does not work for .svg
# Opaque does not work for .pdf
# Context should hide that problem.
for extension in ('pdf', 'jpg'):
    if not os.path.exists('_export'):
        os.mkdir('_export')
    exportPath = "_export/SierpinskiSquare." + extension
    context.saveDocument(exportPath)
    os.system(u'open "%s"' % exportPath)