def on_render(self, cvs, system): Box.on_render(self, cvs, system) Atom.on_render(self, cvs, system) n = self.n_top + self.n_bot if n == 0: return y = system[self.y] top = system[self.top] + PIP bot = system[self.bot] + PIP y_top = y + top y_bot = y - bot x_mid, y_mid = self.get_align("center") x0, y0 = system[x_mid], system[y_mid] x_top = [system[x] for x in self.x_top] x_bot = [system[x] for x in self.x_bot] x0 = (1. / n) * sum(x_top + x_bot) conv = lambda x0, x1, t: (1. - t) * x0 + t * x1 y3 = y_top for x3 in x_top: x2, y2 = x3, conv(y3, y0, 0.3) x1, y1 = conv(x0, x3, 0.7), conv(y3, y0, 0.7) cvs.stroke(path.curve(x0, y0, x1, y1, x2, y2, x3, y3)) y3 = y_bot for x3 in x_bot: x2, y2 = x3, conv(y3, y0, 0.3) x1, y1 = conv(x0, x3, 0.7), conv(y3, y0, 0.7) cvs.stroke(path.curve(x0, y0, x1, y1, x2, y2, x3, y3)) cvs.fill(path.circle(x0, y0, 0.04))
def on_layout(self, cvs, system): Box.on_layout(self, cvs, system) Atom.on_layout(self, cvs, system) x0 = self.x_top[0] x1 = self.x_top[1] system.add(x0 == self.llx + (1. / 4) * self.width, weight=self.weight) system.add(x1 == self.llx + (3. / 4) * self.width, weight=self.weight) system.add(2 * self.height >= x1 - x0)
def on_render(self, cvs, system): Box.on_render(self, cvs, system) Atom.on_render(self, cvs, system) x = system[self.x] y = system[self.y] top = system[self.top] + PIP bot = system[self.bot] + PIP x0 = system[self.x_bot[0]] cvs.stroke(path.line(x0, y - bot, x0, y + top))
def on_render(self, cvs, system): Box.on_render(self, cvs, system) Atom.on_render(self, cvs, system) y = system[self.y] top = system[self.top] + PIP bot = system[self.bot] y0 = y + top x0 = system[self.x_top[0]] x1 = system[self.x_top[1]] x2 = 0.5 * (x0 + x1) radius = 0.5 * (x1 - x0) cvs.stroke(path.arc(x2, y0, radius, pi, 0.))
def on_render(self, cvs, system): Box.on_render(self, cvs, system) Atom.on_render(self, cvs, system) y = system[self.y] top = system[self.top] bot = system[self.bot] + PIP y0 = y - bot x0 = system[self.x_bot[0]] x1 = system[self.x_bot[1]] x2 = 0.5 * (x0 + x1) radius = 0.5 * (x1 - x0) cvs.stroke(path.arc(x2, y0, radius, 0., pi))
def on_layout(self, cvs, system): Box.on_layout(self, cvs, system) Atom.on_layout(self, cvs, system) width = self.width llx = self.llx n_top = self.n_top x_top = self.x_top if n_top > 0: dx = width / (2 * n_top) x = llx + dx for i in range(n_top): system.add(x_top[i] == x, weight=self.weight) x += 2 * dx n_bot = self.n_bot x_bot = self.x_bot if n_bot > 0: dx = width / (2 * n_bot) x = llx + dx for i in range(n_bot): system.add(x_bot[i] == x, weight=self.weight) x += 2 * dx
def on_render(self, cvs, system): Box.on_render(self, cvs, system) Atom.on_render(self, cvs, system)
def on_layout(self, cvs, system): Box.on_layout(self, cvs, system) Atom.on_layout(self, cvs, system) system.add(self.x_bot[0] == self.x_top[0]) x = 0.5 * (self.llx + self.urx) system.add(self.x_bot[0] == x, 1.0)