Example #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)
Example #2
0
def page_with_lines(width, height, x_lines, y_lines, mult, dur, color=False):
    drawBot.newPage(width*mult, height*mult)
    drawBot.frameDuration(dur)
    drawBot.fill(1, 1, 1)
    drawBot.rect(0, 0, width*mult, height*mult)
    if color:
        draw_colors(x_lines, y_lines, width, height, mult)
    draw_lines(x_lines, y_lines, mult)
Example #3
0
 def makeTestAnimation(self, numFrames=25, pageWidth=500, pageHeight=500):
     randomSeed(0)
     drawBot.newDrawing()
     for i in range(numFrames):
         drawBot.newPage(pageWidth, pageHeight)
         drawBot.frameDuration(1/25)
         drawBot.fill(1)
         drawBot.rect(0, 0, pageWidth, pageHeight)
         drawBot.fill(0)
         drawBot.rect(random.randint(0, 100), random.randint(0, 100), 400, 400)
Example #4
0
def draw_board(board: array) -> array:
    n = board.shape[0]
    square_size = BOARD_SIZE / n
    draw.newPage(BOARD_SIZE, BOARD_SIZE)
    draw.frameDuration(FRAME_DURATION)
    for i in range(n):
        for j in range(n):
            if board[i,j] == 0:
                draw.fill(0, 0, 0, 1)
            else:
                draw.fill(255, 255, 255, 1)
            draw.rect(square_size * j, square_size * i, square_size, square_size)
Example #5
0
def feelingSlide(canvasWidth, canvasHeight, polarity):
    db.newPage(canvasWidth, canvasHeight)

    background_fill = polarityBackground(polarity)

    db.fill(*background_fill)
    db.frameDuration(4)
    db.rect(0, 0, canvasWidth, canvasHeight)

    background_images = os.listdir('background_images/')
    background_image_path = 'background_images/' + background_images[(int)(
        len(background_images) * random.random())]
    # https://forum.drawbot.com/topic/180/how-do-i-size-an-image-with-the-imageobject-or-without/4
    srcWidth, srcHeight = db.imageSize(background_image_path)
    dstWidth, dstHeight = canvasWidth - 50, canvasHeight - 50
    factorWidth = dstWidth / srcWidth
    factorHeight = dstHeight / srcHeight
    with db.savedState():
        db.translate(25, 25)
        with db.savedState():
            db.scale(factorWidth, factorHeight)
            db.image(background_image_path, (0, 0))

    dril_feels_text = db.FormattedString()
    dril_feels_text.append("@dril feels",
                           font="Calibri-Bold",
                           fontSize=150,
                           fill=1,
                           align='center',
                           stroke=background_fill,
                           strokeWidth=0.5)
    db.shadow((0, 0), 50, background_fill)
    db.text(dril_feels_text, (canvasWidth / 2, canvasHeight - 300))

    if polarity < -0.1:
        drils_feeling = "angry"
        db.font("LucidaBlackletter", 250)
    elif polarity < 0.25:
        drils_feeling = "neutral"
        db.font("Helvetica", 180)
    else:
        drils_feeling = "happy"
        db.font("Cortado", 250)

    db.fill(1)
    db.shadow((0, 0), 50, background_fill)
    db.text(drils_feeling, (canvasWidth / 2, 250), align='center')
Example #6
0
def introSlide(canvasWidth, canvasHeight, question):
    db.newPage(canvasWidth, canvasHeight)
    backgroundImage(canvasWidth, canvasHeight)
    db.fill(*rgb(94, 174, 235))
    # db.rect(0, 0, canvasWidth, canvasHeight)
    backgroundSquares(canvasWidth, canvasHeight)
    db.frameDuration(2)

    db.fill(1, 1, 1)
    margin_bottom = 0.1 * canvasHeight
    margin_sides = 0.1 * canvasHeight

    text_box_margin = margin_sides * 0.5
    text_box_width = canvasWidth - margin_sides * 2 - text_box_margin * 2
    text_box_height = canvasHeight - margin_sides - margin_bottom - text_box_margin * 2

    current_font_size = 10
    db.font('ArialNarrow-Bold', current_font_size)

    # this is not efficient. Don't show anyone I made this
    while True:
        db.fontSize(current_font_size)
        current_font_size += 1
        _, current_text_height = db.textSize(question,
                                             'center',
                                             width=text_box_width)
        # print(current_text_height)
        # print(text_box_height)
        if (current_font_size > 150):
            break
        elif (current_text_height > text_box_height):
            current_font_size -= 2
            break

    db.fontSize(current_font_size)

    db.fill(*rgb(255, 252, 61))
    db.textBox(question, (margin_sides + text_box_margin, margin_bottom +
                          text_box_margin, text_box_width, text_box_height),
               'center')
Example #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)
Example #8
0
    def makeInstance(self, axes, gname, glyph):
        nbAxes = maxNbAxes = len(axes)
        # steps = [1, 2]
        # maxNbAxes = max(steps)
        # for nbAxes in steps:

        speeds = [1 for i in range(nbAxes)]
        # LCM = self.ilcm(speeds)
        LCM = 60
        # print(LCM)
        # while ((LCM < 600 or LCM > 1200) or self.checkEqual(speeds)):
        #     speeds = [int(10/nbAxes + random.random()*60/nbAxes) for i in range(nbAxes)]
        #     LCM = self.ilcm(speeds)
        #     print(speeds, LCM, (LCM < 600 or LCM > 1200))

        alpha = 2 * math.pi / maxNbAxes
        ld = [{'Axis': l, 'PreviewValue': 0} for l in axes]
        # glyph.preview.computeDeepComponentsPreview(ld)
        origineGlyph = RGlyph()
        for atomicInstance in glyph.preview():
            atomicInstance = atomicInstance.glyph
            atomicInstance.draw(origineGlyph.getPen())
        # origineGlyph = glyph.preview.variationPreview.copy()
        origineGlyph.name = "interpo"
        db.newDrawing()
        for k in range(nbAxes):
            start = time.time()
            ld = [{
                'Axis': l,
                'PreviewValue': j == k
            } for j, l in enumerate(axes)]
            # glyph.preview.computeDeepComponentsPreview(ld)
            for g in range(LCM):

                H = 700
                W = 700
                db.newPage(W * 2.5, H)
                db.frameDuration(1 / 30)

                db.fill(1)
                db.rect(0, 0, W * 2.5, H)

                r = W / 3
                ainc = 0
                lines = []
                rands = []
                values = []

                for i in range(nbAxes):
                    path = db.BezierPath()
                    path.moveTo((H / 2, W / 2))
                    line = (r * math.sin(ainc), r * math.cos(ainc))
                    path.lineTo((H / 2 + line[0], W / 2 + line[1]))
                    dx = line[0] * .05
                    dy = line[1] * .05
                    path.moveTo((H / 2 + line[0] - dy, W / 2 + line[1] + dx))
                    path.lineTo((H / 2 + line[0] + dy, W / 2 + line[1] - dx))
                    db.stroke(.2)
                    db.strokeWidth(1.5)
                    db.fill(None)
                    db.drawPath(path)
                    ainc += alpha
                    lines.append((line, axes[i]["sourceName"]))
                    # v = getValueForAxeAtFrame(i, g, nbAxes, LCM, speeds[i])
                    # values.append(v)
                    if i == k:
                        rands.append([
                            1000 * abs(
                                math.sin(math.pi *
                                         (speeds[i] * c / LCM + speeds[i])))
                            for c in range(LCM)
                        ])
                    else:
                        rands.append([0 for c in range(LCM)])

                db.fill(1)
                db.oval(H / 2 - H * .01, W / 2 - W * .01, H * .02, W * .02)

                patharea = db.BezierPath()
                patharea.moveTo((H / 2, W / 2))
                patharea.lineTo((H / 2 + lines[0][0][0] * rands[0][g] / 1000,
                                 W / 2 + lines[0][0][1] * rands[0][g] / 1000))
                db.fill(0, 0, 0, .1)
                db.stroke(None)
                for c, (line, lineName) in enumerate(lines):
                    patharea.lineTo((H / 2 + line[0] * rands[c][g] / 1000,
                                     W / 2 + line[1] * rands[c][g] / 1000))
                patharea.lineTo((H / 2 + lines[0][0][0] * rands[0][g] / 1000,
                                 W / 2 + lines[0][0][1] * rands[0][g] / 1000))
                patharea.lineTo((H / 2, W / 2))
                db.drawPath(patharea)

                for c, (line, lineName) in enumerate(lines):
                    db.fill(0)  #1-rands[c]
                    db.stroke(.2)
                    db.strokeWidth(1)
                    db.oval(H / 2 + line[0] * rands[c][g] / 1000 - 4.5,
                            W / 2 + line[1] * rands[c][g] / 1000 - 4.5, 9, 9)
                    db.fill(.2)
                    ftxt = db.FormattedString(txt=lineName,
                                              font="GrtskZetta-Light",
                                              fontSize=14,
                                              align="center")
                    db.textBox(ftxt, (H / 2 + line[0] * 1.3 - 30,
                                      W / 2 + line[1] * 1.3 - 10, 60, 20))

                #########
                db.save()
                # ld = []
                # for j, l in enumerate(axes):
                #     ld.append({'Axis': l, 'PreviewValue':rands[j][g]/1000})

                # # d = {l:rands[j][g]/1000 for (j, l) in enumerate(axes)}

                # # glyph = interpolation(NewFont().newGlyph('temp'), ufo[gname], layersInfo = d)
                # # glyph = self.RCJKI.currentFont.get(gname)
                # glyph.preview.computeDeepComponentsPreview(ld)
                #########
                # print(glyph)
                db.translate(W * 1.3, H * .15)
                db.scale(.7 * H / 1000)
                db.stroke(.5)
                db.fill(None)
                db.rect(0, 0, 1000, 1000)
                db.fill(0)
                db.stroke(None)
                db.save()
                db.translate(0, 120)

                ratioX = ratioY = (rands[k][g]) / 1000
                resultGlyph = RGlyph()
                locations = {}
                for e in ld:
                    locations[e["Axis"]["sourceName"]] = e["PreviewValue"]
                for c in glyph.preview(locations):
                    c = c.glyph
                    c.draw(resultGlyph.getPen())
                interpoGlyph = interpolation.interpol_glyph_glyph_ratioX_ratioY_scaleX_scaleY(
                    origineGlyph, resultGlyph, ratioX, ratioY, 1, 1,
                    NewFont(showUI=False))
                db.drawGlyph(interpoGlyph)

                #         for aes in glyph.preview:
                #             # axis2layerName = {axisName:layerName for axisName, layerName in self.RCJKI.currentFont[aes['name']].lib['robocjk.atomicElement.glyphVariations'].items()}

                #             # lInfos = {axis2layerName[axisName]:v for axisName, v in aes['coord'].items()}
                # #            print(ae['coord'])
                #             for ae in aes.values():
                #                 glyph = ae[0]
                #                 print(glyph)
                #                 db.save()
                #                 self._drawGlyph(glyph)
                #                 db.restore()
                db.restore()
                db.restore()
                caption = db.FormattedString(txt='%s-axis' % (nbAxes),
                                             font="GrtskMega-Medium",
                                             fontSize=14,
                                             align="left")
                db.textBox(caption, (10, 10, W - 20, 20))

            stop = time.time()
            print(stop - start, "seconde for axis")

        pdfData = db.pdfImage()
Example #9
0
CANVAS = 500

fps = 50
sec = 14
total_frames = fps * sec
duration = 1 / fps

position = (CANVAS / 2, 0)

particles = []
n_particles = 100

for frame in range(total_frames):
    db.newPage(CANVAS, CANVAS)
    db.frameDuration(duration)

    db.stroke(None)

    if len(particles) < n_particles:
        p = Particle(*position,
                     random.uniform(0, 1) * 8 + 5,
                     math.pi / 2 + (random.uniform(0, 1) * 0.2 - 0.1), 0.1)
        p.radius = random.uniform(0, 1) * 5 + 5
        particles.append(p)

    for i, p in enumerate(particles):
        p.update()
        db.fill(i * 5 / CANVAS, (n_particles - i) * 5 / CANVAS, 0.7, 1)
        db.oval(p.position.x - p.radius, p.position.y - p.radius, p.radius * 2,
                p.radius * 2)
Example #10
0
from os import listdir
from os.path import isfile, join

width = 970
height = 600

files = [f for f in listdir('outputs/gif/') if isfile(join('outputs/gif', f))]
shuffle(files)

db.newDrawing()
db.size(width, height)
for i in range(len(files)):
    fp = 'outputs/gif/' + files[i]
    print(fp)
    db.newPage(width, height)
    db.frameDuration(.25)
    # db.fill(0)
    # db.rect(0,0,width,height)
    # db.fill(None)
    im = db.ImageObject(fp)
    if (im.size()[1] == height):
        pos = ((width - im.size()[0]) / 2, 0)
    elif (im.size()[0] == width):
        pos = (0, (height - im.size()[1]) / 2)
    else:
        pos = ((width - im.size()[0]) / 2, (height - im.size()[1]) / 2)

    db.image(im, pos)
db.saveImage('outputs/gif_slow.gif')
db.endDrawing()
Example #11
0
def answerSlide(canvasWidth, canvasHeight, answer, polarity):
    background_fill = polarityBackground(polarity)
    db.newPage(canvasWidth, canvasHeight)
    db.fill(*background_fill)
    db.rect(0, 0, canvasWidth, canvasHeight)
    db.frameDuration(4)
    background_images = os.listdir('background_images/')
    background_image_path = 'background_images/' + background_images[(int)(
        len(background_images) * random.random())]
    # https://forum.drawbot.com/topic/180/how-do-i-size-an-image-with-the-imageobject-or-without/4
    srcWidth, srcHeight = db.imageSize(background_image_path)
    dstWidth, dstHeight = canvasWidth - 50, canvasHeight - 50
    factorWidth = dstWidth / srcWidth
    factorHeight = dstHeight / srcHeight
    with db.savedState():
        db.translate(25, 25)
        with db.savedState():
            db.scale(factorWidth, factorHeight)
            db.image(background_image_path, (0, 0))

    db.fill(*rgba(*background_fill, 0.1))
    box_width = 0.7 * canvasWidth
    box_height = canvasHeight * 0.7
    x_0 = (canvasWidth - box_width) / 2
    y_0 = (canvasHeight - box_height) / 2 - 100

    text_box_margin = 40
    text_box_width = box_width - text_box_margin * 2
    text_box_height = box_height - text_box_margin * 2

    current_font_size = 10
    db.font('Calibri-Bold', current_font_size)

    # this is not efficient. Don't show anyone I made this
    while True:
        db.fontSize(current_font_size)
        current_font_size += 1
        _, current_text_height = db.textSize(answer,
                                             'left',
                                             width=text_box_width)
        if (current_font_size > 150):
            break
        elif (current_text_height > text_box_height):
            current_font_size -= 2
            break

    db.fontSize(current_font_size)
    db.stroke(*background_fill)
    db.strokeWidth(0.5)
    db.fill(*rgb(255, 252, 61))
    db.textBox(answer, (x_0, y_0, box_width, box_height), 'left')

    # dril says
    d_says = db.FormattedString()
    d_says.append("@dril says:",
                  font="Calibri-Bold",
                  fontSize=100,
                  fill=rgb(255, 252, 61),
                  stroke=background_fill,
                  strokeWidth=2)
    # db.shadow((0,0), 50, background_fill)
    db.text(d_says, (x_0, y_0 + box_height + 30))