def draw(self, x, y): width = 48 height = 48 sy = y + (draw.height() - height) / 2 draw.rect(x, sy, width, height, fill="#eeeeee") # Label if self.label is not None: draw.text(self.label, x + width / 2, sy + height + 10, center=True) if self.comment is not None: draw.text(self.comment, x + width / 2, sy + height + 20, center=True, italic=True, color="gray") # Attachment positions self.top_right = (x + width, sy) self.top_left = (x, sy) self.bot_left = (x, sy + height) self.bot_right = (x + width, sy + height) return width
def draw(self, x, y): big_rect = 32 small_rect = 24 sy = y + draw.mid() - 20 xp = x + 10 yp = sy # Big pool square for i in range(4): for j in range(4): f = "white" if (i + j) % 2 else "white" draw.rect(xp, yp, big_rect / 4, big_rect / 4, stroke="gray") xp += big_rect / 4 yp += big_rect / 4 xp = 10 + x xp = 10 + x + big_rect / 2.5 yp = sy + big_rect / 2.5 # Small pool square for i in range(2): for j in range(2): f = "white" if (i + j) % 2 else "#eeeeee" draw.rect(xp, yp, small_rect / 2, small_rect / 2, fill=f) xp += small_rect / 2 yp += small_rect / 2 xp = 10 + x + big_rect / 2.5 # Label if self.label is not None: draw.text(self.label, 10 + x + big_rect / 2 + 2, sy + 48, center=True) # Comment if self.comment is not None: draw.text(self.comment, 10 + x + big_rect / 2 + 2, sy + 58, center=True, italic=True, color="gray") # Attachment self.top_right = (x + big_rect + 10, sy) self.bot_right = (x + big_rect + 14, sy + big_rect + 5) self.center = (x + big_rect / 2, sy + big_rect / 2) return big_rect + small_rect * 0.25 + 20
def draw(self, x, y): w, h = draw.arrow(x, y + draw.mid()) self.left = (x, y + draw.mid()) self.right = (x + w, y + draw.mid()) if self.label is not None: draw.text(self.label, x + w / 2, y + draw.mid() + h / 2 + 12, center=True) if self.comment is not None: draw.text(self.comment, x + w / 2, y + draw.mid() + h / 2 + 22, center=True, italic=True, color="gray") return w
def _save(self, debug=False): self._step_draw_position = 0 self._draw(debug) if self.title is not None: draw.begin(self._figure) draw.title(self.title, self._PADDING, self._PADDING) draw.add_all(self._figure, 0) if self.author is not None: draw.begin(self._figure) draw.text(self.author, self._PADDING, self._PADDING + 10, color="gray", italic=True) draw.add_all(self._figure, 0) self._figure.width = self._width self._figure.height = self._height self._figure.viewbox(0, 0, self._width, self._height) self._figure.save()
def _draw(self, debug=False): # 256 by default, makes everything less than this appear smaller MAX_DENSE_NODES = 256 MAX_CONV_FILTERS = 1 for l in self.elements: if isinstance(l, element.Dense): MAX_DENSE_NODES = max(l.size, MAX_DENSE_NODES) if isinstance(l, element.Conv): MAX_CONV_FILTERS = max(l.size, MAX_CONV_FILTERS) DRAW_X = 0 DRAW_Y = 0 prev = None for l in self.elements: if isinstance(l, element.Padding): DRAW_X += l.width continue # Needs max nodes for relative sizes if isinstance(l, element.Dense): l.max_size = MAX_DENSE_NODES if isinstance(l, element.Conv): l.max_size = MAX_CONV_FILTERS w = l.draw(DRAW_X, DRAW_Y) if debug: draw.text(type(l).__name__, DRAW_X, DRAW_Y - 4, italic=True, color="red") draw.rect(DRAW_X - 1, DRAW_Y - 1, w + 2, draw.height() + 2, stroke="red", fill="none") if prev is not None: prev.attach(l) DRAW_X += w + self.SPACING prev = l if debug: draw.rect(-2, -2, DRAW_X + 4, draw.height() + 4, stroke="blue", fill="none") return DRAW_X
def draw(self, x, y): x += self.pad # Relative scale scale = self.size / self.max_size * 0.75 + 0.25 sy = y + draw.height() * (1 - scale) / 2 sx = x if self.simple: w, h = draw.rect(x + 4, sy, 8, draw.height() * scale) else: w, h = 16, draw.height() * scale n_nodes = int(draw.height() * scale / 8) if self.size <= 3: n_nodes = self.size offy = (h - n_nodes * 10) / 2 self.circle_positions = [] for i in range(n_nodes): draw.circle(x + 8, sy + i * 10 + 4 + offy, 4) self.circle_positions.append((x + 8, sy + i * 10 + 4 + offy)) sy += offy h -= offy - 1 sx += 6 x -= 2 if self.label is not None: draw.text(self.label, x + w / 2 + 2, sy + h + 10, center=True) if self.comment is not None: draw.text(self.comment, x + w / 2 + 2, sy + h + 20, center=True, italic=True, color="gray") if self.size_label: draw.text(str(self.size), x + w / 2 + 2, sy - 5, center=True, italic=True, color="gray") # Attachment positions self.top_left = (sx, sy) self.bot_left = (sx, sy + h) self.top_right = (sx + 12, sy) self.bot_right = (sx + 12, sy + h) return w + self.pad * 2
def draw(self, x, y): # Relative scale scale = self.size / self.max_size * 0.25 + 0.75 # Max 16 nodes in figure nodes = int(min(max(20 * scale, 1), 20)) if self.size <= 20: nodes = self.size width = nodes * 4 + 20 height = nodes * 4 + 20 sy = y + (draw.height() - height) / 2 for i in range(nodes): f = "#eeeeee" if not (i + nodes % 2) % 2 else "white" draw.rect(x + i * 4, sy + i * 4, 24, 24, fill=f) # Attachment positions self.top_left = (x, sy) self.top_right = (x + 24, sy) self.bot_left = (x + width - 24, sy + height) self.bot_right = (x + width, sy + height) self.center = (x + width / 2 - 18, sy + height / 2 + 4) # Label if self.label is not None: draw.text(self.label, x + width - 12, sy + height + 10, center=True) # Comment if self.comment is not None: draw.text(self.comment, x + width - 12, sy + height + 20, center=True, italic=True, color="gray") # Size label if self.size_label: # draw.line(x+24+8, sy, x+width, sy+height-24-8, stroke="gray") draw.text(str(self.size), x + width / 2 + 16, sy + height / 2 - 16, italic=True, color="gray") return width