Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWalter Bender <walter@sugarlabs.org>2014-02-18 12:37:31 (GMT)
committer Walter Bender <walter@sugarlabs.org>2014-02-18 12:37:31 (GMT)
commit2b550f18b8c12304fca1f7601a6e5a934990c000 (patch)
tree2a86625d3e9e4384eab0958f021024ee44abc75b
parent9a14783a85faaf4ed4a9ea281db8492b552872e7 (diff)
made 3d blocks a plugin
-rw-r--r--TurtleArt/tabasics.py29
-rw-r--r--TurtleArt/taconstants.py3
-rw-r--r--TurtleArt/taturtle.py24
-rw-r--r--plugins/threed/__init__.py0
-rw-r--r--plugins/threed/icons/turtleoff.svg97
-rw-r--r--plugins/threed/icons/turtleon.svg106
-rw-r--r--plugins/threed/threed.py88
7 files changed, 311 insertions, 36 deletions
diff --git a/TurtleArt/tabasics.py b/TurtleArt/tabasics.py
index 4254967..a7dbd5b 100644
--- a/TurtleArt/tabasics.py
+++ b/TurtleArt/tabasics.py
@@ -276,21 +276,6 @@ towards the top of the screen.)'))
call_afterwards=lambda value: self.after_set(
'heading', value)))
- palette.add_block('setxyz',
- style='basic-style-3arg',
- # TRANS: xyz are coordinates in a 3-dimensional space
- label=[_('set xyz') + '\n\n',
- _('x'), _('y'), _('z')],
- prim_name='setxyz',
- default=[0, 0, 0],
- help_string=_('sets the xyz-coordinates of the \
-turtle'))
- self.tw.lc.def_prim(
- 'setxyz', 3,
- Primitive(Turtle.set_xyz,
- arg_descs=[ArgSlot(TYPE_NUMBER), ArgSlot(TYPE_NUMBER),
- ArgSlot(TYPE_NUMBER)]))
-
palette.add_block('xcor',
style='box-style',
label=_('xcor'),
@@ -321,20 +306,6 @@ the turtle (can be used in place of a number block)'),
ConstantArg(Primitive(
self.tw.get_coord_scale))]))
- palette.add_block('zcor',
- style='box-style',
- label=_('zcor'),
- help_string=_('holds current z-coordinate value of \
-the turtle (can be used in place of a number block)'),
- value_block=True,
- prim_name='zcor')
- self.tw.lc.def_prim(
- 'zcor', 0,
- Primitive(Primitive.divide, return_type=TYPE_FLOAT,
- arg_descs=[ConstantArg(Primitive(Turtle.get_z)),
- ConstantArg(Primitive(
- self.tw.get_coord_scale))]))
-
palette.add_block('heading',
style='box-style',
label=_('heading'),
diff --git a/TurtleArt/taconstants.py b/TurtleArt/taconstants.py
index 0a3cc23..87616d6 100644
--- a/TurtleArt/taconstants.py
+++ b/TurtleArt/taconstants.py
@@ -273,7 +273,8 @@ CONSTANTS = {'leftpos': None, 'toppos': None, 'rightpos': None,
# Blocks that are expandable
EXPANDABLE_STYLE = ['boolean-style', 'compare-porch-style', 'compare-style',
'number-style-porch', 'number-style', 'basic-style-2arg',
- 'number-style-block', 'box-style-media']
+ 'number-style-block', 'box-style-media',
+ 'basic-style-3arg']
# These are defined in add_block based on block style
EXPANDABLE_FLOW = []
diff --git a/TurtleArt/taturtle.py b/TurtleArt/taturtle.py
index 08a896e..ccdd60b 100644
--- a/TurtleArt/taturtle.py
+++ b/TurtleArt/taturtle.py
@@ -141,8 +141,10 @@ class Turtles:
self._active_turtle.set_gray(100)
if self.turtle_window.coord_scale == 1:
self._active_turtle.set_pen_size(5)
+ self._active_turtle.set_z_scale = 100.
else:
self._active_turtle.set_pen_size(1)
+ self._active_turtle.set_z_scale = 20.
self._active_turtle.reset_shapes()
self._active_turtle.set_heading(0.0)
self._active_turtle.set_pen_state(False)
@@ -230,6 +232,7 @@ class Turtle:
self._x = 0.0
self._y = 0.0
self._z = 0.0
+ self._z_scale = 100.
self._heading = 0.0
self._half_width = 0
self._half_height = 0
@@ -355,6 +358,9 @@ class Turtle:
self._custom_shapes = False
self._calculate_sizes()
+ def set_z_scale(self, scale):
+ self._z_scale = scale
+
def set_heading(self, heading, share=True):
''' Set the turtle heading (one shape per 360/SHAPES degrees) '''
self._heading = heading
@@ -565,8 +571,8 @@ class Turtle:
old = self.get_xy()
if self._z > 0.0:
- old[0] = old[0] * ((self._z / 100.) + 1)
- old[1] = old[1] * ((self._z / 100.) + 1)
+ old[0] = old[0] * ((self._z / self._z_scale) + 1)
+ old[1] = old[1] * ((self._z / self._z_scale) + 1)
xcor = old[0] + scaled_distance * sin(self._heading * DEGTOR)
ycor = old[1] + scaled_distance * cos(self._heading * DEGTOR)
@@ -587,8 +593,8 @@ class Turtle:
self.set_xy(x, y, share, pendown)
def set_z(self, z, share=True, pendown=True):
- xcor = self._x * ((self._z / 100.) + 1)
- ycor = self._y * ((self._z / 100.) + 1)
+ xcor = self._x * ((self._z / self._z_scale) + 1)
+ ycor = self._y * ((self._z / self._z_scale) + 1)
self._z = z
self.set_xy(xcor, ycor, share, pendown)
@@ -602,8 +608,8 @@ class Turtle:
ycor = y * self._turtles.turtle_window.coord_scale
if not dragging and self._z > 0.0:
- xcor /= ((self._z / 100.) + 1)
- ycor /= ((self._z / 100.) + 1)
+ xcor /= ((self._z / self._z_scale) + 1)
+ ycor /= ((self._z / self._z_scale) + 1)
self._draw_line(old, (xcor, ycor), pendown)
self.move_turtle((xcor, ycor))
@@ -637,6 +643,9 @@ class Turtle:
r = -r
a = -a
pos = self.get_xy()
+ if self._z > 0.0:
+ pos[0] = pos[0] * ((self._z / self._z_scale) + 1)
+ pos[1] = pos[1] * ((self._z / self._z_scale) + 1)
cx = pos[0] + r * cos(self._heading * DEGTOR)
cy = pos[1] - r * sin(self._heading * DEGTOR)
if self._pen_state:
@@ -661,6 +670,9 @@ class Turtle:
r = -r
a = -a
pos = self.get_xy()
+ if self._z > 0.0:
+ pos[0] = pos[0] * ((self._z / self._z_scale) + 1)
+ pos[1] = pos[1] * ((self._z / self._z_scale) + 1)
cx = pos[0] - r * cos(self._heading * DEGTOR)
cy = pos[1] + r * sin(self._heading * DEGTOR)
if self._pen_state:
diff --git a/plugins/threed/__init__.py b/plugins/threed/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/plugins/threed/__init__.py
diff --git a/plugins/threed/icons/turtleoff.svg b/plugins/threed/icons/turtleoff.svg
new file mode 100644
index 0000000..9a70be3
--- /dev/null
+++ b/plugins/threed/icons/turtleoff.svg
@@ -0,0 +1,97 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- Created with Inkscape (http://www.inkscape.org/) -->
+
+<svg
+ xmlns:dc="http://purl.org/dc/elements/1.1/"
+ xmlns:cc="http://creativecommons.org/ns#"
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+ xmlns:svg="http://www.w3.org/2000/svg"
+ xmlns="http://www.w3.org/2000/svg"
+ version="1.0"
+ width="55"
+ height="55"
+ id="svg2">
+ <metadata
+ id="metadata3044">
+ <rdf:RDF>
+ <cc:Work
+ rdf:about="">
+ <dc:format>image/svg+xml</dc:format>
+ <dc:type
+ rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
+ <dc:title></dc:title>
+ </cc:Work>
+ </rdf:RDF>
+ </metadata>
+ <defs
+ id="defs5" />
+ <rect
+ width="45"
+ height="45"
+ x="5"
+ y="5"
+ id="rect2990"
+ style="fill:#282828;fill-opacity:1;stroke:none" />
+ <path
+ d="m 27.567493,45.252146 c -0.46948,0 -0.933016,-0.02903 -1.389761,-0.08296 l 1.178368,1.948634 1.161389,-1.918769 c -0.314968,0.02489 -0.629086,0.05309 -0.949996,0.05309 z"
+ id="path3003"
+ style="fill:none;stroke:#ffffff;stroke-width:1.20000005;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" />
+ <path
+ d="m 38.317981,14.929279 c -1.837168,0 -3.360217,1.289964 -3.68707,2.992219 1.578232,1.115757 2.934884,2.584076 3.968928,4.320343 1.939893,-0.142684 3.475677,-1.709721 3.475677,-3.641764 0,-2.027442 -1.682656,-3.670798 -3.757535,-3.670798 z"
+ id="path3007"
+ style="fill:#686868;fill-opacity:1;stroke:#ffffff;stroke-width:2.29999995;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" />
+ <path
+ d="m 38.787461,38.290488 c -1.039138,1.851575 -2.42805,3.426908 -4.072502,4.609029 0.442312,1.546298 1.878767,2.686942 3.603022,2.686942 2.07403,0 3.757535,-1.642527 3.757535,-3.669969 0,-1.870656 -1.437304,-3.397874 -3.288055,-3.626002 z"
+ id="path3009"
+ style="fill:#686868;fill-opacity:1;stroke:#ffffff;stroke-width:2.29999995;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" />
+ <path
+ d="m 16.340734,38.277215 c -1.912727,0.170889 -3.41625,1.724653 -3.41625,3.639275 0,2.026612 1.680958,3.669969 3.755837,3.669969 1.752271,0 3.212497,-1.177974 3.626793,-2.764091 -1.598607,-1.174655 -2.950165,-2.728419 -3.96638,-4.545153 z"
+ id="path3011"
+ style="fill:#686868;fill-opacity:1;stroke:#ffffff;stroke-width:2.29999995;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" />
+ <path
+ d="m 20.375881,18.007772 c -0.291196,-1.744563 -1.828678,-3.078493 -3.69556,-3.078493 -2.074879,0 -3.755837,1.643356 -3.755837,3.669968 0,1.97601 1.601155,3.575399 3.603872,3.655037 1.006876,-1.694789 2.319381,-3.139051 3.847525,-4.246512 z"
+ id="path3013"
+ style="fill:#686868;fill-opacity:1;stroke:#ffffff;stroke-width:2.29999995;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" />
+ <path
+ d="m 27.567493,15.62362 c 1.619832,0 3.164955,0.340948 4.599711,0.935742 0.629086,-0.892605 1.000085,-1.971862 1.000085,-3.138221 0,-3.058584 -2.537567,-5.5389654 -5.668563,-5.5389654 -3.130146,0 -5.667713,2.4803814 -5.667713,5.5389654 0,1.18461 0.383734,2.280457 1.032345,3.180529 1.463622,-0.62134 3.04525,-0.97805 4.704135,-0.97805 z"
+ id="path3015"
+ style="fill:#686868;fill-opacity:1;stroke:#ffffff;stroke-width:2.29999995;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" />
+ <g
+ transform="matrix(0.8489685,0,0,0.82955893,4.2234061,5.2018707)"
+ id="g3017"
+ style="fill:#686868;fill-opacity:1;stroke:#ffffff;stroke-width:1.42992032;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none">
+ <path
+ d="m 43.102,30.421 c 0,4.7344 -1.6452,9.2798 -4.5706,12.6275 -2.9254,3.3478 -6.8973,5.2305 -11.0344,5.2305 -4.1371,0 -8.109,-1.8827 -11.0344,-5.2305 -2.9254,-3.3477 -4.5706,-7.8931 -4.5706,-12.6275 0,-9.7966 7.0444,-17.858 15.605,-17.858 8.5606,0 15.605,8.0614 15.605,17.858 z"
+ id="path3019"
+ style="fill:#686868;fill-opacity:1;stroke:#ffffff;stroke-width:1.42992032;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" />
+ </g>
+ <g
+ transform="matrix(0.8489685,0,0,0.82955893,4.2234061,5.2018707)"
+ id="g3021"
+ style="fill:#ffffff;fill-opacity:1;stroke:none">
+ <path
+ d="m 25.875,33.75 -1.542,-4.625 3.164,-2.587 3.615,2.626 -1.487,4.669 z"
+ id="path3023"
+ style="fill:#ffffff;fill-opacity:1;stroke:none" />
+ <path
+ d="m 27.501,41.551 c -3.968,-0.16 -5.543,-2.009 -5.543,-2.009 l 3.57,-4.163 4.465,0.168 3.132,4.12 c 0,0 -2.89,1.994 -5.624,1.884 z"
+ id="path3025"
+ style="fill:#ffffff;fill-opacity:1;stroke:none" />
+ <path
+ d="m 18.453,33.843 c -0.849,-2.968 0.172,-6.884 0.172,-6.884 l 4,2.167 1.493,4.629 -3.582,4.233 c 0,-10e-4 -1.465,-1.99 -2.083,-4.145 z"
+ id="path3027"
+ style="fill:#ffffff;fill-opacity:1;stroke:none" />
+ <path
+ d="m 19.458,25.125 c 0,0 0.5,-1.958 3.039,-3.822 2.237,-1.643 4.465,-1.72 4.465,-1.72 l -0.037,4.981 -3.521,2.75 -3.946,-2.189 z"
+ id="path3029"
+ style="fill:#ffffff;fill-opacity:1;stroke:none" />
+ <path
+ d="M 32.084,27.834 28.625,24.959 29,19.75 c 0,0 1.834,-0.042 3.959,1.667 2.228,1.791 3.362,4.983 3.362,4.983 l -4.237,1.434 z"
+ id="path3031"
+ style="fill:#ffffff;fill-opacity:1;stroke:none" />
+ <path
+ d="m 31.292,34.042 1.313,-4.464 4.187,-1.536 c 0,0 0.677,2.663 -0.042,5.667 -0.54,2.256 -2.084,4.361 -2.084,4.361 l -3.374,-4.028 z"
+ id="path3033"
+ style="fill:#ffffff;fill-opacity:1;stroke:none" />
+ </g>
+</svg>
diff --git a/plugins/threed/icons/turtleon.svg b/plugins/threed/icons/turtleon.svg
new file mode 100644
index 0000000..4d955de
--- /dev/null
+++ b/plugins/threed/icons/turtleon.svg
@@ -0,0 +1,106 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- Created with Inkscape (http://www.inkscape.org/) -->
+
+<svg
+ xmlns:dc="http://purl.org/dc/elements/1.1/"
+ xmlns:cc="http://creativecommons.org/ns#"
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+ xmlns:svg="http://www.w3.org/2000/svg"
+ xmlns="http://www.w3.org/2000/svg"
+ version="1.0"
+ width="55"
+ height="55"
+ id="svg2">
+ <metadata
+ id="metadata3068">
+ <rdf:RDF>
+ <cc:Work
+ rdf:about="">
+ <dc:format>image/svg+xml</dc:format>
+ <dc:type
+ rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
+ <dc:title></dc:title>
+ </cc:Work>
+ </rdf:RDF>
+ </metadata>
+ <defs
+ id="defs5" />
+ <rect
+ width="55"
+ height="55"
+ rx="0"
+ x="0"
+ y="0"
+ id="rect2839"
+ style="fill:#ffd200;fill-opacity:1;fill-rule:evenodd;stroke:none" />
+ <g
+ id="g3854">
+ <path
+ d="m 27.567493,45.252146 c -0.46948,0 -0.933016,-0.02903 -1.389761,-0.08296 l 1.178368,1.948634 1.161389,-1.918769 c -0.314968,0.02489 -0.629086,0.05309 -0.949996,0.05309 z"
+ id="path3003"
+ style="fill:none;stroke:#00ff00;stroke-width:1.20000005;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" />
+ <g
+ transform="matrix(0.8489685,0,0,0.82955893,4.2234061,5.2018707)"
+ id="g3005"
+ style="fill:#00d000;fill-opacity:1;stroke:#00ff00;stroke-width:1.42992032;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none">
+ <path
+ d="m 40.16,11.726 c -2.164,0 -3.958,1.555 -4.343,3.607 1.859,1.345 3.457,3.115 4.675,5.208 2.285,-0.172 4.094,-2.061 4.094,-4.39 0,-2.444 -1.982,-4.425 -4.426,-4.425 z"
+ id="path3007"
+ style="fill:#00d000;fill-opacity:1;stroke:#00ff00;stroke-width:1.42992032;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" />
+ <path
+ d="m 40.713,39.887 c -1.224,2.232 -2.86,4.131 -4.797,5.556 0.521,1.864 2.213,3.239 4.244,3.239 2.443,0 4.426,-1.98 4.426,-4.424 0,-2.255 -1.693,-4.096 -3.873,-4.371 z"
+ id="path3009"
+ style="fill:#00d000;fill-opacity:1;stroke:#00ff00;stroke-width:1.42992032;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" />
+ <path
+ d="m 14.273,39.871 c -2.253,0.206 -4.024,2.079 -4.024,4.387 0,2.443 1.98,4.424 4.424,4.424 2.064,0 3.784,-1.42 4.272,-3.332 -1.883,-1.416 -3.475,-3.289 -4.672,-5.479 z"
+ id="path3011"
+ style="fill:#00d000;fill-opacity:1;stroke:#00ff00;stroke-width:1.42992032;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" />
+ <path
+ d="m 19.026,15.437 c -0.343,-2.103 -2.154,-3.711 -4.353,-3.711 -2.444,0 -4.424,1.981 -4.424,4.424 0,2.382 1.886,4.31 4.245,4.406 1.186,-2.043 2.732,-3.784 4.532,-5.119 z"
+ id="path3013"
+ style="fill:#00d000;fill-opacity:1;stroke:#00ff00;stroke-width:1.42992032;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" />
+ </g>
+ <path
+ d="m 27.567493,15.62362 c 1.619832,0 3.164955,0.340948 4.599711,0.935742 0.629086,-0.892605 1.000085,-1.971862 1.000085,-3.138221 0,-3.058584 -2.537567,-5.5389654 -5.668563,-5.5389654 -3.130146,0 -5.667713,2.4803814 -5.667713,5.5389654 0,1.18461 0.383734,2.280457 1.032345,3.180529 1.463622,-0.62134 3.04525,-0.97805 4.704135,-0.97805 z"
+ id="path3015"
+ style="fill:#00d000;fill-opacity:1;stroke:#00ff00;stroke-width:1.20000005;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" />
+ <g
+ transform="matrix(0.8489685,0,0,0.82955893,4.2234061,5.2018707)"
+ id="g3017"
+ style="fill:#00d000;fill-opacity:1;stroke:#00ff00;stroke-width:1.42992032;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none">
+ <path
+ d="m 43.102,30.421 c 0,4.7344 -1.6452,9.2798 -4.5706,12.6275 -2.9254,3.3478 -6.8973,5.2305 -11.0344,5.2305 -4.1371,0 -8.109,-1.8827 -11.0344,-5.2305 -2.9254,-3.3477 -4.5706,-7.8931 -4.5706,-12.6275 0,-9.7966 7.0444,-17.858 15.605,-17.858 8.5606,0 15.605,8.0614 15.605,17.858 z"
+ id="path3019"
+ style="fill:#00d000;fill-opacity:1;stroke:#00ff00;stroke-width:1.42992032;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" />
+ </g>
+ <g
+ transform="matrix(0.8489685,0,0,0.82955893,4.2234061,5.2018707)"
+ id="g3021"
+ style="fill:#00ff00;fill-opacity:1;stroke:none">
+ <path
+ d="m 25.875,33.75 -1.542,-4.625 3.164,-2.587 3.615,2.626 -1.487,4.669 z"
+ id="path3023"
+ style="fill:#00ff00;fill-opacity:1;stroke:none" />
+ <path
+ d="m 27.501,41.551 c -3.968,-0.16 -5.543,-2.009 -5.543,-2.009 l 3.57,-4.163 4.465,0.168 3.132,4.12 c 0,0 -2.89,1.994 -5.624,1.884 z"
+ id="path3025"
+ style="fill:#00ff00;fill-opacity:1;stroke:none" />
+ <path
+ d="m 18.453,33.843 c -0.849,-2.968 0.172,-6.884 0.172,-6.884 l 4,2.167 1.493,4.629 -3.582,4.233 c 0,-10e-4 -1.465,-1.99 -2.083,-4.145 z"
+ id="path3027"
+ style="fill:#00ff00;fill-opacity:1;stroke:none" />
+ <path
+ d="m 19.458,25.125 c 0,0 0.5,-1.958 3.039,-3.822 2.237,-1.643 4.465,-1.72 4.465,-1.72 l -0.037,4.981 -3.521,2.75 -3.946,-2.189 z"
+ id="path3029"
+ style="fill:#00ff00;fill-opacity:1;stroke:none" />
+ <path
+ d="M 32.084,27.834 28.625,24.959 29,19.75 c 0,0 1.834,-0.042 3.959,1.667 2.228,1.791 3.362,4.983 3.362,4.983 l -4.237,1.434 z"
+ id="path3031"
+ style="fill:#00ff00;fill-opacity:1;stroke:none" />
+ <path
+ d="m 31.292,34.042 1.313,-4.464 4.187,-1.536 c 0,0 0.677,2.663 -0.042,5.667 -0.54,2.256 -2.084,4.361 -2.084,4.361 l -3.374,-4.028 z"
+ id="path3033"
+ style="fill:#00ff00;fill-opacity:1;stroke:none" />
+ </g>
+ </g>
+</svg>
diff --git a/plugins/threed/threed.py b/plugins/threed/threed.py
new file mode 100644
index 0000000..7cb303b
--- /dev/null
+++ b/plugins/threed/threed.py
@@ -0,0 +1,88 @@
+# -*- coding: utf-8 -*-
+#Copyright (c) 2012, Walter Bender
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+from gettext import gettext as _
+
+from plugins.plugin import Plugin
+from TurtleArt.tapalette import make_palette
+from TurtleArt.taprimitive import (ArgSlot, ConstantArg, Primitive)
+from TurtleArt.tatype import (TYPE_FLOAT, TYPE_NUMBER)
+from TurtleArt.taturtle import Turtle
+
+
+class Threed(Plugin):
+ """ a class for defining the 3-D Turtle Blocks """
+
+ def __init__(self, turtle_window):
+ Plugin.__init__(self)
+ self.tw = turtle_window
+
+ def setup(self):
+ self._turtle_palette()
+
+ def _turtle_palette(self):
+ palette = make_palette('turtle',
+ colors=["#00FF00", "#00A000"],
+ help_string=_('Palette of turtle commands'),
+ translation=_('turtle'))
+
+ palette.add_block('zcor',
+ style='box-style',
+ label=_('zcor'),
+ help_string=_(
+ 'holds current z-coordinate value of the turtle '
+ '(can be used in place of a number block)'),
+ value_block=True,
+ prim_name='zcor')
+ self.tw.lc.def_prim(
+ 'zcor', 0,
+ Primitive(Primitive.divide, return_type=TYPE_FLOAT,
+ arg_descs=[ConstantArg(Primitive(Turtle.get_z)),
+ ConstantArg(Primitive(
+ self.tw.get_coord_scale))]))
+
+ palette.add_block('setxyz',
+ style='basic-style-3arg',
+ # TRANS: xyz are coordinates in a 3-dimensional space
+ label=[_('set xyz') + '\n\n',
+ _('x'), _('y'), _('z')],
+ prim_name='setxyz',
+ default=[0, 0, 0],
+ help_string=_('sets the xyz-coordinates of the '
+ 'turtle'))
+ self.tw.lc.def_prim(
+ 'setxyz', 3,
+ Primitive(Turtle.set_xyz,
+ arg_descs=[ArgSlot(TYPE_NUMBER), ArgSlot(TYPE_NUMBER),
+ ArgSlot(TYPE_NUMBER)],
+ call_afterwards=self.after_move))
+
+ def after_move(self, *ignored_args, **ignored_kwargs):
+ ''' Update labels after moving the turtle '''
+ if self.tw.lc.update_values:
+ self.tw.lc.update_label_value(
+ 'xcor',
+ self.tw.turtles.get_active_turtle().get_xy()[0] /
+ self.tw.coord_scale)
+ self.tw.lc.update_label_value(
+ 'ycor',
+ self.tw.turtles.get_active_turtle().get_xy()[1] /
+ self.tw.coord_scale)
+ self.tw.lc.update_label_value(
+ 'zcor',
+ self.tw.turtles.get_active_turtle().get_xyz()[2] /
+ self.tw.coord_scale)