Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Por2 #25

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Por2 #25

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions angry.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
from smiley import Smiley
import time



class Angry(Smiley):
def __init__(self):
super().__init__(complexion = self.RED)

Y = self.complexion()
O = self.BLANK
self.pixels = [
O, Y, Y, Y, Y, Y, Y, O,
Y, Y, Y, Y, Y, Y, Y, Y,
Y, Y, Y, Y, Y, Y, Y, Y,
Y, Y, Y, Y, Y, Y, Y, Y,
Y, Y, Y, Y, Y, Y, Y, Y,
Y, Y, Y, Y, Y, Y, Y, Y,
Y, Y, Y, Y, Y, Y, Y, Y,
O, Y, Y, Y, Y, Y, Y, O,
]

self.draw_mouth()
self.draw_eyes()

def draw_mouth(self):
"""
Draws the mouth feature on a smiley
"""
mouth = [50, 42, 43, 44, 45, 53]
for pixel in mouth:
self.pixels[pixel] = self.BLANK

def draw_eyes(self, wide_open=True):
"""
Draws open or closed eyes on a smiley
:param wide_open: Render eyes wide open or shut
"""
eyes = [9, 10, 13, 14, 18, 21]
for pixel in eyes:
if wide_open:
eyes = self.BLANK
else:
eyes = self.complexion()
self.pixels[pixel] = eyes

def blink(self, delay=0.25):

self.draw_eyes(wide_open=False)
self.show()
time.sleep(delay)
self.draw_eyes(wide_open=True)
self.show()
Binary file added civ-ipriot-smiley_screenshots/Blue sad.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions happy.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ def draw_eyes(self, wide_open=True):
"""
eyes = [10, 13, 18, 21]
for pixel in eyes:
self.pixels[pixel] = self.BLANK if wide_open else self.YELLOW
self.pixels[pixel] = self.BLANK if wide_open else self.complexion()

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)
Expand Down
198 changes: 125 additions & 73 deletions knowledge_and_evidence.md

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
import time

from happy import Happy
from sad import Sad
from angry import Angry

def main():
smiley = Happy()
smiley = Angry()

smiley.show()

Expand Down
27 changes: 25 additions & 2 deletions sad.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@
from smiley import Smiley
import time



class Sad(Smiley):
def __init__(self):
super().__init__()
super().__init__(complexion=self.BLUE)

Y = self.complexion()
O = self.BLANK
self.pixels = [
O, Y, Y, Y, Y, Y, Y, O,
Y, Y, Y, Y, Y, Y, Y, Y,
Y, Y, Y, Y, Y, Y, Y, Y,
Y, Y, Y, Y, Y, Y, Y, Y,
Y, Y, Y, Y, Y, Y, Y, Y,
Y, Y, Y, Y, Y, Y, Y, Y,
Y, Y, Y, Y, Y, Y, Y, Y,
O, Y, Y, Y, Y, Y, Y, O,
]

self.draw_mouth()
self.draw_eyes()
Expand All @@ -26,5 +41,13 @@ def draw_eyes(self, wide_open=True):
if wide_open:
eyes = self.BLANK
else:
eyes = self.YELLOW
eyes = self.complexion()
self.pixels[pixel] = eyes

def blink(self, delay=0.25):

self.draw_eyes(wide_open=False)
self.show()
time.sleep(delay)
self.draw_eyes(wide_open=True)
self.show()
27 changes: 17 additions & 10 deletions smiley.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,32 @@
from sense_hat import SenseHat


class Smiley:
WHITE = (255, 255, 255)
GREEN = (0, 255, 0)
RED = (255, 0, 0)
YELLOW = (255, 255, 0)
BLANK = (0, 0, 0)
BLUE = (0, 0, 255)


def __init__(self):
def __init__(self, complexion = YELLOW):
# We have encapsulated the SenseHat object
self.sense_hat = SenseHat()

self.my_complexion = complexion

Y = self.YELLOW
O = self.BLANK
X = self.my_complexion
self.pixels = [
O, Y, Y, Y, Y, Y, Y, O,
Y, Y, Y, Y, Y, Y, Y, Y,
Y, Y, Y, Y, Y, Y, Y, Y,
Y, Y, Y, Y, Y, Y, Y, Y,
Y, Y, Y, Y, Y, Y, Y, Y,
Y, Y, Y, Y, Y, Y, Y, Y,
Y, Y, Y, Y, Y, Y, Y, Y,
O, Y, Y, Y, Y, Y, Y, O,
O, X, X, X, X, X, X, O,
X, X, X, X, X, X, X, X,
X, X, X, X, X, X, X, X,
X, X, X, X, X, X, X, X,
X, X, X, X, X, X, X, X,
X, X, X, X, X, X, X, X,
X, X, X, X, X, X, X, X,
O, X, X, X, X, X, X, O,
]

def dim_display(self, dimmed=True):
Expand All @@ -37,3 +41,6 @@ def show(self):
Show the smiley on the screen.
"""
self.sense_hat.set_pixels(self.pixels)

def complexion(self):
return self.my_complexion