# There are 4 different types of patterns used when generating # a number that is to be placed in a rectangle 3X5 pixels. Combinations of these # are used to create a number pattern such as: # * * * # * # * * * # * * # * * * # 1) * * * Full Row # 2) * * Both Sides # 3) * Right Side # 4) * Left Side class CharacterDisplay: def __init__(self, unicorn): self.unicorn = unicorn def fullLine(self, start, row): for x in range(max(start, 0), start+3): self.unicorn.set_pixel(x, row, 255, 0, 0) def bothSides(self, start, row): if (start >= 0): self.unicorn.set_pixel(start, row, 255, 0, 0) self.unicorn.set_pixel(start+2, row, 255, 0, 0) def leftSide(self, start, row): if (start >= 0): self.unicorn.set_pixel(start, row, 255, 0, 0) def rightSide(self, start, row): self.unicorn.set_pixel(start+2, row, 255, 0, 0) def displayZero(self, x, y): self.clearNumberPixels(x, y) self.fullLine(x, y) self.bothSides(x, y-1) self.bothSides(x, y-2) self.bothSides(x, y-3) self.fullLine(x, y-4) def displayOne(self, x, y): self.clearNumberPixels(x, y) self.rightSide(x, y) self.rightSide(x, y-1) self.rightSide(x, y-2) self.rightSide(x, y-3) self.rightSide(x, y-4) def displayTwo(self, x, y): self.clearNumberPixels(x, y) self.fullLine(x, y) self.rightSide(x, y-1) self.fullLine(x, y-2) self.leftSide(x, y-3) self.fullLine(x, y-4) def displayThree(self, x, y): self.clearNumberPixels(x, y) self.fullLine(x, y) self.rightSide(x, y-1) self.fullLine(x, y-2) self.rightSide(x, y-3) self.fullLine(x, y-4) def displayFour(self, x, y): self.clearNumberPixels(x, y) self.bothSides(x, y) self.bothSides(x, y-1) self.fullLine(x, y-2) self.rightSide(x, y-3) self.rightSide(x, y-4) def displayFive(self, x, y): self.clearNumberPixels(x, y) self.fullLine(x, y) self.leftSide(x, y-1) self.fullLine(x, y-2) self.rightSide(x, y-3) self.fullLine(x, y-4) def displaySix(self, x, y): self.clearNumberPixels(x, y) self.fullLine(x, y) self.leftSide(x, y-1) self.fullLine(x, y-2) self.bothSides(x, y-3) self.fullLine(x, y-4) def displaySeven(self, x, y): self.clearNumberPixels(x, y) self.fullLine(x, y) self.rightSide(x, y-1) self.rightSide(x, y-2) self.rightSide(x, y-3) self.rightSide(x, y-4) def displayEight(self, x, y): self.clearNumberPixels(x, y) self.fullLine(x, y) self.bothSides(x, y-1) self.fullLine(x, y-2) self.bothSides(x, y-3) self.fullLine(x, y-4) def displayNine(self, x, y): self.clearNumberPixels(x, y) self.fullLine(x, y) self.bothSides(x, y-1) self.fullLine(x, y-2) self.rightSide(x, y-3) self.fullLine(x, y-4) def displayNumber(self, x, y, number): if number == 0: self.displayZero(x, y) elif number == 1: self.displayOne(x, y) elif number == 2: self.displayTwo(x, y) elif number == 3: self.displayThree(x, y) elif number == 4: self.displayFour(x, y) elif number == 5: self.displayFive(x, y) elif number == 6: self.displaySix(x, y) elif number == 7: self.displaySeven(x, y) elif number == 8: self.displayEight(x, y) elif number == 9: self.displayNine(x, y) self.unicorn.show() def clearNumberPixels(self, x, y): for y1 in range(y, y-5, -1): for x1 in range(max(x, 0), x+3): self.unicorn.set_pixel(x1, y1, 0, 0, 0) self.unicorn.show() def displayTimeDots(self, x, y): self.unicorn.set_pixel(x, y-1, 255, 0, 0) self.unicorn.set_pixel(x, y-3, 255, 0, 0) self.unicorn.show()