File: split.py

package info (click to toggle)
pyx3 0.17-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,328 kB
  • sloc: python: 27,656; makefile: 225; ansic: 130; sh: 17
file content (26 lines) | stat: -rw-r--r-- 1,041 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import math
from pyx import *

circle = path.circle(0, 0, 5/math.pi)
opencircle, = circle.split(circle.begin())

c = canvas.canvas()

def showsplit(x, y, path, splitpoints, description):
    c.text(x, y, description, [text.halign.center, text.vshift.mathaxis])
    segments = path.transformed(trafo.translate(x, y)).split(splitpoints)
    print("path sement lengths for ``%s'':" % description)
    for segment, segment_color in zip(segments, [color.rgb.red, color.rgb.green, color.rgb.blue]):
        print("  %s" % segment.arclen())
        c.stroke(segment, [deco.earrow.normal, style.linestyle.dashed, segment_color])
    print()

showsplit(0, 0, opencircle, [opencircle.begin()+1, opencircle.end()-1], "open, $p_1 < p_2$")
showsplit(0, -5, opencircle, [opencircle.end()-1, opencircle.begin()+1], "open, $p_1 > p_2$")

showsplit(5, 0, circle, [circle.begin()+1, circle.end()-1], "closed, $p_1 < p_2$")
showsplit(5, -5, circle, [circle.end()-1, circle.begin()+1], "closed, $p_1 > p_2$")

c.writeEPSfile()
c.writePDFfile()
c.writeSVGfile()