| 1 |
from math import pi |
| 2 |
|
| 3 |
|
| 4 |
def path_ellipse(cr, x, y, width, height, angle=0): |
| 5 |
""" |
| 6 |
x - center x |
| 7 |
y - center y |
| 8 |
width - width of ellipse (in x direction when angle=0) |
| 9 |
height - height of ellipse (in y direction when angle=0) |
| 10 |
angle - angle in radians to rotate, clockwise |
| 11 |
""" |
| 12 |
cr.save() |
| 13 |
cr.translate(x, y) |
| 14 |
cr.rotate(angle) |
| 15 |
cr.scale(width / 2.0, height / 2.0) |
| 16 |
cr.arc(0.0, 0.0, 1.0, 0.0, 2.0 * pi) |
| 17 |
cr.restore() |
| 18 |
|
| 19 |
|
| 20 |
def draw(cr, width, height): |
| 21 |
cr.scale(width, height) |
| 22 |
cr.set_line_width(0.04) |
| 23 |
|
| 24 |
path_ellipse(cr, 0.5, 0.5, 1.0, 0.3, pi / 4.0) |
| 25 |
|
| 26 |
|
| 27 |
cr.set_source_rgba(1, 0, 0, 1) |
| 28 |
cr.fill_preserve() |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
cr.save() |
| 34 |
cr.identity_matrix() |
| 35 |
cr.set_source_rgba(0, 0, 0, 1) |
| 36 |
cr.set_line_width(3) |
| 37 |
cr.stroke() |
| 38 |
cr.restore() |