def Detector(e=P(0, 0), height=1.0, label=None): """ Detector @param height: height of detector @type height: float @param label: detector label @type label: string """ if label is not None: return Group(Path(e - P(0, height / 2.0), e + P(0, height / 2.0)), Circle(c=e, r=height / 2.0, start=0, end=180), label) else: return Group(Path(e - P(0, height / 2.0), e + P(0, height / 2.0)), Circle(c=e, r=height / 2.0, start=0, end=180))
def __init__(self, **options): # intitialise base class Group.__init__(self, **options) self.sep = 0.25 self.width = 1.0 self.angle = 0.0 self.pinLength = 0.5 self.fg = Color(0) self.bg = Color(1) # process the options if any self.sep = options.get("sep", self.sep) self.width = options.get("width", self.width) self.angle = options.get("angle", self.angle) self.pinLength = options.get("pinLength", self.pinLength) self.fg = options.get("fg", self.fg) self.bg = options.get("bg", self.bg) pinIn = Group( Path( P(0, 0), P(self.pinLength, 0), ) ) cap = Group( Path(pinIn.e+P(0, -self.width/2.0), pinIn.e+P(0, self.width/2.0)), Path(pinIn.e+P(self.sep, -self.width/2.0), pinIn.e+P(self.sep, self.width/2.0)), ) pinOut = Path( cap.e, cap.e+P(self.pinLength, 0)) # group the objects together obj = Group(pinIn, pinOut, cap) # apply the colours obj.apply(fg=self.fg, bg=self.bg) # rotate if necessary if self.angle != 0.0: obj.rotate(self.angle, p=obj.c) # set the object to myself self.append(obj)
def __init__(self, **options): # initialise the base class Gate.__init__(self, **options) # process the options if any self.height = options.get("height", self.height) self.width = options.get("width", self.width) self.angle = options.get("angle", self.angle) self.pinLength = options.get("pinLength", self.pinLength) self.fg = options.get("fg", self.fg) self.bg = options.get("bg", self.bg) # now draw the gate pl = self.pinLength pinEdgeDist = 0.1*self.height pinBackDist = -0.08*self.width bodyHeight = self.height bodyWidth = self.width - 2.0*pl rad = 0.1 gateBody = Group( Path( P(-pinBackDist, -pinEdgeDist), C(90, 225), P(1.25*bodyWidth, bodyHeight/2.0), C(-45, 90), P(-pinBackDist, bodyHeight+pinEdgeDist), C(140, 40), closed=1, ) ) gatePinIn1 = Path( P(0, bodyHeight-pinEdgeDist), P(pl, bodyHeight-pinEdgeDist)) gatePinIn2 = Path( P(0, pinEdgeDist), P(pl, pinEdgeDist)) gatePinOut = Group( Circle(w=gateBody.e, r=rad), Path( gateBody.e+P(0.2, 0), gateBody.e+P(pl+0.2, 0)), ) # collect the objects together obj = Group(gateBody, gatePinIn1, gatePinIn2, gatePinOut) # apply the colours obj.apply(fg=self.fg, bg=self.bg) # rotate if necessary if self.angle != 0.0: obj.rotate(self.angle, p=obj.c) # nwo set the object to myself self.append(obj)
def __init__(self, text, **options): Group.__init__(self, **options) # set up tex width ... this relies on latex notion of # a point being accurate ... adjust for tex_scale too width_pp = int(self.width / float(self.iscale) * defaults.units) t = TeX(r'\begin{minipage}{%dpt}%s\end{minipage}' % (width_pp, text), fg=self.fg, iscale=self.iscale) # use this for alignment as the latex bounding box may be smaller # than the full width a = Area(width=self.width, height=0) Align(t, a, a1=self.align, a2=self.align, space=0) self.append(a, t)
def ZGate(c=P(0, 0), side=0.5): """ Z gate @param side: length of the box side @type side: float """ return Group(Rectangle(width=side, height=side, c=c, bg=Color("white")), TeX(r'Z', c=c))
def Cnot(c=P(0, 0), targetDist=1.0, direction="up"): """ Controlled NOT gate @param targetDist: distance to the target rail @type targetDist: float @param direction: in which direction is the target rail? up/down @type direction: string """ if direction is "up": return Group(Circle(r=0.06, bg=Color("black"), c=c), Circle(r=0.2, c=c + P(0, targetDist)), Path(c, c + P(0, targetDist + 0.2))) elif direction is "down": return Group(Circle(r=0.06, bg=Color("black"), c=c), Circle(r=0.2, c=c + P(0, -targetDist)), Path(c, c + P(0, -targetDist - 0.2)))
def __init__(self, **options): # initialise the base class Gate.__init__(self, **options) # process the options if any self.height = options.get("height", self.height) self.width = options.get("width", self.width) self.angle = options.get("angle", self.angle) self.pinLength = options.get("pinLength", self.pinLength) self.fg = options.get("fg", self.fg) self.bg = options.get("bg", self.bg) # now draw the gate buff = 0.0 pinEdgeDist = 0.1*self.height pl = self.pinLength bodyHeight = self.height bodyWidth = self.width - 2.0*pl rad = 0.1 gateBody = Group( Path( P(pl, buff+0), P(pl, buff+bodyHeight), P(pl+bodyWidth/2., buff+bodyHeight)), Circle(c=P(pl+bodyWidth/2., buff+bodyHeight/2.), r=bodyHeight/2., start=0, end=180), Path( P(pl+bodyWidth/2., buff+0), P(pl, buff+0))) gatePinIn1 = Path( P(0, bodyHeight-pinEdgeDist), P(pl, bodyHeight-pinEdgeDist)) gatePinIn2 = Path( P(0, pinEdgeDist), P(pl, pinEdgeDist)) gatePinOut = Group( Circle(c=P(bodyWidth+pl+rad, bodyHeight/2.), r=rad), Path( P(bodyWidth+pl+2.*rad, bodyHeight/2.), P(bodyWidth+2.*rad+2.*pl, bodyHeight/2.))) # collect the objects together obj = Group(gateBody, gatePinIn1, gatePinIn2, gatePinOut) # apply the colours obj.apply(fg=self.fg, bg=self.bg) # rotate if necessary if self.angle != 0.0: obj.rotate(self.angle, p=obj.c) # now set the object to myself self.append(obj)
def __init__(self, **options): # inherit from the base class Group.__init__(self, **options) # process the options if any self.fg = options.get("fg", self.fg) self.bg = options.get("bg", self.bg) self.height = options.get("height", self.height) self.thickness = options.get("thickness", self.thickness) self.angle = options.get("angle", self.angle) self.type = options.get("type", self.type) # determine what type of lens to make if self.type == "convex": leftCurveAngle = -30 rightCurveAngle = -30 elif self.type == "concave": leftCurveAngle = 30 rightCurveAngle = 30 else: print "Unknown lens type, defaulting to concave" leftCurveAngle = 30 rightCurveAngle = 30 # make the lens lens = Group() lens.append( Path( P(0, 0), C(leftCurveAngle, 180 - leftCurveAngle), P(0, self.height), P(self.thickness, self.height), C(-180 + rightCurveAngle, -rightCurveAngle), P(self.thickness, 0), closed=1, fg=self.fg, bg=self.bg, )) # rotate if necessary lens.rotate(self.angle, p=lens.bbox().c) self.append(lens)
def __init__(self, **options): # intitialise base class Group.__init__(self, **options) self.length = 3.0 self.width = 1.0 self.angle = 0.0 self.pinLength = 0.5 self.fg = Color(0) self.bg = Color(1) # process the options if any self.length = options.get("length", self.length) self.width = options.get("width", self.width) self.angle = options.get("angle", self.angle) self.pinLength = options.get("pinLength", self.pinLength) self.fg = options.get("fg", self.fg) self.bg = options.get("bg", self.bg) pinIn = Group( Path( P(0, 0), P(self.pinLength, 0) ) ) resistor = Rectangle(w=pinIn.e, width=self.length, height=self.width) pinOut = Path( resistor.e, resistor.e+P(self.pinLength, 0)) # collect the objects together obj = Group(pinIn, pinOut, resistor) # apply the colours obj.apply(fg=self.fg, bg=self.bg) # rotate if necessary if self.angle != 0.0: obj.rotate(self.angle, p=obj.c) # return object to myself self.append(obj)
def background(self): ''' Return background for poster ''' area = self.area() signature = Text( 'Created with PyScript. http://pyscript.sourceforge.net', size=14, fg=Color(1)) signature.se = area.se + P(-.5, .5) return Group( Rectangle(width=area.width, height=area.height, fg=None, bg=self.bg), signature, )
def detector(**options): ''' @return: a D shaped detector ''' r = 0.3 c = 0.65 * r path = [ P(0, -r), P(0, r), C(P(c, r), P(r, c)), P(r, 0), C(P(r, -c), P(c, -r)), P(0, -r) ] options['bg'] = options.get('bg', Color(.8)) options['closed'] = 1 p = apply(Path, path, options) a = Area(width=r, height=2 * r, e=P(0, 0)) return Group(a, p)
def classicalpath(*paths): ''' @param paths: 1 or more Path() objects @return: classical path ''' g = Group() for path in paths: g.append(path.copy(linewidth=2, fg=Color(0))) # reuse these paths for path in paths: g.append(path(linewidth=1, fg=Color(1))) return g
def cbox(obj, x, yt, yc): ''' @param obj: the object to put a box around @type obj: object @param x: x position of line and centre of box @type x: float @param yt: y position of target @type yt: float @param yc: y position of control @type yc: float @return: a controlled box ''' g = Group( Path(P(x, yt), P(x, yc)), Boxed(obj, c=P(x, yt), bg=Color(1)), Dot(P(x, yc)), ) return g
def __init__(self, **options): # inherit from the base class Group.__init__(self, **options) # process the options if any self.fg = options.get("fg", self.fg) self.bg = options.get("bg", self.bg) self.height = options.get("height", self.height) self.width = options.get("width", self.width) self.angle = options.get("angle", self.angle) # make the modulator modulator = Group() modulator.append( Path( P(0, 0), P(0, self.height), P(self.width, self.height), P(self.width, 0), closed=1, fg=self.fg, bg=self.bg, )) modulator.append( Path( P(0, -self.buf), P(self.width, -self.buf), fg=self.fg, bg=self.bg, )) modulator.append( Path( P(0, self.height + self.buf), P(self.width, self.height + self.buf), fg=self.fg, bg=self.bg, )) # rotate if necessary modulator.rotate(self.angle, p=modulator.bbox().c) self.append(modulator)
def __init__(self, **options): Group.__init__(self, **options) p = Group() self.fg = options.get("fg", self.fg) self.bg = options.get("bg", self.bg) if self.width > self.height: p.append( Path(P(0, 0), P(0, self.height), P(self.width - self.height / 2.0, self.height), C(90, 0), P(self.width, self.height / 2.0), C(180, 90), P(self.width - self.height / 2.0, 0), fg=self.fg, bg=self.bg, closed=1)) else: p.append( Path(P(0, 0), P(0, self.height), C(90, 0), P(self.width, self.height / 2.0), C(180, 90), closed=1)) # rotate if necessary self.angle = options.get("angle", self.angle) p.rotate(self.angle, p=p.bbox().c) self.append(p)
def __init__(self, **options): # inherit from the base class Group.__init__(self, **options) # process the options if any self.fg = options.get("fg", self.fg) self.bg = options.get("bg", self.bg) self.length = options.get("length", self.length) self.thickness = options.get("thickness", self.thickness) self.angle = options.get("angle", self.thickness) self.flicks = options.get("flicks", self.flicks) # make the mirror itself mirror = Group() mirror.append( Path(P(0, 0), P(0, self.length), P(self.thickness, self.length), P(self.thickness, 0), closed=1, fg=self.fg, bg=self.bg)) if self.flicks: # make the flicks on the back of the mirror flickLen = 0.15 flicksObj = Group() for i in range(10): flicksObj.append( Path(P((i + 1.0) * self.length / 10.0, self.thickness), P(i * self.length / 10.0, self.thickness + flickLen), fg=self.fg, bg=self.bg)) mirror.append(flicksObj) # rotate the mirror if necessary if self.angle != 0.0: mirror.rotate(self.angle, p=mirror.bbox().c) # make the mirror the current object self.append(mirror)