271 | | from sage.plot.bezier_path import bezier_path |
272 | | from sage.plot.plot import Graphics, line |
273 | | from sage.plot.colors import rainbow |
274 | | if orientation=='top-bottom': |
275 | | orx = 0 |
276 | | ory = -1 |
277 | | nx = 1 |
278 | | ny = 0 |
279 | | elif orientation=='left-right': |
280 | | orx = 1 |
281 | | ory = 0 |
282 | | nx = 0 |
283 | | ny = -1 |
284 | | elif orientation=='bottom-top': |
285 | | orx = 0 |
286 | | ory = 1 |
287 | | nx = 1 |
288 | | ny = 0 |
289 | | else: |
290 | | raise ValueError('unknown value for "orientation"') |
291 | | n = self.strands() |
292 | | if isinstance(color, (list, tuple)): |
293 | | if len(color) != n: |
294 | | raise TypeError("color (=%s) must contain exactly %d colors" % (color, n)) |
295 | | col = list(color) |
296 | | elif color == "rainbow": |
297 | | col = rainbow(n) |
298 | | else: |
299 | | col = [color]*n |
300 | | braid = self.Tietze() |
301 | | a = Graphics() |
302 | | op = gap |
303 | | for i, m in enumerate(braid): |
304 | | for j in range(n): |
305 | | if m==j+1: |
306 | | a += bezier_path([[(j*nx+i*orx, i*ory+j*ny), (j*nx+orx*(i+0.25), j*ny+ory*(i+0.25)), |
307 | | (nx*(j+0.5)+orx*(i+0.5), ny*(j+0.5)+ory*(i+0.5))], |
308 | | [(nx*(j+1)+orx*(i+0.75), ny*(j+1)+ory*(i+0.75)), |
309 | | (nx*(j+1)+orx*(i+1), ny*(j+1)+ory*(i+1))]], color=col[j], **kwds) |
310 | | elif m==j: |
311 | | a += bezier_path([[(nx*j+orx*i, ny*j+ory*i), (nx*j+orx*(i+0.25), ny*j+ory*(i+0.25)), |
312 | | (nx*(j-0.5+4*op)+orx*(i+0.5-2*op), ny*(j-0.5+4*op)+ory*(i+0.5-2*op)), |
313 | | (nx*(j-0.5+2*op)+orx*(i+0.5-op), ny*(j-0.5+2*op)+ory*(i+0.5-op))]], |
314 | | color=col[j], **kwds) |
315 | | a += bezier_path([[(nx*(j-0.5-2*op)+orx*(i+0.5+op), ny*(j-0.5-2*op)+ory*(i+0.5+op)), |
316 | | (nx*(j-0.5-4*op)+orx*(i+0.5+2*op), ny*(j-0.5-4*op)+ory*(i+0.5+2*op)), |
317 | | (nx*(j-1)+orx*(i+0.75), ny*(j-1)+ory*(i+0.75)), |
318 | | (nx*(j-1)+orx*(i+1), ny*(j-1)+ory*(i+1))]], color=col[j], **kwds) |
319 | | col[j], col[j-1] = col[j-1], col[j] |
320 | | elif -m==j+1: |
321 | | a += bezier_path([[(nx*j+orx*i, ny*j+ory*i), (nx*j+orx*(i+0.25), ny*j+ory*(i+0.25)), |
322 | | (nx*(j+0.5-4*op)+orx*(i+0.5-2*op), ny*(j+0.5-4*op)+ory*(i+0.5-2*op)), |
323 | | (nx*(j+0.5-2*op)+orx*(i+0.5-op), ny*(j+0.5-2*op)+ory*(i+0.5-op))]], |
324 | | color=col[j], **kwds) |
325 | | a += bezier_path([[(nx*(j+0.5+2*op)+orx*(i+0.5+op), ny*(j+0.5+2*op)+ory*(i+0.5+op)), |
326 | | (nx*(j+0.5+4*op)+orx*(i+0.5+2*op), ny*(j+0.5+4*op)+ory*(i+0.5+2*op)), |
327 | | (nx*(j+1)+orx*(i+0.75), ny*(j+1)+ory*(i+0.75)), |
328 | | (nx*(j+1)+orx*(i+1), ny*(j+1)+ory*(i+1))]], color=col[j], **kwds) |
329 | | elif -m==j: |
330 | | a += bezier_path([[(nx*j+orx*i, ny*j+ory*i), (nx*j+orx*(i+0.25), ny*j+ory*(i+0.25)), |
331 | | (nx*(j-0.5)+orx*(i+0.5), ny*(j-0.5)+ory*(i+0.5))], |
332 | | [(nx*(j-1)+orx*(i+0.75), ny*(j-1)+ory*(i+0.75)), |
333 | | (nx*(j-1)+orx*(i+1), ny*(j-1)+ory*(i+1))]], color=col[j], **kwds) |
334 | | col[j], col[j-1] = col[j-1], col[j] |
335 | | else: |
336 | | a += line([(nx*j+orx*i, ny*j+ory*i), (nx*j+orx*(i+1), ny*j+ory*(i+1))], color=col[j], **kwds) |
337 | | a.set_aspect_ratio(aspect_ratio) |
338 | | a.axes(axes) |
339 | | return a |
| 272 | from sage.plot.braid_plot import braid_plot |
| 273 | return braid_plot(self.Tietze(), color=color, orientation=orientation, |
| 274 | gap=gap, aspect_ratio=aspect_ratio, axes=axes, **kwds) |