ColabTurtlePlus 2.1.0__tar.gz → 2.1.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -32,7 +32,16 @@ Fixed Python 3.13+ SyntaxWarning by using raw strings in regular expressions.
32
32
 
33
33
  v2.1.0 September 2026
34
34
  Added register_shape() (alias addshape) to mimic the role of the function register_shape() from Python's turtle.
35
- This only works to add a polygonal shape. It does not work with images or components.
35
+ This only works to add a polygonal shape (and now component shapes with v2.1.1). It does not work with images.
36
+
37
+ v2.1.1 September 2026
38
+ Added addcomponent() to create new polygonal turtles. Because turtles are defined as svg strings, also added two
39
+ new functions, addellipsecomponent() and addpathcomponent, to create turtles bassed on ellipical shapes and svg
40
+ paths. To be consistent with Python's turtle, these are first invoked using a call to Shape("compound") and then
41
+ combined using register_shape().
42
+
43
+ v2.1.2 September 2026
44
+ Fixed an issue introduced with register_shape when two or more turtles had the same shape.
36
45
  """
37
46
 
38
47
  DEFAULT_WINDOW_SIZE = (800, 600)
@@ -94,7 +103,7 @@ TURTLE_RING_SVG_TEMPLATE = """<g id="ring" visibility="{visibility}" transform="
94
103
  <polygon points="0,5 5,0 -5,0" transform="skewX({sk}) scale({sx},{sy})" style="fill:{turtle_color};stroke:{pcolor};stroke-width:1" />
95
104
  </g>"""
96
105
  TURTLE_CLASSIC_SVG_TEMPLATE = """<g id="classic" visibility="{visibility}" transform="rotate({degrees},{rotation_x},{rotation_y}) translate({turtle_x}, {turtle_y})">
97
- <polygon points="{points}" transform="skewX({sk}) scale({sx},{sy})" style="stroke:{pcolor};fill:{turtle_color};stroke-width:{pw}" />
106
+ <polygon points="-5,-4.5 0,-2.5 5,-4.5 0,4.5" transform="skewX({sk}) scale({sx},{sy})" style="stroke:{pcolor};fill:{turtle_color};stroke-width:{pw}" />
98
107
  </g>"""
99
108
  TURTLE_ARROW_SVG_TEMPLATE = """<g id="arrow" visibility="{visibility}" transform="rotate({degrees},{rotation_x},{rotation_y}) translate({turtle_x}, {turtle_y})">
100
109
  <polygon points="-10,-5 0,5 10,-5" transform="skewX({sk}) scale({sx},{sy})" style="stroke:{pcolor};fill:{turtle_color};stroke-width:{pw}" />
@@ -115,6 +124,18 @@ TURTLE_USER_SVG_TEMPLATE = """<g id="{id}" visibility="{visibility}" transform="
115
124
  <polygon points="{points}" transform="skewX({sk}) scale({sx},{sy})" style="stroke:{pcolor};fill:{turtle_color};stroke-width:{pw}" />
116
125
  </g>"""
117
126
 
127
+ TURTLE_COMPONENT_SVG_TEMPLATE = """<g id="user" visibility="{visibility}" transform="rotate({degrees},{rotation_x},{rotation_y}) translate({turtle_x}, {turtle_y})">
128
+ "{component}"
129
+ </g>"""
130
+
131
+ POLY_TEMPLATE = """<polygon points="{points}" transform="skewX({sk})
132
+ scale({sx},{sy})" style="stroke:{pcolor};fill:{turtle_color};stroke-width:{pw}" />"""
133
+ ELLIPSE_TEMPLATE = """<ellipse transform="skewX({sk}) scale({sx},{sy})"
134
+ style="stroke:{pcolor};fill:{turtle_color};stroke-width:{pw}" rx="{rx}" ry ="{ry}" cx="{cx}" cy="{cy}" />"""
135
+ PATH_TEMPLATE = """<path d="{path}" style="stroke:{pcolor};fill-rule:evenodd;fill:{turtle_color};fill-opacity:1;"
136
+ transform="skewX({sk}) scale({sx},{sy})" />"""
137
+
138
+
118
139
  SPEED_TO_SEC_MAP = {0: 0, 1: 1.0, 2: 0.8, 3: 0.5, 4: 0.3, 5: 0.25, 6: 0.20, 7: 0.15, 8: 0.125, 9: 0.10, 10: 0.08, 11: 0.04, 12: 0.02, 13: 0.005}
119
140
 
120
141
  shapeDict = {"turtle":TURTLE_TURTLE_SVG_TEMPLATE,
@@ -125,18 +146,8 @@ shapeDict = {"turtle":TURTLE_TURTLE_SVG_TEMPLATE,
125
146
  "triangle":TURTLE_TRIANGLE_SVG_TEMPLATE,
126
147
  "circle":TURTLE_CIRCLE_SVG_TEMPLATE,
127
148
  "turtle2":TURTLE_TURTLE2_SVG_TEMPLATE,
128
- "user":TURTLE_USER_SVG_TEMPLATE,
129
- "blank":""}
130
- pointsDict = {"turtle":"",
131
- "ring":"",
132
- "classic":"",
133
- "arrow":"",
134
- "square":"",
135
- "triangle":"",
136
- "circle":"",
137
- "turtle2":"",
138
- "user":"",
139
149
  "blank":""}
150
+
140
151
  #------------------------------------------------------------------------------------------------
141
152
 
142
153
  def Screen():
@@ -194,9 +205,9 @@ class _Screen:
194
205
 
195
206
  turtle_x = turtle.turtle_pos[0]
196
207
  turtle_y = turtle.turtle_pos[1]
197
- if self._mode == "standard":
208
+ if self._mode == 'standard':
198
209
  degrees = turtle.turtle_degree - turtle.tilt_angle
199
- elif self._mode == "world":
210
+ elif self._mode == 'world':
200
211
  degrees = turtle.turtle_orient - turtle.tilt_angle
201
212
  else:
202
213
  degrees = turtle.turtle_degree + turtle.tilt_angle
@@ -206,17 +217,18 @@ class _Screen:
206
217
  elif turtle.turtle_shape == 'ring':
207
218
  turtle_y += 10*turtle.stretchfactor[1]+4
208
219
  degrees -= 90
209
- else:
220
+ else: #turtle.turtle_shape in {'classic', 'arrow', 'square', 'triangle', 'circle', 'turtle2', 'blank'}:
210
221
  degrees -= 90
222
+
211
223
 
212
- svg = shapeDict[turtle.turtle_shape].format(
224
+ svg = turtle.shapeDict[turtle.turtle_shape].format(
213
225
  turtle_color=turtle.fill_color,
214
226
  pcolor=turtle.pen_color,
215
227
  turtle_x=turtle_x,
216
228
  turtle_y=turtle_y,
217
229
  visibility=vis,
218
230
  degrees=degrees,
219
- sx=turtle.stretchfactor[0],
231
+ sx=-turtle.stretchfactor[0],
220
232
  sy=turtle.stretchfactor[1],
221
233
  sk=turtle.shear_factor,
222
234
  rx=10*turtle.stretchfactor[0],
@@ -225,7 +237,6 @@ class _Screen:
225
237
  pw = turtle.outline_width,
226
238
  rotation_x=turtle.turtle_pos[0],
227
239
  rotation_y=turtle.turtle_pos[1],
228
- points=pointsDict[turtle.turtle_shape],
229
240
  id = turtle.turtle_shape)
230
241
  return svg
231
242
 
@@ -345,25 +356,25 @@ class _Screen:
345
356
  text_file.write(output)
346
357
  text_file.close()
347
358
 
348
- def register_shape(self, name, points=None):
349
- """Adds a polygonal turtle shape to to the shape list.
359
+ def register_shape(self, name, shape=None):
360
+ """Adds a turtle shape to to the shape list.
350
361
 
351
362
  Arg:
352
363
  name is an arbitrary string
353
- points is a list or tuple of pairs of coordinates that define the polygon.
364
+ points is a list or tuple of pairs of coordinates that define a polygon,
365
+ or a (compound) Shape object
354
366
 
355
- Installs the corresponding polygon shape.
367
+ Installs the corresponding polygon shape or the corresponding compound shape.
356
368
  If no points are given, the turtle shape will be blank.
357
- Note: This version does NOT include shapes that are images or components.
369
+ Note: This version does NOT include shapes that are images
358
370
  """
359
371
 
360
372
  if not isinstance(name,str):
361
373
  raise TypeError("The name must be a string")
362
- if points is None:
374
+ if shape is None:
363
375
  self.points = None
364
- else:
365
- if not isinstance(points, (list, tuple)):
366
- raise TypeError("The points must be a list or tuple of coordinate pairs.")
376
+ elif isinstance(shape, (list, tuple)):
377
+ points = shape
367
378
  if len(points) < 2:
368
379
  raise ValueError("The points must contain at least 2 coordinate pairs.")
369
380
  for i, point in enumerate(points):
@@ -379,10 +390,25 @@ class _Screen:
379
390
  raise TypeError(
380
391
  f"The point[{i}] must contain numeric coordinates."
381
392
  )
382
- name = name.lower()
383
- VALID_TURTLE_SHAPES.add(name)
384
- pointsDict[name] = " ".join(f"{x},{y}" for x, y in points)
385
- shapeDict[name] = TURTLE_USER_SVG_TEMPLATE
393
+ name = name.lower()
394
+ VALID_TURTLE_SHAPES.add(name)
395
+ pointstr = " ".join(f"{x},{y}" for x, y in points)
396
+ shapeDict[name] = TURTLE_USER_SVG_TEMPLATE.replace("{points}",pointstr) #TURTLE_USER_SVG_TEMPLATE
397
+ else: #assume compound shape
398
+ tmp=TURTLE_COMPONENT_SVG_TEMPLATE.format(
399
+ component=shape._data,
400
+ visibility="{visibility}",
401
+ degrees="{degrees}",
402
+ rotation_x="{rotation_x}",
403
+ rotation_y="{rotation_y}",
404
+ turtle_x="{turtle_x}",
405
+ turtle_y="{turtle_y}",
406
+ )
407
+ name = name.lower()
408
+ VALID_TURTLE_SHAPES.add(name)
409
+ shapeDict[name] = tmp
410
+ for turtle in self._turtles:
411
+ turtle.shapeDict = shapeDict.copy()
386
412
  addshape=register_shape
387
413
 
388
414
  #=========================
@@ -793,7 +819,7 @@ class _Screen:
793
819
  mode: (optional) one of "standard, "logo", "world", or "sv
794
820
 
795
821
  The defaults are (800,600) and "standard".
796
- """
822
+ """
797
823
  if window is not None:
798
824
  if not (isinstance(window, tuple) and len(window) == 2 and isinstance(
799
825
  window[0], int) and isinstance(window[1], int)):
@@ -847,7 +873,109 @@ class _Screen:
847
873
  err = 'The color parameter ' + color + ' must be a color string or a tuple'
848
874
  raise ValueError(err)
849
875
 
876
+ #----------------------------------------------------------------------------------------------
877
+ class Shape(object):
878
+ def __init__(self, type_, data=None):
879
+ self._type = type_
880
+ if type_ == "compound":
881
+ data = ""
882
+ self._data = data
850
883
 
884
+
885
+ def addcomponent(self, points, fill=None, outline=None):
886
+ """Add polygonal component to a shape of type compound.
887
+
888
+ Arguments: poly is a polygon, i. e. a tuple of number pairs.
889
+ fill is the fillcolor of the polygon,
890
+ outline is the outline color of the polygon.
891
+
892
+ Example:
893
+ >>> poly = ((0,0),(10,-5),(0,10),(-10,-5))
894
+ >>> s = Shape("compound")
895
+ >>> s.addcomponent(poly, "red", "blue")
896
+ >>> # .. add more components and then use register_shape()
897
+ """
898
+
899
+ tmp = self._data
900
+ p = " ".join(f"{x},{y}" for x, y in points)
901
+ template = POLY_TEMPLATE.replace("{points}",p) + "\n"
902
+ if fill is not None:
903
+ template = template.replace("{turtle_color}",fill)
904
+ if outline is None:
905
+ template = template.replace("{pcolor}",fill)
906
+ else:
907
+ template = template.replace("{pcolor}", outline)
908
+ elif outline is not None:
909
+ template = template.replace("{pcolor}",outline)
910
+ self._data = tmp + template
911
+
912
+ def addellipsecomponent(self, center, radii, fill=None, outline=None):
913
+ """Add elliptical component to a shape of type compound.
914
+
915
+ Arguments: center is a tuple (cx,cy) that is the center of the ellipse
916
+ radii is a tuple (rx, ry) giving the radius of the ellipse in the x and y directions.
917
+ Can use just radii = r as a substitute for (r,r) to do a circle of radius r
918
+ fill is the fillcolor of the ellipse,
919
+ outline is the outline color of the ellipse.
920
+
921
+ Example:
922
+ >>> s = Shape("compound")
923
+ >>> s.addellipsecomponent((0,0), (50,100), "red", "blue")
924
+ >>> # .. add more components and then use register_shape()
925
+ """
926
+ tmp = self._data
927
+ if isinstance(radii, (float,int)):
928
+ xradius = radii
929
+ yradius = radii
930
+ elif isinstance(radii, tuple):
931
+ xradius = radii[0]
932
+ yradius = radii[1]
933
+ replacements = {
934
+ "{cx}": str(center[0]),
935
+ "{cy}": str(center[1]),
936
+ "{rx}": str(xradius),
937
+ "{ry}": str(yradius)
938
+ }
939
+ pattern = re.compile("|".join(re.escape(key) for key in replacements.keys()))
940
+ template = pattern.sub(lambda match: replacements[match.group(0)], ELLIPSE_TEMPLATE)
941
+ if fill is not None:
942
+ template = template.replace("{turtle_color}",fill)
943
+ if outline is None:
944
+ template = template.replace("{pcolor}",fill)
945
+ else:
946
+ template = template.replace("{pcolor}", outline)
947
+ elif outline is not None:
948
+ template = template.replace("{pcolor}",outline)
949
+ self._data = tmp + template + "\n"
950
+
951
+ def addpathcomponent(self, path, fill=None, outline=None):
952
+ """Add an SVG path component to a shape of type compound.
953
+
954
+ Arguments: path is an SVG string defining a path
955
+ fill is the fillcolor of the component,
956
+ outline is the outline color of the component.
957
+
958
+ Example:
959
+ >>> curve = "M -50 -50 Q 0 100 50 -50" (quadratic Bezier curve)
960
+ >>> s = Shape("compound")
961
+ >>> s.addpathcomponent(curve, "red", "blue")
962
+ >>> # .. add more components and then use register_shape()
963
+ """
964
+ tmp = self._data
965
+ template = PATH_TEMPLATE.replace("{path}",path)
966
+ if fill is not None:
967
+ template = template.replace("{turtle_color}",fill)
968
+ if outline is None:
969
+ template = template.replace("{pcolor}",fill)
970
+ else:
971
+ template = template.replace("{pcolor}", outline)
972
+ elif outline is not None:
973
+ template = template.replace("{pcolor}",outline)
974
+ self._data = tmp + template + "\n"
975
+
976
+ addEllipseComponet = addellipsecomponent
977
+ addPathComponent = addpathcomponent
978
+ #-------------------------------------------------------------
851
979
 
852
980
  #----------------------------------------------------------------------------------------------
853
981
 
@@ -895,8 +1023,8 @@ class RawTurtle:
895
1023
  self.stampnum = 0
896
1024
  self.stamplist=[]
897
1025
  self.points = DEFAULT_POINTS
898
-
899
- if screen._mode == "svg": shapeDict.update({"circle":TURTLE_RING_SVG_TEMPLATE})
1026
+ self.shapeDict = shapeDict.copy()
1027
+ if screen._mode == "svg": self.shapeDict.update({"circle":TURTLE_RING_SVG_TEMPLATE})
900
1028
  screen._add(self)
901
1029
 
902
1030
 
@@ -972,10 +1100,10 @@ class RawTurtle:
972
1100
  self.screen._updateDrawing(turtle=self)
973
1101
  elif self.turtle_shape != 'ring' and self.stretchfactor[0]==self.stretchfactor[1]:
974
1102
  stretchfactor_orig = self.stretchfactor
975
- template = shapeDict[self.turtle_shape]
1103
+ template = self.shapeDict[self.turtle_shape]
976
1104
  tmp = """<animateTransform id = "one" attributeName="transform"
977
1105
  type="scale"
978
- from="1 1" to="{sx} {sy}"
1106
+ from="{sx} {sy}" to="{sx} {sy}"
979
1107
  begin="0s" dur="0.01s"
980
1108
  repeatCount="1"
981
1109
  additive="sum"
@@ -989,13 +1117,13 @@ class RawTurtle:
989
1117
  fill="freeze"
990
1118
  /></g>""".format(extent=deg, t=self.timeout*abs(deg)/90, sx=self.stretchfactor[0], sy=self.stretchfactor[1])
991
1119
  newtemplate = template.replace("</g>",tmp)
992
- shapeDict.update({self.turtle_shape:newtemplate})
1120
+ self.shapeDict.update({self.turtle_shape:newtemplate})
993
1121
  self.stretchfactor = 1,1
994
1122
  self.timeout = self.timeout*abs(deg)/90+0.001
995
- #self.screen._updateDrawing(self)
1123
+ self.screen._updateDrawing(self)
996
1124
  self.turtle_degree = (self.turtle_degree + deg) % 360
997
1125
  self.turtle_orient = self._turtleOrientation()
998
- shapeDict.update({self.turtle_shape:template})
1126
+ self.shapeDict.update({self.turtle_shape:template})
999
1127
  self.stretchfactor = stretchfactor_orig
1000
1128
  self.timeout = timeout_orig
1001
1129
  else: #_turtle_shape == 'ring' or _stretchfactor[0] != _stretchfactor[1]
@@ -1647,6 +1775,19 @@ class RawTurtle:
1647
1775
  deg = math.degrees(math.atan2(-Dxy[1],Dxy[0])) % 360
1648
1776
  return 360-deg
1649
1777
 
1778
+ def extract_points(self):
1779
+ svg_string = self.shapeDict[self.turtle_shape]
1780
+ match = re.search(r'points="([^"]*)"', svg_string)
1781
+ if not match:
1782
+ raise ValueError("No points attribute found")
1783
+ def number(s):
1784
+ value = float(s)
1785
+ return int(value) if value.is_integer() else value
1786
+ return tuple(
1787
+ (number(x), number(y))
1788
+ for x, y in (point.split(",") for point in match.group(1).split())
1789
+ )
1790
+
1650
1791
  #========================================
1651
1792
  # Turtle Motion - Setting and Measurement
1652
1793
  #========================================
@@ -1922,6 +2063,7 @@ class RawTurtle:
1922
2063
 
1923
2064
  return self.is_filling
1924
2065
 
2066
+
1925
2067
  # Initialize the string for the svg path of the filled shape.
1926
2068
  # Modified from aronma/ColabTurtle_2 github repo
1927
2069
  # The current _svg_lines_string is stored to be used when the fill is finished because the svg_fill_string will include
@@ -2241,7 +2383,8 @@ class RawTurtle:
2241
2383
  outline = self.outline_width
2242
2384
  elif not isinstance(outline, (int,float)):
2243
2385
  raise ValueError('The outline must be a positive number.')
2244
- self.outline_width = outline
2386
+ self.outline_width = outline
2387
+ self.screen._updateDrawing(turtle=self, delay=False)
2245
2388
  turtlesize = shapesize #alias
2246
2389
 
2247
2390
  # Set or return the current shearfactor. Shear the turtleshape according to the given shearfactor shear, which is the tangent of the shear angle.
@@ -2449,9 +2592,11 @@ _tg_screen_functions = ['addshape', 'bgcolor', 'clearscreen', 'drawline', 'hideb
2449
2592
  'initializescreen','initializeTurtle', 'showSVG', 'saveSVG', 'line', 'mode', 'register_shape', 'resetscreen', 'setup',
2450
2593
  'setworldcoordinates', 'showborder', 'turtles', 'window_width', 'window_height' ]
2451
2594
 
2595
+ _tg_shape_functions = ['addcomponent', 'addellipsecomponent', 'addpathcomponent']
2596
+
2452
2597
  _tg_turtle_functions = ['animationOff', 'animationOn', 'bk', 'back', 'backward', 'begin_fill',
2453
2598
  'circle', 'clear', 'clearstamp', 'clearstamps', 'color', 'degrees', 'delay', 'distance', 'done',
2454
- 'dot', 'down', 'end_fill', 'face', 'fd', 'fillcolor', 'filling', 'fillopacity', 'fillrule', 'forward',
2599
+ 'dot', 'down', 'end_fill', 'extract_points', 'face', 'fd', 'fillcolor', 'filling', 'fillopacity', 'fillrule', 'forward',
2455
2600
  'getheading', 'getx', 'gety', 'goto', 'heading', 'hideturtle', 'home', 'ht', 'isdown',
2456
2601
  'isvisible', 'jumpto', 'left', 'lt', 'pd', 'pen', 'pencolor', 'pensize', 'pendown', 'penup', 'pos',
2457
2602
  'position', 'pu', 'radians', 'regularPolygon', 'reset', 'right', 'rt', 'setheading', 'seth',
@@ -2514,7 +2659,6 @@ def _screen_docrevise(docstr):
2514
2659
  newdocstr = parexp.sub(":", newdocstr)
2515
2660
  return newdocstr
2516
2661
 
2517
-
2518
2662
  __func_body = """\
2519
2663
  def {name}{paramslist}:
2520
2664
  if {obj} is None:
@@ -2540,3 +2684,4 @@ _make_global_funcs(_tg_screen_functions, _Screen, 'Turtle._screen', 'Screen()',_
2540
2684
 
2541
2685
 
2542
2686
 
2687
+
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ColabTurtlePlus
3
- Version: 2.1.0
3
+ Version: 2.1.2
4
4
  Summary: An HTML based Turtle implementation with classes for Google Colab and Jupyter Labs
5
5
  Home-page: https://github.com/mathriddle/ColabTurtlePlus
6
6
  Author: Larry Riddle
@@ -35,7 +35,11 @@ To use multiple turtles on a screen one has to use the object-oriented interface
35
35
 
36
36
  What's New:
37
37
  ----
38
- Sept. 2026: Version 2.1.0 adds a register_shape (alias addshape) function to create a polygonal turtle shape. It does not work with images or components.
38
+ Sept. 2026: Version 2.1.0 adds a register_shape (alias addshape) function to create a polygonal turtle shape. It does not work with images.
39
+
40
+ Sept. 2026: Version 2.1.1 allows use of addcomponent() to add a polygon to a component turtle shape. There are two new ways to build additional components: addellipsecomponent() adds an elliptical shape, and addpathcompenent adds a path defined using svg path commands.
41
+
42
+ Sept. 2026: Version 2.1.2. Bug fix when multiple turtles have the same shape.
39
43
 
40
44
  Installation
41
45
  ----
@@ -57,7 +61,6 @@ Example 1
57
61
  ---
58
62
  This example uses the procedure-oriented interface.
59
63
  ```
60
- from ColabTurtlePlus.Turtle import *
61
64
  clearscreen()
62
65
  setup(300,300)
63
66
  showborder()
@@ -81,7 +84,6 @@ Example 2
81
84
  ----
82
85
  This example has two turtles and uses the object-oriented interface.
83
86
  ```
84
- from ColabTurtlePlus.Turtle import *
85
87
  clearscreen()
86
88
  setup(500,300)
87
89
  T = Turtle()
@@ -109,6 +111,48 @@ S.end_fill()
109
111
  The resulting image is
110
112
  ![](https://github.com/mathriddle/ColabTurtlePlus/raw/main/stars.svg)
111
113
 
114
+ Example 3:
115
+ ----
116
+ This example uses components.
117
+ ```
118
+ clearscreen()
119
+ setup(300,300)
120
+
121
+ comp_shape = Shape("compound")
122
+ poly = ((-50,0),(-50,100),(50,100),(50,0))
123
+ comp_shape.addcomponent(poly,"blue")
124
+ comp_shape.addellipsecomponent((0,120),50,"red")
125
+
126
+ star_coords = ((-10,-13.8), (0,17), (10,-13.8), (-16.2,5.3), (16.2,5.3))
127
+
128
+ addshape("box_with_ball", comp_shape)
129
+ addshape("star", star_coords)
130
+
131
+ t = Turtle()
132
+ t.shapesize(0.5,0.5)
133
+ t.fillcolor("yellow")
134
+ t.shapesize(0.25)
135
+ t.shape("box_with_ball")
136
+ t.pensize(2)
137
+ t.speed(5)
138
+ t.begin_fill()
139
+
140
+ for _ in range(4):
141
+ t.forward(100)
142
+ t.left(90)
143
+ t.end_fill()
144
+ t.forward(100)
145
+ t.left(90)
146
+
147
+ s = Turtle()
148
+ s.shapesize(1.5)
149
+ s.shape("star")
150
+ s.circle(-50)
151
+ s.color("black","green")
152
+ ```
153
+ The resulting image is
154
+ ![](https://github.com/mathriddle/ColabTurtlePlus/raw/main/example3.svg)
155
+
112
156
  Main differences with ColabTurtle
113
157
  ----
114
158
  This version implements classes.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ColabTurtlePlus
3
- Version: 2.1.0
3
+ Version: 2.1.2
4
4
  Summary: An HTML based Turtle implementation with classes for Google Colab and Jupyter Labs
5
5
  Home-page: https://github.com/mathriddle/ColabTurtlePlus
6
6
  Author: Larry Riddle
@@ -35,7 +35,11 @@ To use multiple turtles on a screen one has to use the object-oriented interface
35
35
 
36
36
  What's New:
37
37
  ----
38
- Sept. 2026: Version 2.1.0 adds a register_shape (alias addshape) function to create a polygonal turtle shape. It does not work with images or components.
38
+ Sept. 2026: Version 2.1.0 adds a register_shape (alias addshape) function to create a polygonal turtle shape. It does not work with images.
39
+
40
+ Sept. 2026: Version 2.1.1 allows use of addcomponent() to add a polygon to a component turtle shape. There are two new ways to build additional components: addellipsecomponent() adds an elliptical shape, and addpathcompenent adds a path defined using svg path commands.
41
+
42
+ Sept. 2026: Version 2.1.2. Bug fix when multiple turtles have the same shape.
39
43
 
40
44
  Installation
41
45
  ----
@@ -57,7 +61,6 @@ Example 1
57
61
  ---
58
62
  This example uses the procedure-oriented interface.
59
63
  ```
60
- from ColabTurtlePlus.Turtle import *
61
64
  clearscreen()
62
65
  setup(300,300)
63
66
  showborder()
@@ -81,7 +84,6 @@ Example 2
81
84
  ----
82
85
  This example has two turtles and uses the object-oriented interface.
83
86
  ```
84
- from ColabTurtlePlus.Turtle import *
85
87
  clearscreen()
86
88
  setup(500,300)
87
89
  T = Turtle()
@@ -109,6 +111,48 @@ S.end_fill()
109
111
  The resulting image is
110
112
  ![](https://github.com/mathriddle/ColabTurtlePlus/raw/main/stars.svg)
111
113
 
114
+ Example 3:
115
+ ----
116
+ This example uses components.
117
+ ```
118
+ clearscreen()
119
+ setup(300,300)
120
+
121
+ comp_shape = Shape("compound")
122
+ poly = ((-50,0),(-50,100),(50,100),(50,0))
123
+ comp_shape.addcomponent(poly,"blue")
124
+ comp_shape.addellipsecomponent((0,120),50,"red")
125
+
126
+ star_coords = ((-10,-13.8), (0,17), (10,-13.8), (-16.2,5.3), (16.2,5.3))
127
+
128
+ addshape("box_with_ball", comp_shape)
129
+ addshape("star", star_coords)
130
+
131
+ t = Turtle()
132
+ t.shapesize(0.5,0.5)
133
+ t.fillcolor("yellow")
134
+ t.shapesize(0.25)
135
+ t.shape("box_with_ball")
136
+ t.pensize(2)
137
+ t.speed(5)
138
+ t.begin_fill()
139
+
140
+ for _ in range(4):
141
+ t.forward(100)
142
+ t.left(90)
143
+ t.end_fill()
144
+ t.forward(100)
145
+ t.left(90)
146
+
147
+ s = Turtle()
148
+ s.shapesize(1.5)
149
+ s.shape("star")
150
+ s.circle(-50)
151
+ s.color("black","green")
152
+ ```
153
+ The resulting image is
154
+ ![](https://github.com/mathriddle/ColabTurtlePlus/raw/main/example3.svg)
155
+
112
156
  Main differences with ColabTurtle
113
157
  ----
114
158
  This version implements classes.
@@ -10,7 +10,11 @@ To use multiple turtles on a screen one has to use the object-oriented interface
10
10
 
11
11
  What's New:
12
12
  ----
13
- Sept. 2026: Version 2.1.0 adds a register_shape (alias addshape) function to create a polygonal turtle shape. It does not work with images or components.
13
+ Sept. 2026: Version 2.1.0 adds a register_shape (alias addshape) function to create a polygonal turtle shape. It does not work with images.
14
+
15
+ Sept. 2026: Version 2.1.1 allows use of addcomponent() to add a polygon to a component turtle shape. There are two new ways to build additional components: addellipsecomponent() adds an elliptical shape, and addpathcompenent adds a path defined using svg path commands.
16
+
17
+ Sept. 2026: Version 2.1.2. Bug fix when multiple turtles have the same shape.
14
18
 
15
19
  Installation
16
20
  ----
@@ -32,7 +36,6 @@ Example 1
32
36
  ---
33
37
  This example uses the procedure-oriented interface.
34
38
  ```
35
- from ColabTurtlePlus.Turtle import *
36
39
  clearscreen()
37
40
  setup(300,300)
38
41
  showborder()
@@ -56,7 +59,6 @@ Example 2
56
59
  ----
57
60
  This example has two turtles and uses the object-oriented interface.
58
61
  ```
59
- from ColabTurtlePlus.Turtle import *
60
62
  clearscreen()
61
63
  setup(500,300)
62
64
  T = Turtle()
@@ -84,6 +86,48 @@ S.end_fill()
84
86
  The resulting image is
85
87
  ![](https://github.com/mathriddle/ColabTurtlePlus/raw/main/stars.svg)
86
88
 
89
+ Example 3:
90
+ ----
91
+ This example uses components.
92
+ ```
93
+ clearscreen()
94
+ setup(300,300)
95
+
96
+ comp_shape = Shape("compound")
97
+ poly = ((-50,0),(-50,100),(50,100),(50,0))
98
+ comp_shape.addcomponent(poly,"blue")
99
+ comp_shape.addellipsecomponent((0,120),50,"red")
100
+
101
+ star_coords = ((-10,-13.8), (0,17), (10,-13.8), (-16.2,5.3), (16.2,5.3))
102
+
103
+ addshape("box_with_ball", comp_shape)
104
+ addshape("star", star_coords)
105
+
106
+ t = Turtle()
107
+ t.shapesize(0.5,0.5)
108
+ t.fillcolor("yellow")
109
+ t.shapesize(0.25)
110
+ t.shape("box_with_ball")
111
+ t.pensize(2)
112
+ t.speed(5)
113
+ t.begin_fill()
114
+
115
+ for _ in range(4):
116
+ t.forward(100)
117
+ t.left(90)
118
+ t.end_fill()
119
+ t.forward(100)
120
+ t.left(90)
121
+
122
+ s = Turtle()
123
+ s.shapesize(1.5)
124
+ s.shape("star")
125
+ s.circle(-50)
126
+ s.color("black","green")
127
+ ```
128
+ The resulting image is
129
+ ![](https://github.com/mathriddle/ColabTurtlePlus/raw/main/example3.svg)
130
+
87
131
  Main differences with ColabTurtle
88
132
  ----
89
133
  This version implements classes.
@@ -1,6 +1,6 @@
1
1
  [metadata]
2
2
  name = ColabTurtlePlus
3
- version = 2.1.0
3
+ version = 2.1.2
4
4
  author = Larry Riddle
5
5
  author_email = lriddle@agnesscott.edu
6
6
  description = 'An HTML based Turtle implementation with classes for Google Colab and Jupyter Labs'
@@ -9,7 +9,7 @@ README = (HERE / "README.md").read_text()
9
9
 
10
10
  setup(
11
11
  name='ColabTurtlePlus',
12
- version='2.1.0',
12
+ version='2.1.2',
13
13
  packages=['ColabTurtlePlus'],
14
14
  url='https://github.com/mathriddle/ColabTurtlePlus',
15
15
  license='MIT',
File without changes