From 6d682014baf524fe3a5630d08cb3c66ac93d68f3 Mon Sep 17 00:00:00 2001 From: Walter Bender Date: Sat, 28 Jul 2012 12:09:14 +0000 Subject: make button down block into a boolean --- (limited to 'TurtleArt') diff --git a/TurtleArt/tablock.py b/TurtleArt/tablock.py index 53c3e5c..2ead410 100644 --- a/TurtleArt/tablock.py +++ b/TurtleArt/tablock.py @@ -178,6 +178,7 @@ class Block: 'compare-porch-style': self._make_compare_porch_style, 'boolean-style': self._make_boolean_style, 'not-style': self._make_not_style, + 'boolean-block-style': self._make_boolean_block_style, 'clamp-style': self._make_clamp_style, 'clamp-style-collapsible': self._make_clamp_style_collapsible, 'clamp-style-collapsed': self._make_clamp_style_collapsed, @@ -871,12 +872,19 @@ class Block: def _make_not_style(self, svg): self.svg.expand(15 + self.dx + self.ex, self.ey) - self._make_block_graphics(svg, self.svg.boolean_not) + self._make_block_graphics(svg, self.svg.boolean_not, arg=False) self.docks = [['bool', True, self.svg.docks[0][0], self.svg.docks[0][1]], ['bool', False, self.svg.docks[1][0], self.svg.docks[1][1]]] + def _make_boolean_block_style(self, svg): + self.svg.expand(15 + self.dx + self.ex, self.ey) + self._make_block_graphics(svg, self.svg.boolean_not, arg=True) + self.docks = [['bool', True, self.svg.docks[0][0], + self.svg.docks[0][1]], + ['unavailable', False, 0, 0]] + def _make_clamp_style(self, svg, extend_x=0, extend_y=4): self.svg.expand(self.dx + self.ex + extend_x, self.ey + extend_y) self.svg.set_slot(True) diff --git a/TurtleArt/tapalette.py b/TurtleArt/tapalette.py index 7a44763..d2ee6bb 100644 --- a/TurtleArt/tapalette.py +++ b/TurtleArt/tapalette.py @@ -62,6 +62,7 @@ block_styles = {'basic-style': [], 'compare-porch-style': [], 'boolean-style': [], 'not-style': [], + 'boolean-block-style': [], 'flow-style-tail': [], 'clamp-style': [], 'clamp-style-collapsible': [], diff --git a/TurtleArt/tasprite_factory.py b/TurtleArt/tasprite_factory.py index 2c403b6..0cbe1cf 100755 --- a/TurtleArt/tasprite_factory.py +++ b/TurtleArt/tasprite_factory.py @@ -334,26 +334,43 @@ class SVG: self.margins[3] = int(self._stroke_width * self._scale) return self.header() + svg - def boolean_not(self): - ''' Booleans are in a class of their own ''' + def boolean_not(self, notnot): + ''' Booleans are in a class of their own: not and not not ''' self.reset_min_max() - svg = self._start_boolean(self._stroke_width / 2.0, self._radius * \ - 2.0 + self._stroke_width / 2.0) + if not notnot: + svg = self._start_boolean( + self._stroke_width / 2.0, + self._radius * 2.0 + self._stroke_width / 2.0) + else: + svg = self._start_boolean( + self._stroke_width / 2.0, + self._radius + self._stroke_width / 2.0) svg += self._rline_to(0, -self._stroke_width) - svg += self._rarc_to(1, -1) + if not notnot: + svg += self._rarc_to(1, -1) svg += self._rline_to(self._radius / 2.0 + self._expand_x, 0) xx = self._x - svg += self._rline_to(0, self._radius / 2.0) - svg += self._do_boolean() - svg += self._rline_to(0, self._radius / 2.0) + if not notnot: + svg += self._rline_to(0, self._radius / 2.0) + svg += self._do_boolean() + svg += self._rline_to(0, self._radius / 2.0) + else: + svg += self._rline_to(0, self._radius * 2) svg += self.line_to(xx, self._y) - svg += self._rline_to(-self._expand_x, 0) - svg += self._end_boolean() - self.margins[0] = int((self._radius + self._stroke_width + 0.5) * \ - self._scale) + if not notnot: + svg += self._rline_to(-self._expand_x, 0) + else: + svg += self._rline_to(-self._radius / 2.0 - self._expand_x, 0) + svg += self._end_boolean(notnot) + if notnot: + self.margins[0] = int((self._radius + self._stroke_width + 0.5) * \ + self._scale) + self.margins[2] = int((self._radius + self._stroke_width + 0.5) * \ + self._scale) + else: + self.margins[0] = int((self._stroke_width + 0.5) * self._scale) + self.margins[2] = int((self._stroke_width + 0.5) * self._scale) self.margins[1] = int(self._stroke_width * self._scale) - self.margins[2] = int((self._radius + self._stroke_width + 0.5) * \ - self._scale) self.margins[3] = int(self._stroke_width * self._scale) return self.header() + svg @@ -1105,8 +1122,11 @@ class SVG: svg = self._rarc_to(-1, 1, 90, 0, 0) + self._rarc_to(1, 1, 90, 0, 0) return svg - def _end_boolean(self): - svg = self._rline_to(-self._radius * 1.5, 0) + def _end_boolean(self, notnot=False): + if not notnot: + svg = self._rline_to(-self._radius * 1.5, 0) + else: + svg = '' svg += self._rline_to(0, -self._stroke_width) svg += self._rline_to(-self._stroke_width, 0) self._radius -= self._stroke_width @@ -1178,13 +1198,10 @@ def close_file(f): def generator(datapath): svg0 = SVG() - f = open_file(datapath, "clamp.svg") + f = open_file(datapath, "true.svg") svg0.set_scale(2) - svg0.set_arm(True) - svg0.expand(0, 0, 0, 21) - svg0.set_collapsible(True) - svg0.set_hide(True) - svg_str = svg0.clamp() + svg0.expand(30, 0, 0, 0) + svg_str = svg0.boolean_not(True) f.write(svg_str) close_file(f) -- cgit v0.9.1