-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy patheyelashes.py
127 lines (113 loc) · 5.85 KB
/
eyelashes.py
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# Speak.activity
# A simple front end to the espeak text-to-speech engine on the XO laptop
# http://wiki.laptop.org/go/Speak
#
# Copyright (C) 2008 Joshua Minor
# Copyright (C) 2014 Walter Bender
# This file is part of Speak.activity
#
# Parts of Speak.activity are based on code from Measure.activity
# Copyright (C) 2007 Arjun Sarwal - arjun@laptop.org
#
# Speak.activity is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Speak.activity is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Speak.activity. If not, see <http://www.gnu.org/licenses/>.
import math
from gi.repository import Gdk
from gi.repository import GdkPixbuf
from eye import Eye
from utils import svg_str_to_pixbuf
class Eyelashes(Eye):
def __init__(self, fill_color):
Eye.__init__(self, fill_color)
self._pixbuf = svg_str_to_pixbuf(eyelashes_svg())
def draw(self, widget, cr):
bounds = self.get_allocation()
eyeSize = min(bounds.width, bounds.height)
outlineWidth = eyeSize / 20.0
pupilSize = eyeSize / 10.0
pupilX, pupilY = self.computePupil()
dX = pupilX - bounds.width / 2.
dY = pupilY - bounds.height / 2.
distance = math.sqrt(dX * dX + dY * dY)
limit = eyeSize / 2 - outlineWidth * 2 - pupilSize
if distance > limit:
pupilX = bounds.width / 2 + dX * limit / distance
pupilY = bounds.height / 2 + dY * limit / distance + \
int(bounds.height * 0.1)
# background
cr.set_source_rgba(*self.fill_color.get_rgba())
cr.rectangle(0, 0, bounds.width, bounds.height)
cr.fill()
w = h = min(bounds.width, bounds.height)
x = int((bounds.width - w) / 2)
y = int((bounds.height - h) / 2)
pixbuf = self._pixbuf.scale_simple(w, h, GdkPixbuf.InterpType.BILINEAR)
cr.translate(x + w / 2., y + h / 2.)
cr.translate(-x - w / 2., -y - h / 2.)
Gdk.cairo_set_source_pixbuf(cr, pixbuf, x, y)
cr.rectangle(x, y, w, h)
cr.fill()
# pupil
cr.arc(pupilX, pupilY, pupilSize, 0, 2 * math.pi)
cr.set_source_rgb(0, 0, 0)
cr.fill()
return True
def eyelashes_svg():
return '<?xml version="1.0" encoding="UTF-8" standalone="no"?>\n' + \
'<svg\n' + \
'xmlns:svg="http://www.w3.org/2000/svg"\n' + \
'xmlns="http://www.w3.org/2000/svg"\n' + \
'version="1.1"\n' + \
'width="300"\n' + \
'height="300"\n' + \
'>\n' + \
'<g\n' + \
'transform="matrix(5.4545455,0,0,5.4545455,-1.239,-5440.1557)"\n' + \
'>\n' + \
'<g\n' + \
'transform="matrix(0.96700035,0,0,0.96700035,0.75256628,31.994388)"\n' + \
'>\n' + \
'<path\n' + \
'd="m 702.85715,-306.42856 a 202.85715,201.42857 0 1 1 -405.7143,0 202.85715,201.42857 0 1 1 405.7143,0 z"\n' + \
'transform="matrix(0.11328527,0,0,0.11328527,-29.306097,1065.8336)"\n' + \
'style="fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:22.06818199;stroke-linecap:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" />\n' + \
'<path\n' + \
'd="M 9.2108952,1016.3927 2.413779,1011.5376"\n' + \
'style="fill:none;stroke:#000000;stroke-width:2.5;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" />\n' + \
'<path\n' + \
'd="m 13.418634,1012.8323 -5.5024274,-7.1208"\n' + \
'style="fill:none;stroke:#000000;stroke-width:2.5;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" />\n' + \
'<path\n' + \
'd="m 17.626373,1010.2429 -3.884067,-8.0918"\n' + \
'style="fill:none;stroke:#000000;stroke-width:2.5;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" />\n' + \
'<path\n' + \
'd="m 22.805128,1008.5085 -2.406446,-8.51932"\n' + \
'style="fill:none;stroke:#000000;stroke-width:2.5;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" />\n' + \
'<path\n' + \
'd="m 27.452641,1007.6535 -0.116103,-8.09177"\n' + \
'style="fill:none;stroke:#000000;stroke-width:2.5;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" />\n' + \
'<path\n' + \
'd="m 32.39919,1008.4838 2.38181,-7.9511"\n' + \
'style="fill:none;stroke:#000000;stroke-width:2.5;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" />\n' + \
'<path\n' + \
'd="m 37.694049,1009.9192 3.884067,-8.0918"\n' + \
'style="fill:none;stroke:#000000;stroke-width:2.5;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" />\n' + \
'<path\n' + \
'd="m 41.901788,1013.156 4.855082,-7.4445"\n' + \
'style="fill:none;stroke:#000000;stroke-width:2.5;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" />\n' + \
'<path\n' + \
'd="m 45.462182,1017.04 7.444461,-5.1787"\n' + \
'style="fill:none;stroke:#000000;stroke-width:2.5;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" />\n' + \
'</g>\n' + \
'</g>\n' + \
'</svg>'