def pipe(x0, y0, x1, y1, x2, y2, x3, y3, c, x): c.stroke( path.curve(x0, y0, x1, y1, x2, y2, x3, y3), [color.rgb.black, style.linewidth(width=0.6 * x / 24)]) c.stroke(path.curve(x0, y0, x1, y1, x2, y2, x3, y3), [color.cmyk.RoyalBlue, style.linewidth(width=0.5 * x / 24)])
def state(x0, y0, r, c): x1 = x0 - r / sqrt(2) y1 = y0 + r / sqrt(2) x2 = x0 - 3 * r / 4 / sqrt(2) y2 = y1 + r / 8 x3 = x0 - r / 4 / sqrt(2) y3 = y1 - r / 8 x4 = x0 + r / 4 / sqrt(2) y4 = y1 + r / 8 x5 = x0 + 3 * r / 4 / sqrt(2) y5 = y1 - r / 8 x6 = x0 + r / sqrt(2) y6 = y1 delta = r / 40 c.fill(path.circle(x0, y0, r), [color.cmyk.RoyalBlue]) c.fill(path.rect(x1 + delta, y0 + delta, r * sqrt(2) - 2 * delta, r), [color.rgb.white]) inside = path.curve(x1, y1, x2, y2, x3, y3, x0, y1) << \ path.curve(x0, y1, x4, y4, x5, y5, x6, y6) << \ path.line(x6, y6, x6, y0) << \ path.line(x6, y0, x1, y0) inside.append(path.closepath()) c.fill(inside, [color.cmyk.RoyalBlue]) c.stroke(path.circle(x0, y0, r), [style.linewidth(r / 25)])
def matrix_22(m, dx=0.5, dy=0.5, pd=0.1, pdx=0.1, pdy=0.3): c = canvas.canvas() for nx in range(2): for ny in range(2): c.text(nx*dx, -ny*dy, str(m[ny, nx]), [text.halign.center]) box = c.bbox() xoff = box.left()-pd c.stroke(path.curve(xoff, box.top()+pd, xoff-pdx, box.top()-pdy, xoff-pdx, box.bottom()+pdy, xoff, box.bottom()-pd)) xoff = box.right()+pd c.stroke(path.curve(xoff, box.top()+pd, xoff+pdx, box.top()-pdy, xoff+pdx, box.bottom()+pdy, xoff, box.bottom()-pd)) return c
def draw_crs_to_canvas(c, crs: torch.Tensor, lw=1, lcols=None, alpha=0.5): # crs [n, nc, 2]; only draw nc>1<nc-1 if crs is None: return n, nc, _ = crs.shape # Premultiplied power constant for the following tj() function. alpha = alpha / 2 def tj(ti, pi, pj): return ((pi - pj)**2).sum(dim=-1)**alpha + ti if lcols is not None: lcols = lcols.detach().cpu() if crs is not None: crs = crs.detach().cpu() for i in range(n): _lw = lw[i] if isinstance(lw, torch.Tensor) else lw if _lw > 1e-3: for j in range(nc - 4 + 1): p0 = crs[i, j + 0] p1 = crs[i, j + 1] p2 = crs[i, j + 2] p3 = crs[i, j + 3] t0 = 0 t1 = tj(t0, p0, p1) t2 = tj(t1, p1, p2) t3 = tj(t2, p2, p3) c1 = (t2 - t1) / (t2 - t0) c2 = (t1 - t0) / (t2 - t0) d1 = (t3 - t2) / (t3 - t1) d2 = (t2 - t1) / (t3 - t1) m1 = (t2 - t1) * (c1 * (p1 - p0) / (t1 - t0) + c2 * (p2 - p1) / (t2 - t1)) m2 = (t2 - t1) * (d1 * (p2 - p1) / (t2 - t1) + d2 * (p3 - p2) / (t3 - t2)) q0 = p1 q1 = p1 + m1 / 3 q2 = p2 - m2 / 3 q3 = p2 curve = path.curve(q0[1], -q0[0], q1[1], -q1[0], q2[1], -q2[0], q3[1], -q3[0]) if lcols is None: c.stroke(curve, [style.linewidth(_lw), style.linecap.round]) else: c.stroke(curve, [ style.linewidth(_lw), style.linecap.round, color.rgb(*lcols[i]) ])
def matrix_22(m, dx=0.5, dy=0.5, pd=0.1, pdx=0.1, pdy=0.3): c = canvas.canvas() for nx in range(2): for ny in range(2): c.text(nx * dx, -ny * dy, str(m[ny, nx]), [text.halign.center]) box = c.bbox() xoff = box.left() - pd c.stroke( path.curve(xoff, box.top() + pd, xoff - pdx, box.top() - pdy, xoff - pdx, box.bottom() + pdy, xoff, box.bottom() - pd)) xoff = box.right() + pd c.stroke( path.curve(xoff, box.top() + pd, xoff + pdx, box.top() - pdy, xoff + pdx, box.bottom() + pdy, xoff, box.bottom() - pd)) return c
def display(self): """method to display the sector""" # draw the segment if self.level == 0: # don't draw anything in the center return if self.letter == '': self.sunburst.text_object.update( self.level, self.path[6:], (self.centroid_radians, self.inner_r + 0.5 * self.sector_width), self.freq) else: self.sunburst.text_object.update( self.level, self.letter, (self.centroid_radians, self.inner_r + 0.5 * self.sector_width), self.freq) if self.letter == '': self.draw_sector(True) else: self.draw_sector(False) if self.level == 1: # don't draw lines to nothing return # draw the bezier x0 = (self.inner_r + 0.05) * cos(self.centroid_radians) + self.xo y0 = (self.inner_r + 0.05) * sin(self.centroid_radians) + self.yo r = self.parent_outer_radius x1 = r * cos(self.centroid_radians) + self.xo y1 = r * sin(self.centroid_radians) + self.yo delta = 0.1 * (self.centroid_radians - self.parent_centroid_radian) r = self.inner_r x2 = r * cos(self.parent_centroid_radian + delta) + self.xo y2 = r * sin(self.parent_centroid_radian + delta) + self.yo x3 = self.parent_outer_radius * cos(self.parent_centroid_radian + delta) + self.xo y3 = self.parent_outer_radius * sin(self.parent_centroid_radian + delta) + self.yo sector_len = (self.end_angle - self.start_angle) * self.inner_r * pi / 180.0 self.shape_canvas.stroke( path.curve(x0, y0, x1, y1, x2, y2, x3, y3), [style.linewidth(0.05 * sector_len), self.sector_color])
def makePath(self): ''' makes pyx path object from pygame points ''' # so we can use pop() w/o modifying self.positions positions = copy.copy(self.points) positions.reverse() p = None # BEZIER CURVES while len(positions) > 4: # need at least 4 points to make bezier curve # make a bezier curve points = [] for _ in range(3): points += positions.pop() points += positions[-1] # so next curve will start at this point if p: p += path.curve(*points) else: p = path.curve(*points) # LINES while len(positions) > 1: # use up rest of points with lines points = [] points += positions.pop() points += positions[-1] if p: p += path.line(*points) else: p = path.line(*points) # store curve in object p = deformer.smoothed(2.0).deform(p) # smooth curve self.path = p self.arclen = p.arclen_pt()*metersPerPoint self.duration = self.arclen/self.velocity
def makePath(self): ''' makes pyx path object from pygame points ''' # so we can use pop() w/o modifying self.positions positions = copy.copy(self.points) positions.reverse() p = None # BEZIER CURVES while len( positions) > 4: # need at least 4 points to make bezier curve # make a bezier curve points = [] for _ in range(3): points += positions.pop() points += positions[-1] # so next curve will start at this point if p: p += path.curve(*points) else: p = path.curve(*points) # LINES while len(positions) > 1: # use up rest of points with lines points = [] points += positions.pop() points += positions[-1] if p: p += path.line(*points) else: p = path.line(*points) # store curve in object p = deformer.smoothed(2.0).deform(p) # smooth curve self.path = p self.arclen = p.arclen_pt() * metersPerPoint self.duration = self.arclen / self.velocity
text.set(text.LatexRunner) c = canvas.canvas() c.stroke(path.circle(0, 0, 1)) c.stroke(path.circle(5, 0, 1)) c.stroke(path.circle(15, 0, 1)) c.stroke(path.circle(20, 5, 1)) c.stroke(path.circle(9, 0, 0.1), [style.linewidth.THICK]) c.stroke(path.circle(10, 0, 0.1), [style.linewidth.THICK]) c.stroke(path.circle(11, 0, 0.1), [style.linewidth.THICK]) c.text(0, 0, r'\Huge{1}', [text.parbox(0), text.valign.middle, text.halign.center]) c.text(5, 0, r'\Huge{2}', [text.parbox(0), text.valign.middle, text.halign.center]) c.text(15, 0, r'\Huge{K}', [text.parbox(0), text.valign.middle, text.halign.center]) c.text(20, 5, r'\Huge{0}', [text.parbox(0), text.valign.middle, text.halign.center]) c.stroke(path.curve(1 / sqrt(2), 1 / sqrt(2), 2, 2, 3, 2, 5 - 1 / sqrt(2), 1 / sqrt(2)), [deco.earrow(size=1)]) c.stroke(path.curve(5 - 1 / sqrt(2), -1 / sqrt(2), 3, -2, 2, -2, 1 / sqrt(2), -1 / sqrt(2)), [deco.earrow(size=1)]) c.stroke(path.curve(1 / sqrt(2), 1 / sqrt(2), 1, 5, 10, 5, 19, 5), [deco.earrow(size=1)]) c.stroke(path.curve(5 + 1 / sqrt(2), 1 / sqrt(2), 7, 5, 12, 5, 19, 5), [deco.earrow(size=1)]) c.stroke(path.line(15 + 1 / sqrt(2), 1 / sqrt(2), 20 - 1 / sqrt(2), 5 - 1 / sqrt(2)), [deco.earrow(size=1)]) c.text(2.5, 2.5, r'\huge{$p_1^2$}', [text.parbox(0), text.valign.middle, text.halign.center]) c.text(2.5, -1, r'\huge{$p_2^1$}', [text.parbox(0), text.valign.middle, text.halign.center]) c.text(2.5, 4, r'\huge{$p_1^0$}', [text.parbox(0), text.valign.middle, text.halign.center]) c.text(8, 3, r'\huge{$p_2^0$}', [text.parbox(0), text.valign.middle, text.halign.center]) c.text(18, 2, r'\huge{$p_K^0$}', [text.parbox(0), text.valign.middle, text.halign.center]) c.writePDFfile("states.pdf")
from pyx import canvas, color, path p1 = path.curve(0, 0, 1, 0, 1, 1, 2, 1) p2 = path.circle(1, 0.5, 0.5) (a1, a2), (b1, b2) = p1.intersect(p2) x1, y1 = p1.at(a1) x2, y2 = p1.at(a2) c = canvas.canvas() c.fill(path.circle(x1, y1, 0.1), [color.rgb.blue]) c.fill(path.circle(x2, y2, 0.1), [color.rgb.blue]) c.stroke(p1, [color.rgb.red]) c.stroke(p2, [color.rgb.green]) c.writePDFfile() c.writeGSfile(device="png16m", resolution=800)
from pyx import canvas, color, deco, path, text, unit text.set(text.LatexRunner) text.preamble( r'\usepackage[sfdefault,scaled=.85,lining]{FiraSans}\usepackage{newtxsf}') text.preamble(r'\usepackage{nicefrac}') unit.set(xscale=1.4, wscale=1.2) c = canvas.canvas() r = 0.05 for n in range(1, 5): c.stroke(path.circle(n, 0, r)) c.stroke(path.circle(-n, 0, r)) c.stroke(path.circle(0, 0, r), [deco.filled([color.grey(0)])]) dx = 0.1 dy = 0.3 c.stroke(path.curve(dx, dx, dy, dy, 1 - dy, dy, 1 - dx, dx), [deco.earrow]) c.text(0.5, dy + 0.1, '+1', [text.halign.center]) c.stroke(path.curve(-dx, dx, -dy, dy, -1 + dy, dy, -1 + dx, dx), [deco.earrow]) c.text(-0.5, dy + 0.1, '-1', [text.halign.center]) c.writePDFfile()
from pyx import canvas, color, deco, path, text, unit text.set(text.LatexRunner) text.preamble(r'\usepackage[sfdefault,scaled=.85,lining]{FiraSans}\usepackage{newtxsf}') text.preamble(r'\usepackage{nicefrac}') unit.set(xscale=1.4, wscale=1.2) c = canvas.canvas() r = 0.05 for n in range(1, 5): c.stroke(path.circle(n, 0, r)) c.stroke(path.circle(-n, 0, r)) c.stroke(path.circle(0, 0, r), [deco.filled([color.grey(0)])]) dx = 0.1 dy = 0.3 c.stroke(path.curve(dx, dx, dy, dy, 1-dy, dy, 1-dx, dx), [deco.earrow]) c.text(0.5, dy+0.1, '+1', [text.halign.center]) c.stroke(path.curve(-dx, dx, -dy, dy, -1+dy, dy, -1+dx, dx), [deco.earrow]) c.text(-0.5, dy+0.1, '-1', [text.halign.center]) c.writePDFfile()
tmax = 0.8 * width lowertick = -0.15 color_cl = color.rgb(0.2, 0, 0.8) color_fluc = color.rgb(0.2, 0.6, 0) text.set(engine=text.LatexEngine) text.preamble(r'''\usepackage[sfdefault,scaled=.85]{FiraSans} \usepackage{newtxsf}''') unit.set(vscale=1.2, wscale=1.3, xscale=1.3) c = canvas.canvas() c.stroke(path.line(0, 0, width, 0), [deco.earrow]) c.text(width + 0.1, 0, '$t$', [text.valign.middle]) c.stroke(path.line(0, 0, 0, height), [deco.earrow]) c.text(0.2, height, '$q$', [text.valign.top]) c.stroke( path.curve(0, qi, 0.4 * tmax, qi + 0.2 * (qf - qi), 0.5 * tmax, 2 * qf, tmax, qf), [color_fluc]) c.stroke( path.curve(0, qi, 0.2 * tmax, qi + 2 * (qf - qi), 0.7 * tmax, 0.5 * qf, tmax, qf), [color_fluc]) c.stroke( path.curve(0, qi, 0.2 * tmax, qi - 0.4 * (qf - qi), 0.7 * tmax, 1.1 * qf, tmax, qf), [color_fluc]) c.stroke( path.curve(0, qi, 0.2 * tmax, qi + 0.8 * (qf - qi), 0.7 * tmax, 1.2 * qf, tmax, qf), [style.linewidth.thick, color_cl]) for x, y in ((0, qi), (tmax, qf)): c.fill(path.circle(x, y, 0.04), [color.grey(1), deco.stroked([color.grey(0)])]) c.text(-0.1, qi, r'$q_\text{i}$', [text.halign.right, text.valign.middle]) c.text(tmax + 0.1, qf, r'$q_\text{f}$', [text.valign.middle]) c.stroke(path.line(0.73 * tmax, 1.03 * qf, tmax, 0.6 * qf),
dy = 0.8 c = canvas.canvas() for nx in range(3): for ny in range(3): c.text(nx * dx, -ny * dy, r'a[\textcolor{axis0}{%s}, \textcolor{axis1}{%s}]' % (ny, nx), [text.halign.center]) box = c.bbox() pd = 0.1 xoff = box.left() - pd pdx = 0.2 pdy = 0.5 c.stroke( path.curve(xoff, box.top() + pd, xoff - pdx, box.top() - pdy, xoff - pdx, box.bottom() + pdy, xoff, box.bottom() - pd)) xoff = box.right() + pd c.stroke( path.curve(xoff, box.top() + pd, xoff + pdx, box.top() - pdy, xoff + pdx, box.bottom() + pdy, xoff, box.bottom() - pd)) x = box.left() - pdx - 0.4 c.stroke(path.line(x, box.top(), x, box.bottom()), [deco.earrow, color0]) c.text( x - 0.1, 0.5 * (box.top() + box.bottom()), 'axis 0', [text.halign.center, color0, trafo.rotate(90)]) y = box.top() + 0.4
c = canvas.canvas() c.fill(path.rect(0, 0, boxwidth, height), [color.rgb(0.92, 1, 0.92)]) for n in range(-1, 4): c.stroke(path.line(n * boxwidth, 0, n * boxwidth, height), [style.linewidth.THick, color.grey(0.4)]) poslinestyle = (style.linestyle.dashed, style.linewidth.thick) c.stroke(path.line(qi, 0, qi, height), [*poslinestyle, color.rgb(0.2, 0.6, 0)]) for n in range(-1, 2): q = qf + 2 * n * boxwidth c.stroke(path.line(q, 0, q, height), [*poslinestyle, color.rgb(0.6, 0, 0)]) for n in range(-1, 1): q = -qf + (2 * n + 2) * boxwidth c.stroke(path.line(q, 0, q, height), [*poslinestyle, color.rgb(0.6, 0, 0)]) for delta in (2 * (boxwidth - qf), -2 * qf): c.stroke( path.curve(qf, -0.1, qf + 0.3 * delta, -0.5, qf + 0.7 * delta, -0.5, qf + delta, -0.1), [deco.earrow]) for delta in (-4 * boxwidth + 2 * qf, 2 * qf): c.stroke( path.curve(2 * boxwidth - qf, height + 0.1, 2 * boxwidth - qf + 0.3 * delta, height + 0.5, 2 * boxwidth - qf + 0.7 * delta, height + 0.5, 2 * boxwidth - qf + delta, height + 0.1), [deco.earrow]) for n, q in enumerate( (qf, -qf, 2 * boxwidth - qf, -2 * boxwidth + qf, 2 * boxwidth + qf)): ypos = (n + 0.5) * height / 5 c.stroke( path.line(qi, ypos, q, ypos), [style.linewidth.Thick, color.rgb(0.2, 0, 0.8)]) c.stroke(path.circle(qi, ypos, 0.06), [style.linewidth.thick, linecolor, deco.filled([color.grey(1)])])
def draw_level_chain(): c = canvas.canvas() # levels circles # for r in 3, 8, 11: # circle = path.circle(11, 0, r) # intersect = (circle.intersect(path.line(0, 2.6, 11, 2.6))[0][0], circle.intersect(path.line(0, -2.2, 11, -2.1))[0][0]) # arc = circle.split(intersect)[1] # c.stroke(arc, [style.linestyle.dashed, style.linewidth.thin]) #states c.stroke(path.circle(0, 0, 0.4)) c.stroke(path.circle(3, 0, 0.4)) c.stroke(path.circle(8, 0, 0.4)) c.stroke(path.circle(11, 0, 0.4)) c.fill(path.circle(0, 0, 0.4), [color.rgb.white]) c.fill(path.circle(3, 0, 0.4), [color.rgb.white]) c.fill(path.circle(8, 0, 0.4), [color.rgb.white]) c.fill(path.circle(11, 0, 0.4), [color.rgb.black]) c.text(0, 0, r"0", [text.halign.boxcenter, text.valign.middle, text.size.huge]) c.text(3, 0, r"1", [text.halign.boxcenter, text.valign.middle, text.size.huge]) c.text(8, 0, r"$k - 1$", [text.size.small, text.halign.boxcenter, text.valign.middle]) #dots c.fill(path.circle(6, 0, 0.1), [color.rgb.black]) c.fill(path.circle(5, 0, 0.1), [color.rgb.black]) c.fill(path.circle(5.5, 0, 0.1), [color.rgb.black]) #transitions c.stroke(path.line(sqrt(0.15), 0.1, 3 - sqrt(0.15), 0.1), [deco.earrow()]) c.text(1.5, 0.1, r"$p_0^1$", [text.halign.boxcenter, text.valign.bottom]) c.stroke(path.line(3 - sqrt(0.15), -0.1, sqrt(0.15), -0.1), [deco.earrow()]) c.text(1.5, -0.1, r"$p_1^0$", [text.halign.boxcenter, text.valign.top]) c.stroke( path.curve(3 + sqrt(0.15), 0.1, 5, 0.4, 6, 0.4, 8 - sqrt(0.15), 0.1), [deco.arrow()]) c.text(5.5, 0.4, r"$p_1^{k - 1}$", [text.halign.boxcenter, text.valign.bottom]) c.stroke( path.curve(8 - sqrt(0.15), -0.1, 6, -0.4, 5, -0.4, 3 + sqrt(0.15), -0.1), [deco.arrow()]) c.text(5.5, -0.4, r"$p_{k - 1}^1$", [text.halign.boxcenter, text.valign.top]) c.stroke(path.line(8.4, 0, 10.6, 0), [deco.earrow()]) c.text(9.5, 0, r"$p_{k - 1}^k$", [text.halign.boxcenter, text.valign.bottom]) c.stroke(path.curve(0, 0.4, 3, 2.7, 8, 2.7, 11, 0.4), [deco.arrow()]) c.text(5.5, 2.2, r"$p_0^k$", [text.halign.boxcenter, text.valign.bottom]) c.stroke(path.curve(sqrt(0.07), 0.3, 3, 2, 5, 2, 8 - sqrt(0.07), 0.3), [deco.arrow()]) c.text(4.5, 1.6, r"$p_0^{k - 1}$", [text.halign.boxcenter, text.valign.bottom]) c.stroke(path.curve(8 - sqrt(0.12), 0.2, 5, 1.9, 3, 1.9, sqrt(0.12), 0.2), [deco.arrow()]) c.text(4.5, 1.4, r"$p_{k - 1}^0$", [text.halign.boxcenter, text.valign.top]) c.stroke( path.curve(3 + sqrt(0.07), -0.3, 6, -2, 9, -2, 11 - sqrt(0.07), -0.3), [deco.arrow()]) c.text(7, -1.7, r"$p_1^k$", [text.halign.boxcenter, text.valign.top]) c.stroke( path.curve(-sqrt(0.07), -0.3, -0.3, -1, 0.3, -1, sqrt(0.07), -0.3), [deco.earrow]) c.text(0, -1, r"$p_0^0$", [text.halign.boxcenter, text.valign.top]) c.stroke( path.curve(3 - sqrt(0.07), -0.3, 3 - 0.3, -1, 3.3, -1, 3 + sqrt(0.07), -0.3), [deco.earrow]) c.text(3, -1, r"$p_1^1$", [text.halign.boxcenter, text.valign.top]) c.stroke( path.curve(8 - sqrt(0.07), -0.3, 8 - 0.3, -1, 8.3, -1, 8 + sqrt(0.07), -0.3), [deco.earrow]) c.text(8, -1, r"$p_{k - 1}^{k - 1}$", [text.halign.boxcenter, text.valign.top]) c.writePDFfile("levels_chain.pdf")
def draw_leaky_chain(): c = canvas.canvas() x = 6 r = x / 6 pipe( sqrt(0.75) * r, r / 2, x / 3, r, 2 * x / 3, r, 19 / 24 * x, 0.65 * r, c, x) c.fill(arrow(x - sqrt(0.75) * r, r / 2, 19 / 24 * x, 0.65 * r), [color.rgb.black]) pipe(x - sqrt(0.75) * r, -r / 2, 2 * x / 3, -r, x / 3, -r, 5 / 24 * x, -0.65 * r, c, x) c.fill(arrow(sqrt(0.75) * r, -r / 2, 5 / 24 * x, -0.65 * r), [color.rgb.black]) pipe(x + sqrt(0.75) * r, r / 2, 1.5 * x, r, x * 1.5, -r, x + 5 / 4 * r, -2.3 / 4 * r, c, x) c.fill(arrow(x + sqrt(0.75) * r, -r / 2, x + 5 / 4 * r, -2.3 / 4 * r)) pipe(-sqrt(0.75) * r, -r / 2, -0.5 * x, -r, -x * 0.5, r, -5 / 4 * r, 2.3 / 4 * r, c, x) c.fill(arrow(-sqrt(0.75) * r, r / 2, -5 / 4 * r, 2.3 / 4 * r)) state(0, 0, r, c) state(x, 0, r, c) c.text(-x * 0.2, r, r"\Pr[0 \to 0]", [text.halign.boxright, text.mathmode, text.size.large]) c.text(x * 1.2, r, r"\Pr[1 \to 1]", [text.halign.boxleft, text.mathmode, text.size.large]) c.text(x * 0.5, 5 / 4 * r, r"\Pr[0 \to 1]", [ text.valign.bottom, text.halign.boxcenter, text.mathmode, text.size.large ]) c.text(x * 0.5, -5 / 4 * r, r"\Pr[1 \to 0]", [ text.valign.top, text.halign.boxcenter, text.mathmode, text.size.large ]) c.text(0, 0, r"0", [ color.rgb.white, text.halign.boxcenter, text.valign.middle, text.mathmode, text.size.Huge ]) c.text(x, 0, r"1", [ color.rgb.white, text.halign.boxcenter, text.valign.middle, text.mathmode, text.size.Huge ]) draw_drop(0, -5 / 4 * r, r / 4, c) draw_drop(x, -7 / 4 * r, r / 4, c) water = path.curve(-5/4 * r, -x/2, -5/4 * r + 17/72 * x, -x / 2 - x/48, -5/4 * r + 34/72 * x, -x/2 + x / 48, x/2, -x/2) << \ path.curve(x/2, -x/2, x/2 + 17/72 * x, -x/2 - x /48, x/2 + 34/72 * x, -x/2 + x/48, x + 5/4 * r, -x/2) << \ path.line(x + 5/4 * r, -x/2, x + 5/4 * r, -7/12 * x) << path.line(x + 5/4 * r, -7/12 * x, -5/4 * r, -7/12 * x) water.append(path.closepath()) c.fill(water, [color.cmyk.RoyalBlue]) c.stroke( path.line(-5 / 4 * r, -11 / 24 * x, -5 / 4 * r, -7 / 12 * x) << path.line(-5 / 4 * r, -7 / 12 * x, x + 5 / 4 * r, -7 / 12 * x) << path.line(x + 5 / 4 * r, -7 / 12 * x, x + 5 / 4 * r, -11 / 24 * x), [style.linewidth.THICK]) c.writePDFfile("leaky_chain.pdf")
dx = 2 dy = 0.8 c = canvas.canvas() for nx in range(3): for ny in range(3): c.text(nx*dx, -ny*dy, r'a[\textcolor{axis0}{%s}, \textcolor{axis1}{%s}]' % (ny, nx), [text.halign.center]) box = c.bbox() pd = 0.1 xoff = box.left()-pd pdx = 0.2 pdy = 0.5 c.stroke(path.curve(xoff, box.top()+pd, xoff-pdx, box.top()-pdy, xoff-pdx, box.bottom()+pdy, xoff, box.bottom()-pd)) xoff = box.right()+pd c.stroke(path.curve(xoff, box.top()+pd, xoff+pdx, box.top()-pdy, xoff+pdx, box.bottom()+pdy, xoff, box.bottom()-pd)) x = box.left()-pdx-0.4 c.stroke(path.line(x, box.top(), x, box.bottom()), [deco.earrow, color0]) c.text(x-0.1, 0.5*(box.top()+box.bottom()), 'axis 0', [text.halign.center, color0, trafo.rotate(90)]) y = box.top()+0.4 c.stroke(path.line(box.left(), y, box.right(), y), [deco.earrow, color1]) c.text(0.5*(box.left()+box.right()), y+0.1, 'axis 1', [text.halign.center, color1]) c.writePDFfile()
text.set(text.LatexRunner) text.preamble(r'\usepackage{arev}\usepackage[T1]{fontenc}') unit.set(xscale=1.3) c = canvas.canvas() pos = [(0, 1), (sin(2 * pi / 3), cos(2 * pi / 3)), (-sin(2 * pi / 3), cos(2 * pi / 3))] sfak = 1.5 for x, y in pos: c.insert(server(0.3), [trafo.translate(sfak * x, sfak * y)]) c.insert(client(), [trafo.scale(0.5).translated(3 * x, 3 * y + 0.15)]) c.stroke(path.line(2.7 * x, 2.7 * y, 1.9 * x, 1.9 * y), [ arrowcolor, deco.earrow.large, deco.barrow.large, style.linewidth.THick ]) for phi in (0, 120, 240): c.stroke( path.curve(-sfak * sin(2 * pi / 3) + 0.4, -0.5 * sfak + 0.15, -sfak * sin(2 * pi / 3) + 0.8, -0.5 * sfak + 0.35, sfak * sin(2 * pi / 3) - 0.8, -0.5 * sfak + 0.35, sfak * sin(2 * pi / 3) - 0.4, -0.5 * sfak + 0.15), [ arrowcolor, deco.earrow.large, deco.barrow.large, style.linewidth.THick, trafo.rotate(phi) ]) c.insert(server(0.5, color.hsb(0.5, 0.8, 0.5), 0.13)) c.text(0.8, 0.2, 'Gitlab / Github server', [color.hsb(0.5, 0.8, 0.5), text.size.small]) c.writePDFfile()