-
Notifications
You must be signed in to change notification settings - Fork 183
/
happy.py
43 lines (36 loc) · 1.1 KB
/
happy.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
import time
from blinkable import Blinkable
from smiley import Smiley
class Happy(Smiley, Blinkable):
"""
Provides a Smiley with a happy expression
"""
def __init__(self):
super().__init__()
self.draw_mouth()
self.draw_eyes()
def draw_mouth(self):
"""
Renders a mouth by blanking the pixels that form that object.
"""
mouth = [41, 46, 50, 51, 52, 53]
for pixel in mouth:
self.pixels[pixel] = self.BLANK
def draw_eyes(self, wide_open=True):
"""
Draws the eyes (open or closed) on the standard smiley.
:param wide_open (bool): eyes open or closed.
"""
eyes = [10, 13, 18, 21]
for pixel in eyes:
self.pixels[pixel] = self.BLANK if wide_open else self.YELLOW
def blink(self, delay=0.25):
"""
Blinks the smiley's eyes once
:param delay: Delay between blinks (in seconds)
"""
self.draw_eyes(wide_open=False)
self.show()
time.sleep(delay)
self.draw_eyes(wide_open=True)
self.show()