def drawContour(self): color = self.colorScheme.colorsRGB['contour'] drawBot.save() drawBot.fontSize(self.captionSize) drawBot.font(self.captionFont) for char in self.txt: uni = ord(char) glyphName = UV2AGL.get(uni) # interpolate g1 = self.font[glyphName].getLayer('regular') g2 = self.font[glyphName].getLayer('bold') glyph = RGlyph() glyph.name = g1.name glyph.unicode = g1.unicode glyph.interpolate(self.interpolationFactor, g1, g2) # draw contours drawBot.stroke(*color) drawBot.strokeWidth(self.contourStrokeWidth) drawBot.fill(None) B = drawBot.BezierPath() for contour in glyph.contours: contour.draw(B) drawBot.drawPath(B) # done glyph drawBot.translate(glyph.width, 0) drawBot.restore()
def setStrokeColor(c, w=1, fs=None, cmyk=False): u"""Set global stroke color or the color of the formatted string.""" if c is NO_COLOR: pass # Color is undefined, do nothing. elif c is None or isinstance( c, (float, long, int)): # Because None is a valid value. if cmyk: if fs is None: cmykStroke(c) else: fs.cmykStroke(c) else: if fs is None: stroke(c) else: fs.stroke(c) elif isinstance(c, (list, tuple)) and len(c) in (3, 4): if cmyk: if fs is None: cmykStroke(*c) else: fs.cmykStroke(*c) else: if fs is None: stroke(*c) else: fs.stroke(*c) else: raise ValueError('Error in color format "%s"' % c) if w is not None: strokeWidth(w)
def pageSetup(self): drawBot.newDrawing() drawBot.newPage("LetterLandscape") pageWidth = drawBot.width() pageHeight = drawBot.height() #drawBot.fill(0,0,0, 0.5) drawBot.stroke(0,0,0,.5) drawBot.strokeWidth(0.5) #this needs major clean up drawBot.line((margin, pageHeight-margin), (pageWidth-dpi, pageHeight-margin)) #xHeight line drawBot.line((margin, pageHeight-margin-self.xHeightTarget), (pageWidth-dpi, pageHeight-margin-self.xHeightTarget)) #baseline drawBot.line((margin, pageHeight-margin-(2.5*self.xHeightTarget)), (pageWidth-dpi, pageHeight-margin-(2.5*self.xHeightTarget))) #xHeight line drawBot.line((margin, pageHeight-margin-self.xHeightTarget-(2.5*self.xHeightTarget)), (pageWidth-dpi, pageHeight-margin-self.xHeightTarget-(2.5*self.xHeightTarget))) #baseline drawBot.line((margin, pageHeight-margin-(5*self.xHeightTarget)), (pageWidth-dpi, pageHeight-margin-(5*self.xHeightTarget))) #xHeight line drawBot.line((margin, pageHeight-margin-self.xHeightTarget-(5*self.xHeightTarget)), (pageWidth-dpi, pageHeight-margin-self.xHeightTarget-(5*self.xHeightTarget))) #baseline #drawBot.rect(margin, pageHeight-margin, pageWidth-dpi, -self.xHeightTarget) pdf = drawBot.pdfImage() # set the pdf data in the canvas self.w.canvas.setPDFDocument(pdf)
def _lineTo(self, pt): x0, y0 = self._getCurrentPoint() x, y = pt db.fill(None) db.stroke(r.random(), r.random(), r.random(), 1) db.strokeWidth(self.width) # db.newPath() db.moveTo((x0, y0)) db.lineTo(pt) db.drawPath() # Or use line() instead of newPath, moveTo, lineTo, drawPath combo # line((x0, y0), (x, y)) # Use rectangle below... still not sure why one over the other # angle = self.getAngle((x0, y0), (x, y)) # distance = self.getDistance((x0, y0), (x, y)) # fill(0, 0, 1, 1) # with savedState(): # rotate(angle, (x0, y0)) # rect(x0, y0 - self.width / 2, distance, self.width) self.pointsList.append(pt)
def draw(self, origin, view): p = pointOffset(self.oPoint, origin) p = self._applyScale(p) px, py, _ = p = self._applyAlignment(p) # Ignore z-axis for now. save() sh = 1.0 * self.h / self.ih transform((1, 0, 0, 1, px, py)) scale(sh) if self.pathFilter is not None: self.pathFilter(self, self.glyph.path) if self.css('fill') != NO_COLOR or self.css('stroke') != NO_COLOR: setFillColor(self.css('fill')) print(self.css('strokeWidth') or 1), sh setStrokeColor(self.css('stroke', NO_COLOR), (self.css('strokeWidth') or 20)) fill(0) stroke(1, 0, 0) strokeWidth(20) drawPath(self.glyph.path) restore() # If there are child elements, draw them over the polygon. self._drawElements(p, view) # Draw optional bounding box. #self.drawFrame(origin, view) self._restoreScale() view.drawElementMetaInfo( self, origin) # Depends on css flag 'showElementInfo'
def _drawGlyphMarker(self, axisName, mx, my, glyphName, fontSize, location, strokeW=2): # Middle circle fill(1) stroke(0.7) strokeWidth(strokeW) oval(mx - fontSize / 2 * self.R, my - fontSize / 2 * self.R, fontSize * self.R, fontSize * self.R) variableFont = getVariableFont(self.font, location) # Show axis name below circle marker? if self.showAxisNames and axisName is not None: fs = newFS(axisName, style=dict(font=variableFont.installedName, fontSize=fontSize / 4, textFill=0)) tw, th = textSize(fs) text(fs, (mx - tw / 2, my - fontSize / 2 * self.R - th * 2 / 3)) glyphPathScale = fontSize / self.font.info.unitsPerEm drawGlyphPath(variableFont, glyphName, mx, my - fontSize / 3, s=glyphPathScale, fillColor=0)
def drawPageFrame(self, page, origin): u"""Draw the page frame if the the flag is on and if there ie padding enough to show other meta info. Otherwise the padding is truncated to 0: no use to draw the frame.""" if self.showPageFrame: # Different from base View, no check on padding. fill(None) stroke(0.5) strokeWidth(0.5) rect(origin[0], origin[1], page.w, page.h)
def __enter__(self): db.save() for k, v in self.style.items(): db.fill(None) db.stroke(None) db.strokeWidth(1) getattr(db, k)(*v) return self
def drawGlyph(self): color = self.colorScheme.colorsRGB['glyph'] drawBot.save() drawBot.fontSize(self.captionSize) drawBot.font(self.captionFont) for char in self.txt: uni = ord(char) glyphName = UV2AGL.get(uni) # interpolate g1 = self.font[glyphName].getLayer('regular') g2 = self.font[glyphName].getLayer('bold') glyph = RGlyph() glyph.name = g1.name glyph.unicode = g1.unicode glyph.interpolate(self.interpolationFactor, g1, g2) # contours drawBot.fill(*color) B = drawBot.BezierPath() for contour in glyph.contours: contour.draw(B) drawBot.drawPath(B) # advance width if self.glyphWidthDraw: drawBot.save() drawBot.strokeWidth(self.glyphWidthStrokeWidth) drawBot.stroke(*color) drawBot.line((0, self.yBottom), (0, self.yTop)) drawBot.restore() # glyph data if self.glyphDataDraw: h = self.captionSize * 1.5 m = 40 w = glyph.width - m * 2 drawBot.save() drawBot.stroke(None) drawBot.fill(*color) y = self.yTop - h drawBot.textBox(glyph.name, (m, y, w, h)) drawBot.textBox(str(glyph.unicode), (m, y, w, h), align='right') y = self.yBottom drawBot.textBox(str(int(glyph.width)), (m, y, w, h), align='center') drawBot.restore() # done glyph drawBot.translate(glyph.width, 0) # last margin if self.glyphWidthDraw: drawBot.strokeWidth(self.glyphWidthStrokeWidth) drawBot.stroke(*color) drawBot.line((0, self.yBottom), (0, self.yTop)) # done drawBot.restore()
def _drawGlyphMarker(self, mx, my, glyphName, fontSize, location, strokeW=2): # Middle circle fill(1) stroke(0) strokeWidth(strokeW) oval(mx-fontSize*self.R, my-fontSize*self.R, fontSize*2*self.R, fontSize*2*self.R) glyphPathScale = fontSize/self.font.info.unitsPerEm drawGlyphPath(self.font.ttFont, glyphName, mx, my-fontSize/4, location, s=glyphPathScale, fillColor=0)
def _drawGlyphMarker(self, mx, my, glyphName, markerSize, location, strokeW=2): # Middle circle fill(1) stroke(0) strokeWidth(strokeW) oval(mx-markerSize/2, my-markerSize/2, markerSize, markerSize) glyphPathScale = markerSize/self.font.info.unitsPerEm*3/4 drawGlyphPath(self.font.ttFont, glyphName, mx, my-markerSize/4, location, s=glyphPathScale, fillColor=0)
def draw(self, page, x, y): fillColor = self.style.get('fill') if fillColor is not None: setFillColor(fillColor) setStrokColor(None) stroke(0.8) strokeWidth(0.5) fill(None) rect(x, y, self.w, self.h) if len(self.dimensions) == 1: raise ValueError('Not supporting 1 axis now') if len(self.dimensions) > 2: raise ValueError('Not supporting >2 axis now') axisNames = sorted(self.dimensions.keys()) axisX = axisNames[0] sizeX = self.dimensions[axisX] axisY = axisNames[1] sizeY = self.dimensions[axisY] stepX = self.w / (sizeX + 1) stepY = self.h / (sizeY + 1) """Add more parametric layout behavior here.""" RANGE = 1000 for indexX in range(sizeX + 1): for indexY in range(sizeY + 1): ox = 30 oy = 25 px = ox + x + indexX * stepX py = oy + y + indexY * stepY self.location[axisX] = indexX * RANGE / sizeX self.location[axisY] = indexY * RANGE / sizeY glyphPathScale = self.fontSize / self.font.info.unitsPerEm drawGlyphPath(self.font.ttFont, self.glyphNames[0], px, py, self.location, s=glyphPathScale, fillColor=(0, 0, 0)) fs = FormattedString('%s %d\n%s %d' % (axisX, indexX * RANGE / sizeX, axisY, indexY * RANGE / sizeY), fontSize=6, fill=0) w, h = fs.size() page.text( fs, px - stepX / 4, py - 16) # Bit of hack, we need the width of the glyph here. fs = FormattedString('Other axes: %s' % self.location, fontSize=6, fill=0) w, h = fs.size() page.text(fs, x, y - 16)
def drawPageFrame(self, page, origin): u"""Draw the page frame if the the flag is on and if there ie padding enough to show other meta info. Otherwise the padding is truncated to 0: no use to draw the frame.""" if self.showPageFrame and \ self.pl > self.MIN_PADDING and self.pr > self.MIN_PADDING and \ self.pt > self.MIN_PADDING and self.pb > self.MIN_PADDING: fill(None) stroke(0, 0, 1) strokeWidth(0.5) rect(origin[0], origin[1], page.w, page.h)
def drawCell(glyphName, cellWidth, cellHeight, cellLegendSize): # Cell outline db.fill(None) db.stroke(0) db.strokeWidth(0.25) db.rect(0, 0, cellWidth, cellHeight) charArea = cellWidth / 3.5 fontSize = charArea * 0.7 charStartingOffset = (cellWidth * 0.5) - (charArea * 1.5) # Glyph sample for iH, aH in enumerate(angles): for iV, aV in enumerate(reversed(angles)): locStr = "%s %s" % (aH, aV) f = instances[locStr] if glyphName in f: g = f[glyphName] with db.savedState(): db.translate(charStartingOffset, charStartingOffset ) # Center the nine glyphs in the cell db.translate( iH * charArea, iV * charArea) # Move to the current glyph in the cell db.translate(charArea * 0.5, 0) # Offset to center glyph in cell db.translate(0, cellLegendSize * 3) # Leave room for the legend # Draw db.fill(0) db.stroke(None) db.scale(fontSize / 1000) drawGlyph(g) # Legend db.fill(None) db.stroke(0) db.strokeWidth(0.25) db.lineCap("round") db.line((cellLegendSize, cellLegendSize * 3), (cellWidth - cellLegendSize, cellLegendSize * 3)) unicodeValueStr = "" if g.unicode: unicodeValueStr = hex(g.unicode) legendText = "%s\n%s" % (g.name, unicodeValueStr) fs = db.FormattedString(legendText, font="Tilt Neon", fontSize=cellLegendSize, tracking=1, lineHeight=cellLegendSize) db.text(fs, (cellLegendSize, cellLegendSize * 1.7))
def stroke(self, weight=1, color=None, dash=None): db.strokeWidth(weight) if dash: db.lineDash(dash) if color: if isinstance(color, Gradient): pass # possible? elif isinstance(color, Color): db.stroke(color.r, color.g, color.b, color.a) else: db.stroke(None)
def stroke(self, isStroke, color, lineWidth, lineCap='round', lineJoin='round'): if not isStroke: ctx.stroke(None) return if type(color) is str and color.startswith('#'): color = hexToRGB(color) ctx.strokeWidth(lineWidth) ctx.stroke(*color) ctx.lineCap(lineCap) ctx.lineJoin(lineJoin)
def _curveToOne(self, pt1, pt2, pt3): x0, y0 = self._getCurrentPoint() db.fill(None) db.stroke(r.random(), r.random(), r.random(), 1) db.strokeWidth(self.width) # db.newPath() db.moveTo((x0, y0)) db.curveTo(pt1, pt2, pt3) db.drawPath() self.pointsList.append(pt3)
def drawInfo(self): color = self.colorScheme.colorsRGB['info'] drawBot.save() # font info if self.infoValuesDraw: drawBot.fill(*color) drawBot.fontSize(self.captionSizeLarge) h = self.captionSizeLarge * 2 y = self.yTop txt = '%s %s' % (self.font.info.familyName, self.font.info.styleName) drawBot.textBox(txt, (0, y, self.textLength, h)) # blue zones # for i, y in enumerate(self.font.info.postscriptBlueValues): # if not i % 2: # yNext = self.font.info.postscriptBlueValues[i+1] # h = yNext - y # drawBot.fill(*color + (0.35,)) # drawBot.rect(0, y, self.textLength, h) # vertical dimensions yValues = set([ 0, self.font.info.xHeight, self.font.info.capHeight, self.font.info.descender, self.font.info.ascender, ]) drawBot.font(self.captionFont) drawBot.fontSize(self.captionSize) for y in yValues: # draw guide drawBot.stroke(*color) drawBot.strokeWidth(self.infoStrokeWidth) if not self.infoLineDash: drawBot.lineDash(None) else: drawBot.lineDash(*self.infoLineDash) drawBot.line((0, y), (self.textLength, y)) # draw y value if self.infoValuesDraw: w = 300 m = 50 drawBot.save() drawBot.stroke(None) drawBot.fill(*color) drawBot.textBox(str(int(y)), (-w-m, y-self.captionSize*0.5, w, self.captionSize*1.2), align='right') drawBot.restore() # done drawBot.restore()
def createPlaceholder(wdt, hgt, locationOnDisk): dB.newDrawing() dB.newPage(wdt, hgt) dB.fill(.5) dB.rect(0, 0, dB.width(), dB.height()) dB.stroke(1) dB.strokeWidth(10) dB.line((0, 0), (dB.width(), dB.height())) dB.line((0, dB.height()), (dB.width(), 0)) dB.saveImage(f'{locationOnDisk}') dB.endDrawing()
def drawForeground(self, ox, oy, doc, page, parent): """Draw the foreground of the element. Default is to just draw the rectangle with the fill color, if it is defined. This method should be redefined by inheriting subclasses that need different foreground drawing. """ if self.stroke is not None and self.strokeWidth: # Only if defined. drawBot.fill(None) # Fill is done in background drawing. r, g, b, a = asColor(self.stroke) if r is None: drawBot.stroke(None) else: drawBot.strokeWidth(self.strokeWidth) drawBot.stroke(r, g, b, a) if self.w is not None and self.h is not None: drawBot.rect(ox, oy, self.w, self.h)
def drawPagePadding(self, page, origin): u"""Draw the page frame of its current padding.""" pt, pr, pb, pl = page.padding if self.showPagePadding and (pt or pr or pb or pl): p = pointOffset(page.oPoint, origin) p = page._applyScale(p) px, py, _ = page._applyAlignment(p) # Ignore z-axis for now. fill(None) stroke(0, 0, 1) strokeWidth(0.5) if page.originTop: rect(px + pr, py + page.h - pb, page.w - pl - pr, page.h - pt - pb) else: rect(px + pr, py + pb, page.w - pl - pr, page.h - pt - pb)
def drawPageCropMarks(self, e, origin): u"""If the show flag is set, then draw the cropmarks or page frame.""" if self.showPageCropMarks: x, y, _ = point3D(origin) # Ignore z-axus for now. w, h = e.w, e.h folds = self.css('folds') bleed = self.css('bleed') / 2 # 1/2 overlap with image bleed cmSize = min(self.css('viewCropMarkSize', 32), self.pl) cmStrokeWidth = self.css('viewCropMarkStrokeWidth') fill(None) cmykStroke(1, 1, 1, 1) strokeWidth(cmStrokeWidth) newPath() # Bottom left moveTo((x - bleed, y)) lineTo((x - cmSize, y)) moveTo((x, y - bleed)) lineTo((x, y - cmSize)) # Bottom right moveTo((x + w + bleed, y)) lineTo((x + w + cmSize, y)) moveTo((x + w, y - bleed)) lineTo((x + w, y - cmSize)) # Top left moveTo((x - bleed, y + h)) lineTo((x - cmSize, y + h)) moveTo((x, y + h + bleed)) lineTo((x, y + h + cmSize)) # Top right moveTo((x + w + bleed, y + h)) lineTo((x + w + cmSize, y + h)) moveTo((x + w, y + h + bleed)) lineTo((x + w, y + h + cmSize)) # Any fold lines to draw? if folds is not None: for fx, fy in folds: if fx is not None: moveTo((x + fx, y - bleed)) lineTo((x + fx, y - cmSize)) moveTo((x + fx, y + h + bleed)) lineTo((x + fx, y + h + cmSize)) if fy is not None: moveTo((x - bleed, y + fy)) lineTo((x - cmSize, y + fy)) moveTo((x + w + bleed, y + fy)) lineTo((x + w + cmSize, y + fy)) drawPath()
def drawGuideline(self): color = self.colorScheme.colorsRGB['guideline'] drawBot.save() drawBot.stroke(*color) drawBot.strokeWidth(self.guidelineStrokeWidth) drawBot.font(self.captionFont) drawBot.fontSize(self.captionSize) for guide in self.font.guidelines: drawBot.line((0, guide.y), (self.textLength, guide.y)) if self.guidelineValuesDraw: w = 300 m = 50 drawBot.save() drawBot.stroke(None) drawBot.fill(*color) drawBot.textBox(str(int(guide.y)), (-(w + m), guide.y - self.captionSize * 0.5, w, self.captionSize * 1.2), align='right') drawBot.restore() drawBot.restore()
def drawPlusMinus(sf, a): x, y = a.x, a.y x, y, ang = a.x, a.y, a.angle path = d.BezierPath() path.moveTo((-50, 0)) path.lineTo((50, 0)) if a.type == PLUS: path.moveTo((0, 50)) path.lineTo((0, -50)) path.closePath() path.scale(sf) d.lineCap("round") d.lineJoin("round") path.translate(x, y) d.fill(None) d.stroke(1, 0, 0, 0.5) d.strokeWidth(annoThickness / sf) d.drawPath(path)
def drawArrow(sf, a): x, y, ang = a.x, a.y, a.angle path = d.BezierPath() path.moveTo((50, 40)) path.lineTo((0, 0)) path.lineTo((50, -40)) path.moveTo((0, 0)) path.lineTo((120, 0)) path.closePath() path.scale(sf) d.lineCap("round") d.lineJoin("round") path.rotate(ang, center=(0, 0)) path.translate(x, y) d.fill(None) d.stroke(1, 0, 0, 0.5) d.strokeWidth(annoThickness / sf) d.drawPath(path)
def drawAnchor(self): r = self.anchorSize * 0.5 color = self.colorScheme.colorsRGB['anchor'] drawBot.save() drawBot.strokeWidth(self.anchorStrokeWidth) drawBot.stroke(*color) drawBot.fill(None) for char in self.txt: uni = ord(char) glyphName = UV2AGL.get(uni) glyph = self.font[glyphName] if len(glyph.anchors): for anchor in glyph.anchors: x, y = anchor.x, anchor.y drawBot.oval(x-r, y-r, r*2, r*2) drawBot.line((x-r, anchor.y), (x+r, anchor.y)) drawBot.line((anchor.x, y-r), (anchor.x, y+r)) drawBot.translate(glyph.width, 0) drawBot.restore()
def test_distribute_on_path(self): mistral = Font.Cacheable("~/Type/fonts/fonts/_script/MistralD.otf") with test_image(self, "test_distribute.png", Rect(1000, 1000)) as (i, r): s = (StyledString("Hello", Style(mistral, 300)).pens().f( hsl(0.3, s=1)).align(r).chain(dbdraw)) with db.savedState(): db.fill(None) db.stroke(0) db.strokeWidth(1) db.rect(*s.ambit()) circle = DraftingPen().oval(r.inset(200)).reverse().rotate(0) s2 = (s.copy().zero_translate().distribute_on_path(circle).chain( dbdraw)) self.assertEqual(s.f(), s2.f())
def drawCropMarks(origin, w, h, bleed, cmSize, cmStrokeWidth, folds=None): u"""If the show flag is set, then draw the cropmarks or page frame.""" x, y, _ = point3D(origin) # Ignore z-axus for now. fill(None) cmykStroke(1, 1, 1, 1) strokeWidth(cmStrokeWidth) newPath() # Bottom left moveTo((x - bleed, y)) lineTo((x - cmSize, y)) moveTo((x, y - bleed)) lineTo((x, y - cmSize)) # Bottom right moveTo((x + w + bleed, y)) lineTo((x + w + cmSize, y)) moveTo((x + w, y - bleed)) lineTo((x + w, y - cmSize)) # Top left moveTo((x - bleed, y + h)) lineTo((x - cmSize, y + h)) moveTo((x, y + h + bleed)) lineTo((x, y + h + cmSize)) # Top right moveTo((x + w + bleed, y + h)) lineTo((x + w + cmSize, y + h)) moveTo((x + w, y + h + bleed)) lineTo((x + w, y + h + cmSize)) # Any fold lines to draw? if folds is not None: for fx, fy in folds: if fx is not None: moveTo((x + fx, y - bleed)) lineTo((x + fx, y - cmSize)) moveTo((x + fx, y + h + bleed)) lineTo((x + fx, y + h + cmSize)) if fy is not None: moveTo((x - bleed, y + fy)) lineTo((x - cmSize, y + fy)) moveTo((x + w + bleed, y + fy)) lineTo((x + w + cmSize, y + fy)) drawPath()
def drawRegistrationMark(origin, cmSize, cmStrokeWidth, vertical): u"""Draw registration mark as position x, y.""" x, y = origin if vertical: dx = cmSize / 2 dy = cmSize else: dx = cmSize dy = cmSize / 2 fill(None) cmykStroke(1, 1, 1, 1) strokeWidth(cmStrokeWidth) newPath() # Registration circle oval(x - cmSize / 4, y - cmSize / 4, cmSize / 2, cmSize / 2) # Registration cross, in length of direction. moveTo((x - dx, y)) # Horizontal line. lineTo((x + dx, y)) moveTo((x, y + dy)) # Vertical line. lineTo((x, y - dy)) drawPath()
def drawBPoint(self): r1 = self.bPointSize * 0.5 r2 = self.pointSize * 0.5 color = self.colorScheme.colorsRGB['bPoint'] drawBot.save() for char in self.txt: uni = ord(char) glyphName = UV2AGL.get(uni) # interpolate g1 = self.font[glyphName].getLayer('regular') g2 = self.font[glyphName].getLayer('bold') glyph = RGlyph() glyph.name = g1.name glyph.unicode = g1.unicode glyph.interpolate(self.interpolationFactor, g1, g2) for c in glyph.contours: for pt in c.bPoints: x, y = pt.anchor xIn, yIn = pt.bcpIn xOut, yOut = pt.bcpOut drawBot.fill(*color) drawBot.stroke(None) drawBot.oval(x - r1, y - r1, r1 * 2, r1 * 2) if not self.layers['point']: drawBot.oval(x + xIn - r2, y + yIn - r2, r2 * 2, r2 * 2) drawBot.oval(x + xOut - r2, y + yOut - r2, r2 * 2, r2 * 2) drawBot.fill(None) drawBot.stroke(*color) drawBot.strokeWidth(5) drawBot.line((x, y), (x + xIn, y + yIn)) drawBot.line((x, y), (x + xOut, y + yOut)) drawBot.translate(glyph.width, 0) drawBot.restore()
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()
import drawBot drawBot.size(200, 200) drawBot.stroke(0, 0, 1) drawBot.strokeWidth(5) with drawBot.savedState(): drawBot.fill(1, 0, 0) drawBot.translate(100, 100) drawBot.rect(0, 0, 100, 100) drawBot.rect(0, 0, 100, 100) with drawBot.savedState(): drawBot.fill(0, 1, 0) drawBot.translate(100, 0) drawBot.rect(0, 0, 100, 100) drawBot.rect(0, 100, 100, 100)
import drawBot drawBot.size(200, 200) drawBot.text("hello world", (10, 10)) drawBot.fill(1, 0, 0) drawBot.text("foo bar", (10, 30)) drawBot.fill(1, 0, 1) drawBot.stroke(0, 1, 0) drawBot.strokeWidth(4) drawBot.font("Times", 50) drawBot.text("foo bar", (10, 50)) drawBot.fill(None) drawBot.stroke(0, 1, 0) drawBot.strokeWidth(1) drawBot.line((0, 50), (drawBot.width(), 50)) drawBot.stroke(None) drawBot.fill(0, 1, 1) drawBot.fontSize(20) drawBot.text("foo bar", (drawBot.width()*.5, 100), align="right") drawBot.text("foo bar", (drawBot.width()*.5, 120), align="center") drawBot.text("foo bar", (drawBot.width()*.5, 140), align="left")