File: ellipse.py

package info (click to toggle)
wxpython3.0 3.0.2.0%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 482,760 kB
  • ctags: 518,293
  • sloc: cpp: 2,127,226; python: 294,045; makefile: 51,942; ansic: 19,033; sh: 3,013; xml: 1,629; perl: 17
file content (33 lines) | stat: -rw-r--r-- 792 bytes parent folder | download | duplicates (14)
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
27
28
29
30
31
32
33
snippet_normalize(cr, width, height)

def path_ellipse(cr, x, y, width, height, angle=0):
    """
    x      - center x
    y      - center y
    width  - width of ellipse  (in x direction when angle=0)
    height - height of ellipse (in y direction when angle=0)
    angle  - angle in radians to rotate, clockwise
    """
    cr.save()
    cr.translate(x, y)
    cr.rotate(angle)
    cr.scale(width / 2.0, height / 2.0)
    cr.arc(0.0, 0.0, 1.0, 0.0, 2.0 * M_PI)
    cr.restore()


path_ellipse(cr, 0.5, 0.5, 1.0, 0.3, M_PI/4.0)

# fill
cr.set_source_rgba(1,0,0,1)
cr.fill_preserve()

# stroke
# reset identity matrix so line_width is a constant
# width in device-space, not user-space
cr.save()
cr.identity_matrix()
cr.set_source_rgba(0,0,0,1)
cr.set_line_width(3)
cr.stroke()
cr.restore()