コード例 #1
0
ファイル: StrokePen.py プロジェクト: jtanadi/robofontScripts
    def draw(self):
        """
        This function is what Canvas calls to draw
        """

        db.translate(400, 400)
        db.scale(self.scale)

        for letter in self.letters:
            rotateFlag = False
            glyph = self.f[letter]

            pt0 = (glyph.contours[0].points[0].x,
                   glyph.contours[0].points[0].y)
            pt1 = (glyph.contours[0].points[1].x,
                   glyph.contours[0].points[1].y)
            pt2 = (glyph.contours[0].points[-2].x,
                   glyph.contours[0].points[-2].y)
            pt3 = (glyph.contours[0].points[-1].x,
                   glyph.contours[0].points[-1].y)

            if getAngle(pt0, pt1) >= 90 or getAngle(pt0, pt1) <= -90:
                rotateFlag = True
                db.translate(0, -820)

            db.newPath()
            pen = StrokePen(glyph.getParent(), self.widthValue)
            glyph.draw(pen)
            db.drawPath()

            if rotateFlag:
                db.rotate(-90)
                db.translate(0, 0)
            else:
                db.translate(glyph.width, 0)
コード例 #2
0
def hslDonut(rings,
             ringThickness,
             holeRadius,
             fixedValue,
             isLuminosityConst,
             captions=True):
    for angle in range(FULL_CIRCLE):
        for eachRing in range(rings):
            ringFactor = eachRing / (rings - 1)
            radius = holeRadius + eachRing * ringThickness

            if isLuminosityConst:
                rgbClr = hls_to_rgb(angle / FULL_CIRCLE, fixedValue,
                                    ringFactor)
            else:
                rgbClr = hls_to_rgb(angle / FULL_CIRCLE, ringFactor,
                                    fixedValue)
            lineQualities(rgbClr, ringThickness)

            newPath()
            arc((0, 0), radius, angle - .5, angle + .5, clockwise=False)
            drawPath()

        with savedState():
            if angle % 10 == 0 and captions:
                captionRadius = radius + ringThickness
                rotate(angle)

                lineQualities(thickness=.5)
                line((captionRadius - 2, 0), (captionRadius + 2, 0))

                typeQualities()
                text(f'{angle}', (radius + ringThickness + 6, 0))
コード例 #3
0
def drawFolds(foldWidth, currentPage):
    ticks = 0
    for y in range(0, int(canvasHeight * 1.3), int(foldWidth * 0.6)):
        with db.savedState():
            yCopy = y
            db.rotate(-30, center=(0, yCopy))
            xOffset = -foldWidth
            for x in range(xOffset, int(canvasWidth * 1.3),
                           int(foldWidth * 1.8)):
                yCopy -= foldWidth * 0.03
                db.rotate(math.sqrt((x - xOffset + 1) * 0.1),
                          center=(x, yCopy))
                fold(x, yCopy, foldWidth, currentPage)
                ticks += 1
                if (ticks > 2000):
                    raise Exception('Maximum depth reached')
コード例 #4
0
ファイル: drawbotpen.py プロジェクト: themucha/coldtype
 def image(self, src=None, opacity=1, rect=None, rotate=0, repeating=False, scale=True):
     bounds = self.dat.bounds()
     src = str(src)
     if not rect:
         rect = bounds
     try:
         img_w, img_h = db.imageSize(src)
     except ValueError:
         print("DrawBotPen: No image")
         return
     x = bounds.x
     y = bounds.y
     if repeating:
         x_count = bounds.w / rect.w
         y_count = bounds.h / rect.h
     else:
         x_count = 1
         y_count = 1
     _x = 0
     _y = 0
     while x <= (bounds.w+bounds.x) and _x < x_count:
         _x += 1
         while y <= (bounds.h+bounds.y) and _y < y_count:
             _y += 1
             with db.savedState():
                 r = Rect(x, y, rect.w, rect.h)
                 #db.fill(1, 0, 0.5, 0.05)
                 #db.oval(*r)
                 if scale == True:
                     db.scale(rect.w/img_w, center=r.point("SW"))
                 elif scale:
                     try:
                         db.scale(scale[0], scale[1], center=r.point("SW"))
                     except TypeError:
                         db.scale(scale, center=r.point("SW"))
                 db.rotate(rotate)
                 db.image(src, (r.x, r.y), alpha=opacity)
             y += rect.h
         y = 0
         x += rect.w
コード例 #5
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)
コード例 #6
0
def rotateScale(r, s, center):
    drawBot.rotate(r, center=center)
    drawBot.scale(s, center=center)