chutney/chutney/symbol_display.py

165 lines
5.1 KiB
Python

import chutney.colors as colors
class SymbolDisplay:
def __init__(self, unicorn, minX=0, maxX=15, minY=0, maxY=15):
self.unicorn = unicorn
self.minX = minX
self.maxX = maxX
self.minY = minY
self.maxY = maxY
self.digits = {
'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
}
def displayDigit(self, x, y, digit, color):
self.clearDigit(x, y)
self.digits[digit](x, y, color)
self.unicorn.show()
def clearDigit(self, x, y):
for y1 in range(y, y-5, -1):
for x1 in range(x, x+3):
self.setPixel(x1, y1, colors.BLACK)
self.unicorn.show()
def clearRow(self, y, rowHeight=5):
for row in range(y, y-rowHeight, -1):
for col in range(self.minX, self.maxX + 1):
self.setPixel(col, row, colors.BLACK)
self.unicorn.show()
def displayTimeDots(self, x, y, color):
self.setPixel(x, y-1, color)
self.setPixel(x, y-3, color)
self.unicorn.show()
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()
def displayNegative(self, x, y, color):
self.setPixel(x, y-2, color)
self.setPixel(x+1, y-2, color)
self.unicorn.show()
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)
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)
self.unicorn.show()
def displayZero(self, x, y, color):
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)
def displayOne(self, x, y, color):
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)
def displayTwo(self, x, y, color):
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)
def displayThree(self, x, y, color):
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)
def displayFour(self, x, y, color):
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)
def displayFive(self, x, y, color):
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)
def displaySix(self, x, y, color):
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)
def displaySeven(self, x, y, color):
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)
def displayEight(self, x, y, color):
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)
def displayNine(self, x, y, color):
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)
def fullLine(self, start, row, color):
for x in range(start, start+3):
self.setPixel(x, row, color)
def bothSides(self, start, row, color):
self.setPixel(start, row, color)
self.setPixel(start+2, row, color)
def leftSide(self, start, row, color):
self.setPixel(start, row, color)
def rightSide(self, start, row, color):
self.setPixel(start+2, row, color)
def setPixel(self, x, y, color):
if x >= self.minX and x <= self.maxX and y >= self.minY and y <= self.maxY:
self.unicorn.set_pixel(x, y, *color)