tangled
alpha
login
or
join now
cduck.me
/
drawsvg
0
fork
atom
Programmatically generate SVG (vector) images, animations, and interactive Jupyter widgets
0
fork
atom
overview
issues
pulls
pipelines
Update example for hyperbolic~=2.0
cduck.me
3 years ago
1cb673ad
d3ccb9f5
+7
-13
1 changed file
expand all
collapse all
unified
split
README.md
+7
-13
README.md
reviewed
···
333
333
```python
334
334
import drawsvg as draw
335
335
from drawsvg.widgets import DrawingWidget
336
336
-
import hyperbolic.poincare.shapes as hyper # python3 -m pip install hyperbolic
336
336
+
import hyperbolic.poincare as hyper # python3 -m pip install hyperbolic
337
337
from hyperbolic import euclid
338
338
-
339
339
-
# Patch the hyperbolic package for drawsvg version 2
340
340
-
patch = lambda m: lambda self, **kw: m(self, draw, **kw)
341
341
-
hyper.Circle.to_drawables = patch(hyper.Circle.toDrawables)
342
342
-
hyper.Line.to_drawables = patch(hyper.Line.toDrawables)
343
343
-
euclid.Arc.Arc.drawToPath = lambda self, path, includeM=True, includeL=False: path.arc(self.cx, self.cy, self.r, self.startDeg, self.endDeg, cw=not self.cw, include_m=includeM, include_l=includeL)
344
338
345
339
# Create drawing
346
340
d = draw.Drawing(2, 2, origin='center', context=draw.Context(invert_y=True))
···
356
350
for x1, y1 in points:
357
351
for x2, y2 in points:
358
352
if (x1, y1) == (x2, y2): continue
359
359
-
p1 = hyper.Point.fromEuclid(x1, y1)
360
360
-
p2 = hyper.Point.fromEuclid(x2, y2)
361
361
-
if p1.distanceTo(p2) <= 2:
362
362
-
line = hyper.Line.fromPoints(*p1, *p2, segment=True)
353
353
+
p1 = hyper.Point.from_euclid(x1, y1)
354
354
+
p2 = hyper.Point.from_euclid(x2, y2)
355
355
+
if p1.distance_to(p2) <= 2:
356
356
+
line = hyper.Line.from_points(*p1, *p2, segment=True)
363
357
group.draw(line, hwidth=0.2, fill='white')
364
358
for x, y in points:
365
365
-
p = hyper.Point.fromEuclid(x, y)
366
366
-
group.draw(hyper.Circle.fromCenterRadius(p, 0.1),
359
359
+
p = hyper.Point.from_euclid(x, y)
360
360
+
group.draw(hyper.Circle.from_center_radius(p, 0.1),
367
361
fill='green')
368
362
redraw(click_list)
369
363