Ejemplo n.º 1
0
def waning_moon(X, r, cx, cy) :
    '''draws a waning moon figure, used for moonrise.'''
    p = path.path(path.moveto(cx, cy+r))
    p.append(path.arc(cx, cy, r, 90, -90))
    if X>0.5 :
        R = R_of_S(X-0.5)*r
        theta = asin(r/R)*180/PI
        moon_arc_p = path.arc(cx-sqrt(R*R-r*r), cy, R, -theta, theta)
    else :
        R = R_of_S(0.5-X)*r
        theta = asin(r/R)*180/PI
        moon_arc_p = path.arc(cx+sqrt(R*R-r*r), cy, R, 180-theta, 180+theta)
        p = path.path.reversed(p)
    p.append(moon_arc_p)
    return p
Ejemplo n.º 2
0
    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])
Ejemplo n.º 3
0
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
Ejemplo n.º 4
0
def ucirc():
    x1, y1 = x-dx*r, y-r
    st_scale = [trafo.scale(x=x1, y=y1, sx=1., sy=sy)]

    c.fill(path.circle(x1, y1, 0.5*r0), st_scale+[shade0])
    c.stroke(path.path(path.arc(x1, y1, 0.5*r0, 180., 0.)), st_scale)
    x2, y2 = x1-0.5*dx*sy*r0, y1-0.5*sy*r0
    c.stroke(path.line(x, y, x2, y2))
    c.fill(path.circle(x2, y2, 0.05))
    c.text(x2-0.5*r0, y2-0.5*r0, "${c}$", southeast)
Ejemplo n.º 5
0
def draw_pie(c, radius, start, end):
    pie = path.path(path.moveto(0, 0), path.arc(0, 0, radius, start, end),
                    path.closepath())

    hue = (start + end) / (360 * 2)
    color = pyx.color.hsb(hue, 0.8, 0.8)

    c.stroke(
        pie,
        [style.linewidth(0.01),
         pyx.color.rgb(1, 1, 1),
         deco.filled([color])])
Ejemplo n.º 6
0
def test_pie(radius, start, end):
    c = canvas.canvas()
    container = path.rect(-(radius + 1), -(radius + 1), 2 * (radius + 1),
                          2 * (radius + 1))

    c.stroke(container, [style.linewidth(0.001), color.rgb.red])

    pie = path.path(path.moveto(0, 0), path.arc(0, 0, radius, start, end),
                    path.closepath())

    c.stroke(pie, [
        style.linewidth(0.1),
        pyx.color.rgb(1, 1, 1),
        deco.filled([color.rgb.red])
    ])
    c.writeSVGfile("figure")
Ejemplo n.º 7
0
def last_quarter_moon(r, cx, cy) :
    p = path.path(path.moveto(cx, cy))
    p.append(path.arc(cx, cy, r, 90, -90))
    p.append(path.closepath())
    return p
Ejemplo n.º 8
0
c.stroke(path.line(x, y+0.7*h, x+w, y+0.7*h), st_tau)

#c.stroke(path.line(x+0.3*w, y+0.05*h, x+0.4*w, y+0.35*h), st_vac)
c.stroke(path.line(x+0.5*w, y+0.3*h, x+0.5*w, y+0.7*h), st_vac)

x += 1.1*w
c.text(x, y+0.5*h, r"$= \phi^{-1}$", west)

x += 0.7*w
frame()
#c.stroke(path.line(x,   y+0.2*h, x+0.3*w, y+0.5*h), st_tau)
#c.stroke(path.line(x,   y+0.8*h, x+0.3*w, y+0.5*h), st_tau)
#c.stroke(path.line(x+w, y+0.2*h, x+0.7*w, y+0.5*h), st_tau)
#c.stroke(path.line(x+w, y+0.8*h, x+0.7*w, y+0.5*h), st_tau)
#c.stroke(path.circle(x+0.0*w, y+0.5*h, 0.3*w), st_tau)
c.stroke(path.path(path.arc(x+0.0*w, y+0.5*h, 0.2*w, -90, 90)), st_tau)
c.stroke(path.path(path.arc(x+1.0*w, y+0.5*h, 0.2*w, 90, -90)), st_tau)
c.stroke(path.line(x+0.2*w, y+0.5*h, x+0.8*w, y+0.5*h), st_vac)


x += 1.1*w
c.text(x, y+0.5*h, r"$+ \phi^{-\frac{1}{2}}$", west)

x += 0.7*w
frame()
#c.stroke(path.line(x,   y+0.2*h, x+0.3*w, y+0.5*h), st_tau)
#c.stroke(path.line(x,   y+0.8*h, x+0.3*w, y+0.5*h), st_tau)
#c.stroke(path.line(x+w, y+0.2*h, x+0.7*w, y+0.5*h), st_tau)
#c.stroke(path.line(x+w, y+0.8*h, x+0.7*w, y+0.5*h), st_tau)
#c.stroke(path.line(x+0.3*w, y+0.5*h, x+0.7*w, y+0.5*h), st_tau)
Ejemplo n.º 9
0
from math import atan, degrees
from pyx import canvas, color, path, style, text, unit

unit.set(xscale=0.8)
c = canvas.canvas()
c.fill(path.circle(0, 0, 0.1), [color.grey(0.5)])
c.fill(path.circle(2, 1, 0.1), [color.grey(0.5)])
c.stroke(path.line(0, 0, -1., -0.2),
         [style.linewidth.Thick, style.linestyle.dotted])
c.stroke(path.line(2, 1, 2.7, 1.7),
         [style.linewidth.Thick, style.linestyle.dotted])
c.stroke(path.line(0, 0, 2, 1), [style.linewidth.thick])
c.stroke(path.path(path.moveto(0, 0), path.lineto(2, 0), path.lineto(2, 1)))
c.text(0.5, 0.1, r'$\varphi$')
c.stroke(path.path(path.arc(0, 0, 0.8, 0, degrees(atan(0.5)))))
c.text(1, 0.6, r'$\ell=1$', [text.halign.right])
c.text(1, -0.1, r'$\cos(\varphi)$', [text.halign.center, text.valign.top])
c.text(2.1, 0.5, r'$\sin(\varphi)$', [text.valign.middle])
c.writeGSfile(device='pnggray', resolution=200)
Ejemplo n.º 10
0
r = 1.4

ccw = False # counter clockwise

surface(x+0, y, r, mark=True, orient=ccw)
surface(x-0.6*r, y, 0.2*r, fill=white, mark=True, orient=not ccw)
surface(x+0.6*r, y, 0.2*r, fill=white, mark=True, orient=not ccw)


#c.text(x-0.6*r, y+0.3*r, "$a_1$", south)
c.text(x, y, "...", center)
#c.text(x+0.6*r, y+0.3*r, "$a_n$", south)
#c.text(x+0.9*r, y-0.7*r, "$b$", north)

if ccw:
    c.stroke(path.path(path.arc(x+0.2*r, y-0.5*r, 0.15*r, 20, 330)), [deco.earrow()])
else:
    c.stroke(path.path(path.arc(x+0.2*r, y-0.5*r, 0.15*r, 20, 330)),
        [deco.earrow(), trafo.scale(x=x+0.2*r, y=y-0.5*r, sx=-1,sy=1)])

c.writePDFfile("pic-disc.pdf")


#############################################################################
#
#

w = 1.5
h = 1.5

x = 0
from pyx import canvas, color, 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.6, wscale=1.2)

c = canvas.canvas()
side = 4
lightcolor = color.hsb(0.65, 0.2, 1)
darkcolor = color.hsb(0.65, 1, 1)
c.fill(path.path(path.moveto(0, 0),
                 path.lineto(side, 0),
                 path.arc(0, 0, side, 0, 90),
                 path.closepath()), [lightcolor])
c.stroke(path.path(path.arc(0, 0, side, 0, 90)), [darkcolor])
c.stroke(path.rect(0, 0, side, side))
ticklen = 0.15
for tick in (0, 1):
    dist = tick*side
    c.stroke(path.line(dist, 0, dist, -ticklen))
    c.text(dist, -1.5*ticklen, str(tick), [text.halign.center, text.valign.top])
    c.stroke(path.line(0, dist, -ticklen, dist))
    c.text(-1.5*ticklen, dist, str(tick), [text.halign.right, text.valign.middle])
c.text(0.4*side, 0.4*side, r'\huge$\nicefrac{\pi}{4}$',
       [text.halign.center, text.valign.middle, darkcolor])
c.writePDFfile()
Ejemplo n.º 12
0
ks = []
for k in d.keys():
    if len(d[k]) > 1:
        #print k, d[k]
        ks.append(k)

ks.sort()
#for k in ks:
#    print k, d[k]

c = canvas.canvas()

m = 0.1
c.stroke(path.line(-m, 0., +m, 0.))
c.stroke(path.line(0., -m, 0., +m))

for k in ks:

    r = k**0.5
    #c.stroke(path.circle(0., 0., r))
    c.stroke(path.path(path.arc(0., 0., r, 45., 90)), [grey])

for k in ks:

    r = 0.1 * len(d[k]) - 0.1
    for x, y in d[k]:
        c.fill(path.circle(x, y, r), [green])

c.writePDFfile("pic-rational.pdf")
Ejemplo n.º 13
0
from pyx import canvas, color, path, text, unit

text.set(text.LatexRunner)
text.preamble(
    r'\usepackage{arev}\usepackage[T1]{fontenc}\usepackage{nicefrac}')
unit.set(xscale=1.2, wscale=1.2)

c = canvas.canvas()
side = 4
lightcolor = color.hsb(0.65, 0.2, 1)
darkcolor = color.hsb(0.65, 1, 1)
c.fill(
    path.path(path.moveto(0, 0), path.lineto(side, 0),
              path.arc(0, 0, side, 0, 90), path.closepath()), [lightcolor])
c.stroke(path.path(path.arc(0, 0, side, 0, 90)), [darkcolor])
c.stroke(path.rect(0, 0, side, side))
ticklen = 0.15
for tick in (0, 1):
    dist = tick * side
    c.stroke(path.line(dist, 0, dist, -ticklen))
    c.text(dist, -1.5 * ticklen, str(tick),
           [text.halign.center, text.valign.top])
    c.stroke(path.line(0, dist, -ticklen, dist))
    c.text(-1.5 * ticklen, dist, str(tick),
           [text.halign.right, text.valign.middle])
c.text(0.4 * side, 0.4 * side, r'\huge$\nicefrac{\pi}{4}$',
       [text.halign.center, text.valign.middle, darkcolor])
c.writePDFfile()
Ejemplo n.º 14
0
c.fill(path.rect(0, 0, width, height), [color.rgb(0.92, 1, 0.92)])
c.fill(path.rect(0, 0, -boxwidth, height), [boxcolor])
c.stroke(path.line(0, 0, 0, height), [style.linewidth.thick])
c.text(0, labelypos, '$0$', [text.halign.center])
c.fill(path.rect(width, 0, boxwidth, height), [boxcolor])
c.stroke(path.line(width, 0, width, height), [style.linewidth.thick])
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):
Ejemplo n.º 15
0
        t = Turtle(x1, y1-r1, -pi/2).right(pi, r1).fwd(s).right(pi, r1).fwd(s)
        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)
Ejemplo n.º 16
0
 def place(self, x, y):
     return (path.path(path.arc(x + self.r, y, self.r, 0, 180),
                       path.lineto(x + 2 * self.r,
                                   y)), self.color, self.stroke_color)
Ejemplo n.º 17
0
axislen = 3

text.set(engine=text.LatexEngine)
text.preamble(r'''\usepackage[sfdefault,scaled=.85]{FiraSans}
                  \usepackage{newtxsf}
                  \usepackage{nicefrac}''')
unit.set(vscale=1.2, wscale=1.3, xscale=1.3)
c = canvas.canvas()
c.stroke(path.line(-0.2*axislen, 0, axislen, 0), [deco.earrow])
c.text(axislen+0.1, 0, 'Re($x$)', [text.valign.middle])
c.stroke(path.line(0, -0.2*axislen, 0, axislen), [deco.earrow])
c.text(0.2, axislen, 'Im($x$)', [text.valign.top])
r = 0.85*axislen
p = path.path(path.moveto(0, 0),
              path.lineto(r, 0),
              path.arc(0, 0, r, 0, 45),
              path.lineto(0, 0),
              path.closepath())
pathcolor = color.rgb(0.2, 0, 0.8)
c.stroke(p, [style.linewidth.thick, style.linejoin.round, pathcolor])
c.stroke(path.line(0, 0, 0.53*axislen, 0), [deco.earrow, pathcolor])
c.stroke(path.path(path.arc(0, 0, r, 0, 23)), [deco.earrow, pathcolor])
c.stroke(path.path(path.moveto(r/sqrt(2), r/sqrt(2)),
                   path.lineto(0.48*r/sqrt(2), 0.48*r/sqrt(2))),
         [deco.earrow, pathcolor])
c.text(0.33, 0.11, r'\footnotesize$\nicefrac{\pi}{4}$', [pathcolor])
c.stroke(path.path(path.arc(0, 0, 0.82, 0, 45)),
         [style.linewidth.thin, pathcolor])

c.writePDFfile()
Ejemplo n.º 18
0
c = canvas.canvas()


x = 0.
y = 0.
m = 0.1*w
m0 = m/2
r = 0.3*w

c.fill(path.rect(x-m0, y-m0, 2*m0+w, 2*m0+h), [shade])
c.stroke(path.rect(x, y, w, h))

p = path.path(
    path.moveto(x+r, y-m), 
    path.lineto(x+r, y),
    path.arc(x, y, r, 0, 90),
    path.lineto(x-m, y+r), 
)
c.stroke(p, g_curve+[trafo.scale(1.0, 1.3, x=x, y=y-m)])

c.stroke(path.line(x+0.5*w, y-m, x+0.5*w, y+h+m), g_curve)

r = 0.2*w
p = path.path(
    path.moveto(x+w+m, y+0.5*h+r), 
    path.lineto(x+w, y+0.5*h+r), 
    path.arc(x+w, y+0.5*h, r, 90, 270),
    path.lineto(x+w+m, y+0.5*h-r), 
)
c.stroke(p, g_curve+[trafo.scale(1.4, 1.0, x=x+1.*w+m, y=y+0.5*h)])