Пример #1
0
 def test_instructionStack(self):
     expected = [
         "reset None", "newPage 200 200", "save",
         "clipPath moveTo 5.0 5.0 lineTo 15.0 5.0 lineTo 15.0 15.0 lineTo 5.0 15.0 closePath",
         "restore", "image Image Object 10 10 0.5 None",
         "blendMode saturation", "transform 1 0 0 1 10 10",
         "drawPath moveTo 10.0 10.0 lineTo 110.0 10.0 lineTo 110.0 110.0 lineTo 10.0 110.0 closePath",
         "textBox foo bar 72.48291015625 84.0 55.0341796875 26.0 center",
         "frameDuration 10", "saveImage * {'myExtraAgrument': True}"
     ]
     with StdOutCollector() as output:
         import drawBot
         drawBot.newDrawing()
         drawBot.size(200, 200)
         drawBot.save()
         path = drawBot.BezierPath()
         path.rect(5, 5, 10, 10)
         drawBot.clipPath(path)
         drawBot.restore()
         im = drawBot.ImageObject()
         with im:
             drawBot.size(20, 20)
             drawBot.rect(5, 5, 10, 10)
         drawBot.image(im, (10, 10), alpha=.5)
         drawBot.blendMode("saturation")
         drawBot.translate(10, 10)
         drawBot.rect(10, 10, 100, 100)
         drawBot.text("foo bar", (100, 100), align="center")
         drawBot.frameDuration(10)
         drawBot.saveImage("*", myExtraAgrument=True)
         drawBot.endDrawing()
     self.assertEqual(output.lines(), expected)
Пример #2
0
 def test_newPage_following(self):
     drawBot.newDrawing()
     drawBot.size(400, 500)
     drawBot.newPage()
     self.assertEqual(drawBot.width(), 400)
     self.assertEqual(drawBot.height(), 500)
     self.assertEqual(drawBot.pageCount(), 2)
Пример #3
0
 def run(self, render_pass, renderer_state):
     use_pool = True
     if use_pool:
         pool = AppKit.NSAutoreleasePool.alloc().init()
     try:
         db.newDrawing()
         if renderer_state.previewing:
             ps = renderer_state.preview_scale
             db.size(self.rect.w * ps, self.rect.h * ps)
             db.scale(ps, ps)
             DATPen().rect(self.rect).f(self.bg).db_drawPath()
         else:
             db.size(self.rect.w, self.rect.h)
         render_pass.fn(*render_pass.args)
         result = None
         if renderer_state.previewing:
             previews = (render_pass.output_path.parent / "_previews")
             previews.mkdir(exist_ok=True, parents=True)
             preview_frame = previews / render_pass.output_path.name
             db.saveImage(str(preview_frame))
             result = preview_frame
         else:
             render_pass.output_path.parent.mkdir(exist_ok=True,
                                                  parents=True)
             db.saveImage(str(render_pass.output_path))
             result = render_pass.output_path
         db.endDrawing()
     finally:
         if use_pool:
             del pool
     return result
Пример #4
0
 def test_newPage_following(self):
     drawBot.newDrawing()
     drawBot.size(400, 500)
     drawBot.newPage()
     self.assertEqual(drawBot.width(), 400)
     self.assertEqual(drawBot.height(), 500)
     self.assertEqual(drawBot.pageCount(), 2)
Пример #5
0
    def test_imageAntiAliasing(self):
        from testScripts import DrawBotTest

        expectedPath = os.path.join(testDataDir, "expected_imageAntiAliasing.png")

        drawBot.newDrawing()
        drawBot.size(100, 100)
        drawBot.fill(1, 0, 0)
        drawBot.oval(10, 10, 40, 80)
        drawBot.fill(0)
        drawBot.stroke(0)
        drawBot.line((-0.5, -0.5), (100.5, 100.5))
        drawBot.line((0, 20.5), (100, 20.5))
        drawBot.fontSize(20)
        drawBot.text("a", (62, 30))

        with TempFile(suffix=".png") as tmp:
            drawBot.saveImage(tmp.path, antiAliasing=False)
            self.assertImageFilesEqual(tmp.path, expectedPath)
Пример #6
0
 def draw(pen, state, data):
     if state == 0:
         DrawBotPen(pen, rect).draw(scale=scale)
     elif state == -1:
         imgf = pen.data.get("imgf")
         if imgf:
             im = db.ImageObject()
             im.lockFocus()
             db.size(rect.w+300, rect.h+300)
             db.translate(150, 150)
             db.scale(scale)
             pen.data["im"] = im
     elif state == 1:
         imgf = pen.data.get("imgf")
         im = pen.data.get("im")
         if imgf and im:
             im.unlockFocus()
             imgf(im)
             x, y = im.offset()
             db.translate(-150, -150)
             db.image(im, (x, y))
Пример #7
0
 def test_instructionStack(self):
     expected = [
         "reset None",
         "newPage 200 200",
         "save",
         "clipPath moveTo 5.0 5.0 lineTo 15.0 5.0 lineTo 15.0 15.0 lineTo 5.0 15.0 closePath",
         "restore",
         "image Image Object 10 10 0.5 None",
         "blendMode saturation",
         "transform 1 0 0 1 10 10",
         "drawPath moveTo 10.0 10.0 lineTo 110.0 10.0 lineTo 110.0 110.0 lineTo 10.0 110.0 closePath",
         "textBox foo bar 82.48291015625 84.0 35.0341796875 26.0 center",
         "frameDuration 10",
         "saveImage * {'myExtraAgrument': True}"
     ]
     with StdOutCollector() as output:
         import drawBot
         drawBot.newDrawing()
         drawBot.size(200, 200)
         drawBot.save()
         path = drawBot.BezierPath()
         path.rect(5, 5, 10, 10)
         drawBot.clipPath(path)
         drawBot.restore()
         im = drawBot.ImageObject()
         with im:
             drawBot.size(20, 20)
             drawBot.rect(5, 5, 10, 10)
         drawBot.image(im, (10, 10), alpha=.5)
         drawBot.blendMode("saturation")
         drawBot.translate(10, 10)
         drawBot.rect(10, 10, 100, 100)
         drawBot.text("foo bar", (100, 100), align="center")
         drawBot.frameDuration(10)
         drawBot.saveImage("*", myExtraAgrument=True)
         drawBot.endDrawing()
     self.assertEqual(output.lines(), expected)
Пример #8
0
import drawBot
drawBot.size(500, 500)
imagePath = "../data/drawBot.pdf"
w, h = drawBot.imageSize(imagePath)
drawBot.scale(250 / w)
drawBot.image(imagePath, (0, 0))
drawBot.image(imagePath, (w, 0), alpha=0.5)
drawBot.image(imagePath, (0, h), alpha=0.25)
drawBot.image(imagePath, (w, h), alpha=0.75)
Пример #9
0
import drawBot
drawBot.newDrawing()
drawBot.size(600, 100)
p1 = drawBot.BezierPath()
p1.oval(5, 5, 70, 70)
p2 = drawBot.BezierPath()
p2.rect(25, 25, 70, 70)
drawBot.fill(0, 0.3)
drawBot.stroke(0)

drawBot.drawPath(p1)
drawBot.drawPath(p2)

pUnion = p1 | p2
pIntersection = p1 & p2
pXor = p1 ^ p2
pDiff1 = p1 % p2
pDiff2 = p2 % p1

for p in [pUnion, pIntersection, pXor, pDiff1, pDiff2]:
    drawBot.translate(100, 0)
    drawBot.drawPath(p)
Пример #10
0
import random
sys.path.append(os.path.dirname(os.getcwd()))

import drawBot as db
import sketch_helper as sh

CANVAS = (500, 500)
FRAMES = 30

ufo_path = '/Users/shu/Dropbox/Life/Misc/nenga_2019/pig_2018.ufo'

if __name__ == "__main__":

    db.newDrawing()

    db.size(*CANVAS)
    
    glyphs = ['A', 'B', 'C', 'D', 'E', 'F']
    
    pig_outline = sh.getGlyphPath(ufo_path, 'A')
    min_x, min_y, max_x, max_y = pig_outline.bounds()
    width = (max_x - min_x)
    height = (max_y - min_y)
    
    scale = 0.1
    margin = 20
    
    vertical_pigs = math.floor(CANVAS[1] / ((height + margin / 2) * scale))
    horizontal_pigs = math.floor(CANVAS[0] / ((width + margin) * scale))
    
#    for k in range(FRAMES):
# https://github.com/typemytype/drawbot/issues/427
import drawBot
drawBot.size(200, 200)

fs = drawBot.FormattedString()
fs.font("Lucida Grande")
fs.fontSize(50)
fs.appendGlyph("H")
fs.appendGlyph("i")
drawBot.text(fs, (30, 110))

fs = drawBot.FormattedString()
fs.font("Lucida Grande")
fs.fontSize(50)
fs.tracking(10)
fs.appendGlyph("H")
fs.appendGlyph("i")
drawBot.text(fs, (30, 50))
Пример #12
0
import os
import drawBot
drawBot.size(50, 50)
characters = "Aa今"
glyphNames = ["A", "a", "zzz"]
for fontName in ["Helvetica", "../data/MutatorSans.ttf"]:
    print(fontName)
    print(drawBot.font(fontName))
    drawBot.fontSize(50)
    for char in characters:
        print(drawBot.fontContainsCharacters(char))
    for glyphName in glyphNames:
        print(drawBot.fontContainsGlyph(glyphName))
    print(os.path.basename(drawBot.fontFilePath()))
    print(drawBot.listFontGlyphNames()[:6])
    print(drawBot.fontAscender())
    print(drawBot.fontDescender())
    print(drawBot.fontXHeight())
    print(drawBot.fontCapHeight())
    print(drawBot.fontLeading())
    print(drawBot.fontLineHeight())
    print()

for i in range(4):
    print(drawBot.font("../data/MutatorSans.ttc", fontNumber=i))
    print(os.path.basename(drawBot.fontFilePath()),
          drawBot.fontFileFontNumber())
    assert drawBot.fontFileFontNumber() == i

print()
for fontName in ["Courier", "Courier-Bold", "Courier-Oblique"]:
Пример #13
0
import drawBot
drawBot.size(250, 250)
imagePath = "http://f.cl.ly/items/1T3x1y372J371p0v1F2Z/drawBot.jpg"
drawBot.scale(250 / 700)
drawBot.image(imagePath, (20, 20))
Пример #14
0
import drawBot
drawBot.size(500, 70)
fontPath = "../data/MutatorSans.ttf"
drawBot.font(fontPath)
drawBot.fontSize(20)
drawBot.text("HELLO MUTATOR", (10, 10))
drawBot.fontVariations(wdth=500, wght=900)
drawBot.text("HELLO MUTATOR", (10, 40))
Пример #15
0
import drawBot
drawBot.size(300, 300)
with drawBot.savedState():
    drawBot.fill(1, 0, 0)
    drawBot.translate(150, 150)
    drawBot.rect(0, 0, 100, 100)
    with drawBot.savedState():
        drawBot.rotate(45)
        drawBot.fill(0, 1, 0)
        drawBot.rect(0, 0, 100, 100)
drawBot.rect(0, 0, 100, 100)
Пример #16
0
import drawBot
drawBot.size(250, 250)
imagePath = "https://d1sz9tkli0lfjq.cloudfront.net/items/1T3x1y372J371p0v1F2Z/drawBot.jpg"
drawBot.scale(250 / 700)
drawBot.image(imagePath, (20, 20))
Пример #17
0
import drawBot
drawBot.newDrawing()
drawBot.size(200, 100)
p = drawBot.BezierPath()
p.oval(5, 5, 70, 70)
p.rect(25, 25, 70, 70)
drawBot.fill(0, 0.3)
drawBot.stroke(0)
drawBot.drawPath(p)
p.removeOverlap()
drawBot.translate(100, 0)
drawBot.drawPath(p)
Пример #18
0
import drawBot

drawBot.newDrawing()
drawBot.size(600, 100)
p1 = drawBot.BezierPath()
p1.oval(5, 5, 70, 70)
p2 = drawBot.BezierPath()
p2.rect(25, 25, 70, 70)
drawBot.fill(0, 0.3)
drawBot.stroke(0)

drawBot.drawPath(p1)
drawBot.drawPath(p2)

pUnion = p1 | p2
pIntersection = p1 & p2
pXor = p1 ^ p2
pDiff1 = p1 % p2
pDiff2 = p2 % p1

for p in [pUnion, pIntersection, pXor, pDiff1, pDiff2]:
    drawBot.translate(100, 0)
    drawBot.drawPath(p)
Пример #19
0
import drawBot
drawBot.size(200, 200)

drawBot.newPath()
drawBot.moveTo((20, 20))
drawBot.lineTo((20, 100))
drawBot.lineTo((100, 100))
drawBot.lineTo((100, 180))
drawBot.curveTo((150, 180), (180, 150), (180, 100))
drawBot.lineTo((180, 20))
drawBot.closePath()

drawBot.moveTo((40, 40))
drawBot.lineTo((160, 40))
drawBot.curveTo((160, 65), (145, 80), (120, 80))
drawBot.lineTo((40, 80))
drawBot.closePath()

drawBot.fill(0.5, 0, 0)
drawBot.stroke(None)
drawBot.strokeWidth(10)
drawBot.drawPath()
Пример #20
0
import sys
sys.path.append('./')
sys.path.append('./../')
import drawBot as db

width = 300
height = 250
db.newDrawing()
db.size(width, height)
# db.fill(0, .9)
# db.rect(0, 0, width, height)
# db.stroke(1)
frame = db.ImageObject('assets/[email protected]')
sf = width / frame.size()[0]
db.scale(sf)
db.image(frame, (0,0))
db.scale(1/sf)
badge = db.ImageObject('assets/badge.png')
sf = 500 / db.imageSize(badge)[0]
badge.lanczosScaleTransform(sf)
print(badge.size())
db.blendMode('difference')
db.image(badge, (30, 30))
db.saveImage('outputs/svg_test.png')
db.endDrawing()
Пример #21
0
import sys
sys.path.append('./')
import drawBot

drawBot.newDrawing()
drawBot.size(1080,1080)
im = drawBot.ImageObject('assets/1080_1080.png')
texture = drawBot.ImageObject('assets/chalkboard_invert.png')
texture.lanczosScaleTransform(2.5)
im.blendWithMask(backgroundImage=None, maskImage=texture)
mask = drawBot.ImageObject('assets/mask_square.png')
im.blendWithMask(backgroundImage=None, maskImage=mask)
drawBot.image(im, (0,0))
drawBot.saveImage('outputs/experiments/texture.png')
Пример #22
0
import drawBot
drawBot.size(100, 100)
drawBot.fill(.5, .5)
drawBot.oval(0, 0, 100, 100)
for x in range(10):
    for y in range(10):
        drawBot.fill(x / 10, 1 - y / 10, y / 10, y / 20 + .5)
        drawBot.rect(x*10, y*10, 10, 10)
Пример #23
0
    for i in range(len(points) - 1):
        draw_square(points[i], points[i + 1])


def generate_points(size: float) -> tuple:
    points = [(size / 2, size / 2)]
    radios = []
    num1, num2 = 0, 50
    i = 0

    while 0 <= points[i][0] < size or 0 <= points[i][1] < size:
        point = points[i][0] + num2 * COEFS[i % 4][0], points[i][1] + num2 * COEFS[i % 4][1]

        points.append(point)
        radios.append(num2)

        i += 1

        num1, num2 = num2, num1 + num2

    return points


if __name__ == '__main__':
    draw.newDrawing()
    draw.size(RESOLUTION[0], RESOLUTION[1])
    draw_spiral(RESOLUTION[0])
    draw.saveImage("FibonacciSpiral.jpeg")
    draw.endDrawing()
Пример #24
0
# https://github.com/typemytype/drawbot/issues/402
import drawBot
drawBot.size(640, 160)

fs = drawBot.FormattedString()
fs.font("Skia")
fs.fontSize(200)
fs.fontVariations(wght=1)
fs += "&"
fs.appendGlyph("ampersand")
fs.fontVariations(wght=2)
fs.appendGlyph("ampersand")
fs += "&"

drawBot.text(fs, (10, 10))