Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/eye.py
diff options
context:
space:
mode:
authorflavio <fdanesse@gmail.com>2012-07-31 14:09:40 (GMT)
committer flavio <fdanesse@gmail.com>2012-07-31 14:09:40 (GMT)
commitbdee0fb30a0e4d9da08fc7481e20070a3ce7ac0a (patch)
tree7c4df1c9a1e73b4b495497a1f00eedac74b9a5f7 /eye.py
parent777d75ee9daedc65e37f4b15e924feb2f6b6dcb6 (diff)
Modularization of the eye
Diffstat (limited to 'eye.py')
-rw-r--r--eye.py59
1 files changed, 58 insertions, 1 deletions
diff --git a/eye.py b/eye.py
index 2729388..7374f92 100644
--- a/eye.py
+++ b/eye.py
@@ -133,4 +133,61 @@ class Eye(Gtk.DrawingArea):
context.fill()
return True
- \ No newline at end of file
+
+class Glasses(Eye):
+ def __init__(self, fill_color):
+ Eye.__init__(self, fill_color)
+
+ self.show_all()
+ self.connect('draw', self.do_draw)
+
+ def do_draw(self, widget, context):
+ rect = self.get_allocation()
+
+ eyeSize = min(rect.width, rect.height)
+ outlineWidth = eyeSize / 20.0
+ pupilSize = eyeSize / 10.0
+ pupilX, pupilY = self.computePupil()
+ dX = pupilX - rect.width / 2.
+ dY = pupilY - rect.height / 2.
+ distance = math.sqrt(dX * dX + dY * dY)
+ limit = eyeSize / 2 - outlineWidth * 2 - pupilSize
+ if distance > limit:
+ pupilX = rect.width / 2 + dX * limit / distance
+ pupilY = rect.height / 2 + dY * limit / distance
+
+ # background
+ context.set_source_rgba(*self.fill_color.get_rgba())
+ context.paint()
+
+ def roundrect(x1, y1, x2, y2):
+ context.move_to(x1, (y1 + y2) / 2.)
+ context.curve_to(x1, y1, x1, y1, (x1 + x2) / 2., y1)
+ context.curve_to(x2, y1, x2, y1, x2, (y1 + y2) / 2.)
+ context.curve_to(x2, y2, x2, y2, (x1 + x2) / 2., y2)
+ context.curve_to(x1, y2, x1, y2, x1, (y1 + y2) / 2.)
+
+ # eye ball
+ context.set_source_rgb(1, 1, 1)
+ roundrect(outlineWidth,
+ outlineWidth,
+ rect.width - outlineWidth,
+ rect.height - outlineWidth)
+ context.fill()
+
+ # outline
+ context.set_source_rgb(0, 0, 0)
+ context.set_line_width(outlineWidth)
+ roundrect(outlineWidth,
+ outlineWidth,
+ rect.width - outlineWidth,
+ rect.height - outlineWidth)
+ #roundrect(0,0, rect.width,rect.height)
+ context.stroke()
+
+ # pupil
+ context.arc(pupilX, pupilY, pupilSize, 0, 360)
+ context.set_source_rgb(0, 0, 0)
+ context.fill()
+
+ return True \ No newline at end of file