def write(size, color): size = size * 0.3 cwrite = canvas.canvas() p = path.path(path.moveto(-0.2, 0.8), path.lineto(0.2, 0.8), path.lineto(0.2, 0), path.lineto(0, -0.2), path.lineto(-0.2, 0), path.lineto(-0.2, 0.8), path.closepath(), path.moveto(0, 0.8), path.lineto(0, 0.05), path.moveto(-0.2, 0), path.arcn(-0.1, 0, 0.1, 180, 20), path.arcn(0.1, 0, 0.1, 160, 0)) cwrite.stroke( p, [color, trafo.scale(size).rotated(-30).translated(0, -0.4 * size)]) return cwrite
def draw_sector(self, end): """draw the sector""" segment = path.path( path.arc(self.xo, self.yo, self.inner_r, self.start_angle, self.end_angle), path.arcn(self.xo, self.yo, self.sector_width + self.inner_r, self.end_angle, self.start_angle), path.closepath()) self.shape_canvas.fill(segment, [self.sector_color]) # draw a delimiting line between sectors line_color = color.gray(0.15) if end and (self.end_angle - self.start_angle) < 0.25: line_color = color.rgb.red r = self.inner_r + self.sector_width start_radians = self.start_angle * pi / 180.0 end_radians = self.end_angle * pi / 180.0 x0 = self.inner_r * cos(start_radians) + self.xo y0 = self.inner_r * sin(start_radians) + self.yo x1 = r * cos(start_radians) + self.xo y1 = r * sin(start_radians) + self.yo self.shape_canvas.stroke(path.line(x0, y0, x1, y1), [style.linewidth(0.01), line_color]) x0 = self.inner_r * cos(end_radians) + self.xo y0 = self.inner_r * sin(end_radians) + self.yo x1 = r * cos(end_radians) + self.xo y1 = r * sin(end_radians) + self.yo self.shape_canvas.stroke(path.line(x0, y0, x1, y1), [style.linewidth(0.01), line_color])
def server(r, servercolor=color.rgb(0.5, 0.5, 0.8)): c = canvas.canvas() c.fill(path.circle(0, 0, r), [servercolor, trafo.scale(1, 0.5)]) h = 2 * r p = path.path(path.moveto(-r, 0), path.lineto(-r, -h), path.arc(0, -h, r, 180, 0), path.lineto(r, 0), path.arcn(0, 0, r, 0, 180), path.closepath()) c.fill(p, [servercolor, trafo.scale(1, 0.5).translated(0, -0.08 * r)]) return c
c.text(width, labelypos, '$L$', [text.halign.center]) for q, label in ((qi, r'$q_\text{i}$'), (qf, r'$q_\text{f}$')): c.stroke(path.line(q, 0, q, height), [style.linestyle.dashed]) c.text(q, labelypos, label, [text.halign.center]) pathsegments = [path.path(path.moveto(qi, 0), path.lineto(qf, 0)), path.path(path.moveto(qf, 0), path.lineto(width-radius, 0), path.arc(width-radius, radius, radius, -90, 90), path.lineto(qf, 2*radius)), path.path(path.moveto(qf, 0), path.lineto(qi, 0)), path.path(path.moveto(qi, 0), path.lineto(radius, 0), path.arcn(radius, radius, radius, 270, 90), path.lineto(qi, 2*radius))] anzahl_segmente = (1, 2, 2, 3) ypos = 0.5*dy for n in range(1, ntraj+1): offset = 0 if n % 2 == 0: offset = -1 nsegmente = anzahl_segmente[(n-1) % 4] + (n-1)//4*4 for nsegment in range(1, nsegmente+1): yshift = (-offset+nsegment-1)//2*2*radius c.stroke(pathsegments[(offset+nsegment-1) % 4], [trafo.translate(0, ypos+yshift), linecolor, style.linewidth.Thick]) c.stroke(path.circle(qi, ypos, 0.06), [style.linewidth.thick, linecolor, deco.filled([color.grey(1)])])
t.stroke(extra) t.stroke(extra+[deco.earrow()]) c = canvas.canvas() R = 1.7*r for i in range(3): theta = 2*i*pi/3 x, y = R*sin(theta), R*cos(theta) tetra(x, y, [1, 0, 2][i], reflect=(i in [0,1])) w = 30 + 120*i c.stroke(path.path(path.arc(0., 0., 1.1*R, w-20, w+20)), [deco.earrow()]) c.stroke(path.path(path.arcn(0., 0., 1.1*R, w+20, w-20)), [deco.earrow()]) theta = 2*(i+0.5)*pi/3 x, y = 1.3*R*sin(theta), 1.3*R*cos(theta) c.text(x, y, "$F$", center) c.writePDFfile("pic-fmove-relation.pdf") c = canvas.canvas() R = 1.7*r for i in range(3): theta = 2*i*pi/3 x, y = R*sin(theta), R*cos(theta) tetra(x, y, [2, 1, 0][i], reflect=(i in [0,2]))