2022-12-23 16:15:35 -05:00
|
|
|
# There are 4 different types of patterns used when generating a digit that is
|
|
|
|
# to be placed in a rectangle 3X5 pixels. Combinations of these are used to
|
|
|
|
# create a number pattern such as:
|
2022-12-23 11:26:50 -05:00
|
|
|
# * * *
|
|
|
|
# *
|
|
|
|
# * * *
|
|
|
|
# * *
|
|
|
|
# * * *
|
2022-12-23 16:15:35 -05:00
|
|
|
#
|
2022-12-23 11:26:50 -05:00
|
|
|
# 1) * * * Full Row
|
|
|
|
# 2) * * Both Sides
|
|
|
|
# 3) * Right Side
|
|
|
|
# 4) * Left Side
|
2022-12-24 10:59:04 -05:00
|
|
|
|
|
|
|
import colors
|
|
|
|
|
|
|
|
|
2022-12-23 11:26:50 -05:00
|
|
|
class CharacterDisplay:
|
|
|
|
|
2022-12-26 19:37:50 -05:00
|
|
|
def __init__(self, unicorn, minX=0, maxX=15, minY=0, maxY=15):
|
2022-12-23 11:26:50 -05:00
|
|
|
self.unicorn = unicorn
|
2022-12-23 14:57:33 -05:00
|
|
|
self.minX = minX
|
|
|
|
self.maxX = maxX
|
2022-12-26 19:37:50 -05:00
|
|
|
self.minY = minY
|
|
|
|
self.maxY = maxY
|
2022-12-23 11:26:50 -05:00
|
|
|
|
2022-12-23 18:31:04 -05:00
|
|
|
self.digits = {
|
2022-12-24 10:59:04 -05:00
|
|
|
'0': self.displayZero,
|
|
|
|
'1': self.displayOne,
|
|
|
|
'2': self.displayTwo,
|
|
|
|
'3': self.displayThree,
|
|
|
|
'4': self.displayFour,
|
|
|
|
'5': self.displayFive,
|
|
|
|
'6': self.displaySix,
|
|
|
|
'7': self.displaySeven,
|
|
|
|
'8': self.displayEight,
|
|
|
|
'9': self.displayNine
|
2022-12-23 18:31:04 -05:00
|
|
|
}
|
2022-12-23 11:26:50 -05:00
|
|
|
|
2022-12-23 18:31:04 -05:00
|
|
|
def displayDigit(self, x, y, digit, color):
|
2022-12-23 18:39:55 -05:00
|
|
|
self.clearDigit(x, y)
|
2022-12-23 18:31:04 -05:00
|
|
|
self.digits[digit](x, y, color)
|
2022-12-23 11:26:50 -05:00
|
|
|
self.unicorn.show()
|
|
|
|
|
2022-12-23 16:15:35 -05:00
|
|
|
def clearDigit(self, x, y):
|
2022-12-23 11:26:50 -05:00
|
|
|
for y1 in range(y, y-5, -1):
|
2022-12-23 14:57:33 -05:00
|
|
|
for x1 in range(x, x+3):
|
2022-12-24 10:59:04 -05:00
|
|
|
self.setPixel(x1, y1, colors.BLACK)
|
2022-12-23 11:26:50 -05:00
|
|
|
|
|
|
|
self.unicorn.show()
|
|
|
|
|
2022-12-26 19:37:50 -05:00
|
|
|
def clearRow(self, y, rowHeight=5):
|
|
|
|
for row in range(y, y-rowHeight, -1):
|
2022-12-24 12:10:46 -05:00
|
|
|
for col in range(self.minX, self.maxX + 1):
|
|
|
|
self.setPixel(col, row, colors.BLACK)
|
|
|
|
|
|
|
|
self.unicorn.show()
|
|
|
|
|
2022-12-27 19:49:15 -05:00
|
|
|
def displayTimeDots(self, x, y, color):
|
2022-12-23 18:15:43 -05:00
|
|
|
self.setPixel(x, y-1, color)
|
|
|
|
self.setPixel(x, y-3, color)
|
2022-12-23 11:26:50 -05:00
|
|
|
self.unicorn.show()
|
2022-12-23 14:57:33 -05:00
|
|
|
|
2022-12-27 19:49:15 -05:00
|
|
|
def displayDegree(self, x, y, color):
|
|
|
|
self.setPixel(x, y, color)
|
|
|
|
self.setPixel(x, y-1, color)
|
|
|
|
self.setPixel(x+1, y, color)
|
|
|
|
self.setPixel(x+1, y-1, color)
|
|
|
|
self.unicorn.show()
|
|
|
|
|
2022-12-24 10:59:04 -05:00
|
|
|
def displayNegative(self, x, y, color):
|
|
|
|
self.setPixel(x, y-2, color)
|
|
|
|
self.setPixel(x+1, y-2, color)
|
2022-12-24 19:10:15 -05:00
|
|
|
self.unicorn.show()
|
2022-12-24 10:59:04 -05:00
|
|
|
|
2022-12-26 19:37:50 -05:00
|
|
|
def displaySquare(self, x, y, outlineColor, fillColor):
|
|
|
|
self.fullLine(x, y, outlineColor)
|
|
|
|
self.leftSide(x, y-1, outlineColor)
|
|
|
|
self.leftSide(x, y-2, outlineColor)
|
|
|
|
self.fullLine(x, y-3, outlineColor)
|
|
|
|
self.rightSide(x+1, y, outlineColor)
|
|
|
|
self.rightSide(x+1, y-1, outlineColor)
|
|
|
|
self.rightSide(x+1, y-2, outlineColor)
|
|
|
|
self.rightSide(x+1, y-3, outlineColor)
|
|
|
|
|
2022-12-28 18:37:32 -05:00
|
|
|
self.setPixel(x+1, y-1, fillColor)
|
|
|
|
self.setPixel(x+1, y-2, fillColor)
|
|
|
|
self.setPixel(x+2, y-1, fillColor)
|
|
|
|
self.setPixel(x+2, y-2, fillColor)
|
2022-12-26 19:37:50 -05:00
|
|
|
self.unicorn.show()
|
|
|
|
|
2022-12-23 16:15:35 -05:00
|
|
|
def displayZero(self, x, y, color):
|
2022-12-23 18:15:43 -05:00
|
|
|
self.fullLine(x, y, color)
|
|
|
|
self.bothSides(x, y-1, color)
|
|
|
|
self.bothSides(x, y-2, color)
|
|
|
|
self.bothSides(x, y-3, color)
|
|
|
|
self.fullLine(x, y-4, color)
|
2022-12-23 16:15:35 -05:00
|
|
|
|
|
|
|
def displayOne(self, x, y, color):
|
2022-12-23 18:15:43 -05:00
|
|
|
self.rightSide(x, y, color)
|
|
|
|
self.rightSide(x, y-1, color)
|
|
|
|
self.rightSide(x, y-2, color)
|
|
|
|
self.rightSide(x, y-3, color)
|
|
|
|
self.rightSide(x, y-4, color)
|
2022-12-23 16:15:35 -05:00
|
|
|
|
|
|
|
def displayTwo(self, x, y, color):
|
2022-12-23 18:15:43 -05:00
|
|
|
self.fullLine(x, y, color)
|
|
|
|
self.rightSide(x, y-1, color)
|
|
|
|
self.fullLine(x, y-2, color)
|
|
|
|
self.leftSide(x, y-3, color)
|
|
|
|
self.fullLine(x, y-4, color)
|
2022-12-23 16:15:35 -05:00
|
|
|
|
|
|
|
def displayThree(self, x, y, color):
|
2022-12-23 18:15:43 -05:00
|
|
|
self.fullLine(x, y, color)
|
|
|
|
self.rightSide(x, y-1, color)
|
|
|
|
self.fullLine(x, y-2, color)
|
|
|
|
self.rightSide(x, y-3, color)
|
|
|
|
self.fullLine(x, y-4, color)
|
2022-12-23 16:15:35 -05:00
|
|
|
|
|
|
|
def displayFour(self, x, y, color):
|
2022-12-23 18:15:43 -05:00
|
|
|
self.bothSides(x, y, color)
|
|
|
|
self.bothSides(x, y-1, color)
|
|
|
|
self.fullLine(x, y-2, color)
|
|
|
|
self.rightSide(x, y-3, color)
|
|
|
|
self.rightSide(x, y-4, color)
|
2022-12-23 16:15:35 -05:00
|
|
|
|
|
|
|
def displayFive(self, x, y, color):
|
2022-12-23 18:15:43 -05:00
|
|
|
self.fullLine(x, y, color)
|
|
|
|
self.leftSide(x, y-1, color)
|
|
|
|
self.fullLine(x, y-2, color)
|
|
|
|
self.rightSide(x, y-3, color)
|
|
|
|
self.fullLine(x, y-4, color)
|
2022-12-23 16:15:35 -05:00
|
|
|
|
|
|
|
def displaySix(self, x, y, color):
|
2022-12-23 18:15:43 -05:00
|
|
|
self.fullLine(x, y, color)
|
|
|
|
self.leftSide(x, y-1, color)
|
|
|
|
self.fullLine(x, y-2, color)
|
|
|
|
self.bothSides(x, y-3, color)
|
|
|
|
self.fullLine(x, y-4, color)
|
2022-12-23 16:15:35 -05:00
|
|
|
|
|
|
|
def displaySeven(self, x, y, color):
|
2022-12-23 18:15:43 -05:00
|
|
|
self.fullLine(x, y, color)
|
|
|
|
self.rightSide(x, y-1, color)
|
|
|
|
self.rightSide(x, y-2, color)
|
|
|
|
self.rightSide(x, y-3, color)
|
|
|
|
self.rightSide(x, y-4, color)
|
2022-12-23 16:15:35 -05:00
|
|
|
|
|
|
|
def displayEight(self, x, y, color):
|
2022-12-23 18:15:43 -05:00
|
|
|
self.fullLine(x, y, color)
|
|
|
|
self.bothSides(x, y-1, color)
|
|
|
|
self.fullLine(x, y-2, color)
|
|
|
|
self.bothSides(x, y-3, color)
|
|
|
|
self.fullLine(x, y-4, color)
|
2022-12-23 16:15:35 -05:00
|
|
|
|
|
|
|
def displayNine(self, x, y, color):
|
2022-12-23 18:15:43 -05:00
|
|
|
self.fullLine(x, y, color)
|
|
|
|
self.bothSides(x, y-1, color)
|
|
|
|
self.fullLine(x, y-2, color)
|
|
|
|
self.rightSide(x, y-3, color)
|
|
|
|
self.fullLine(x, y-4, color)
|
2022-12-23 16:15:35 -05:00
|
|
|
|
2022-12-23 18:15:43 -05:00
|
|
|
def fullLine(self, start, row, color):
|
2022-12-23 16:15:35 -05:00
|
|
|
for x in range(start, start+3):
|
2022-12-23 18:15:43 -05:00
|
|
|
self.setPixel(x, row, color)
|
2022-12-23 16:15:35 -05:00
|
|
|
|
2022-12-23 18:15:43 -05:00
|
|
|
def bothSides(self, start, row, color):
|
|
|
|
self.setPixel(start, row, color)
|
|
|
|
self.setPixel(start+2, row, color)
|
2022-12-23 16:15:35 -05:00
|
|
|
|
2022-12-23 18:15:43 -05:00
|
|
|
def leftSide(self, start, row, color):
|
|
|
|
self.setPixel(start, row, color)
|
2022-12-23 16:15:35 -05:00
|
|
|
|
2022-12-23 18:15:43 -05:00
|
|
|
def rightSide(self, start, row, color):
|
|
|
|
self.setPixel(start+2, row, color)
|
2022-12-23 16:15:35 -05:00
|
|
|
|
2022-12-23 18:15:43 -05:00
|
|
|
def setPixel(self, x, y, color):
|
2022-12-26 19:37:50 -05:00
|
|
|
if x >= self.minX and x <= self.maxX and y >= self.minY and y <= self.maxY:
|
2022-12-23 18:15:43 -05:00
|
|
|
self.unicorn.set_pixel(x, y, *color)
|