updates
This commit is contained in:
@@ -196,12 +196,46 @@ a_e = [
|
||||
]
|
||||
|
||||
class color:
|
||||
def __init__(self, red: int, green: int, blue: int, alpha: int = 255) -> None:
|
||||
def __init__(self, color=None, red=None, green=None, blue=None, alpha=255) -> None:
|
||||
# Allow hex string input like "#ff8800" or "ff8800"
|
||||
if isinstance(color, str):
|
||||
hexcode = color.lstrip("#")
|
||||
|
||||
if len(hexcode) not in (6, 8):
|
||||
raise ValueError("Hex color must be 6 or 8 characters long")
|
||||
|
||||
self.r = int(hexcode[0:2], 16)
|
||||
self.g = int(hexcode[2:4], 16)
|
||||
self.b = int(hexcode[4:6], 16)
|
||||
|
||||
if len(hexcode) == 8:
|
||||
self.a = int(hexcode[6:8], 16)
|
||||
else:
|
||||
self.a = alpha
|
||||
|
||||
else:
|
||||
# Regular RGB(A) input
|
||||
self.r = red
|
||||
self.g = green
|
||||
self.b = blue
|
||||
self.a = alpha
|
||||
def get(self) -> tuple[int, int, int]:
|
||||
return (self.r, self.g, self.b)
|
||||
def sub(self, n) -> tuple[int, int, int]:
|
||||
if self.r:
|
||||
r=self.r-n
|
||||
else:
|
||||
r=0
|
||||
if self.g:
|
||||
g=self.g-n
|
||||
else:
|
||||
g=0
|
||||
if self.b:
|
||||
b=self.b-n
|
||||
else:
|
||||
b=0
|
||||
return (r,g,b)
|
||||
|
||||
def multiply(self, other) -> tuple[int, int, int]:
|
||||
r = other[0]
|
||||
g = other[1]
|
||||
@@ -241,7 +275,7 @@ def make_next_board():
|
||||
]
|
||||
return next_board
|
||||
|
||||
def make_board():
|
||||
def make_board(n: int):
|
||||
board_height = 20
|
||||
board_width = 10
|
||||
|
||||
@@ -255,11 +289,13 @@ def make_board():
|
||||
|
||||
board.append(line)
|
||||
|
||||
for _ in range(board_height - 2):
|
||||
board.append([0,1,2,3,4,5,6,7,0,0])
|
||||
|
||||
for _ in range(board_height - 3):
|
||||
line = []
|
||||
|
||||
for _ in range(board_width):
|
||||
line.append(random.randint(0, 5))
|
||||
line.append(random.randint(0, n-1))
|
||||
|
||||
board.append(line)
|
||||
|
||||
@@ -283,40 +319,48 @@ def make_score():
|
||||
# green = color(0, 255, 0, 255)
|
||||
# purple = color(160, 32, 240, 255)
|
||||
# orange = color(255, 165, 0, 255)
|
||||
black = color(0, 0, 0, 255)
|
||||
white = color(255, 255, 255, 255)
|
||||
black = color("#000000")
|
||||
white = color("#ffffff")
|
||||
|
||||
red = color(255, 0, 0, 255)
|
||||
cyan = color(0, 255, 255, 255)
|
||||
red = color("#ff0000")
|
||||
cyan = color("#00ffff")
|
||||
|
||||
blue = color("#0000ff")
|
||||
yellow = color("#fff200")
|
||||
|
||||
green = color("#00ff00")
|
||||
magenta = color("#ff00ff")
|
||||
|
||||
orange = color("#ff8000")
|
||||
sky_blue = color("#0080ff")
|
||||
|
||||
purple = color("#9d00ff")
|
||||
lime = color("#5fdf5f")
|
||||
|
||||
blue = color(0, 0, 255, 255)
|
||||
yellow = color(255, 255, 0, 255)
|
||||
|
||||
green = color(0, 255, 0, 255)
|
||||
magenta = color(255, 0, 255, 255)
|
||||
|
||||
orange = color(255, 128, 0, 255)
|
||||
sky_blue = color(0, 128, 255, 255)
|
||||
|
||||
purple = color(160, 32, 240, 255)
|
||||
lime = color(64, 255, 64, 255)
|
||||
|
||||
colors = [
|
||||
black,
|
||||
red,
|
||||
cyan,
|
||||
blue,
|
||||
green,
|
||||
orange,
|
||||
purple
|
||||
yellow,
|
||||
green,
|
||||
purple,
|
||||
red
|
||||
]
|
||||
|
||||
colors2 = [
|
||||
black,
|
||||
cyan,
|
||||
yellow,
|
||||
magenta,
|
||||
sky_blue,
|
||||
lime
|
||||
color("#0086f3"),
|
||||
color("#3d4fdc"),
|
||||
color("#fdab01"),
|
||||
color("#abcb04"),
|
||||
color("#02bdcd"),
|
||||
color("#d20f63"),
|
||||
color("#fe4b0f"),
|
||||
]
|
||||
|
||||
text_bg = black
|
||||
@@ -325,17 +369,17 @@ next_board = make_next_board()
|
||||
nb1 = coord(88, 96, 128, 128)
|
||||
nb2 = coord(1064, 96, 128, 128)
|
||||
|
||||
board_height, board_width, board = make_board()
|
||||
b1 = coord(304, 40, 320, height=640)
|
||||
board2_height, board2_width, board2 = make_board()
|
||||
b2 = coord(656, 40, 320, height=640)
|
||||
board_height, board_width, board = make_board(len(colors))
|
||||
b1 = coord(304, 40, 320, 640)
|
||||
board2_height, board2_width, board2 = make_board(len(colors2))
|
||||
b2 = coord(656, 40, 320, 640)
|
||||
|
||||
score1 = make_score()
|
||||
s1 = coord(84, 454, 136, height=32)
|
||||
sn1 = coord(74, 490, 156, height=20)
|
||||
s1 = coord(84, 454, 136, 32)
|
||||
sn1 = coord(74, 490, 156, 20)
|
||||
score2 = make_score()
|
||||
s2 = coord(304, 40, 320, height=640)
|
||||
sn2 = coord(304, 40, 320, height=640)
|
||||
s2 = coord(1060, 454, 136, 32)
|
||||
sn2 = coord(1050, 490, 156, 20)
|
||||
|
||||
sprite_pixels, sprite_width, sprite_height = make_sprite()
|
||||
|
||||
@@ -356,15 +400,31 @@ for y in range(height):
|
||||
# pixels[x, y] = colors[board[yd>>5][xd>>5]].multiply(sprite_pixels[yd&0b0000000000011111, xd&0b0000000000011111])
|
||||
xs = xd&0x1F
|
||||
ys = yd&0x1F
|
||||
if (xs == 31) or (ys==31):
|
||||
if (xs == 0) or (ys == 0):
|
||||
pixels[x, y] = colors[board[yd>>5][xd>>5]].shiftr(1)
|
||||
else:
|
||||
pixels[x, y] = colors[board[yd>>5][xd>>5]].shiftr(2)
|
||||
elif (not xs) or (not ys):
|
||||
if (xs > 7 and xs < 24) and (ys > 7 and ys < 24): # middle
|
||||
pixels[x, y] = colors[board[yd>>5][xd>>5]].get()
|
||||
elif (xs > 5 and xs < 26) and (ys > 5 and ys < 26): # mid boarder
|
||||
pixels[x, y] = colors[board[yd>>5][xd>>5]].mask(0xFFFFFFB0)
|
||||
# elif xs == ys or xs+ys==31:
|
||||
# pixels[x, y] = colors[board[yd>>5][xd>>5]].shiftr(2)
|
||||
elif xs+ys<31: # top left edge
|
||||
if xs>ys:
|
||||
pixels[x, y] = colors[board[yd>>5][xd>>5]].get()
|
||||
else:
|
||||
pixels[x, y] = colors[board[yd>>5][xd>>5]].mask(0xFFFFFFEF)
|
||||
else:
|
||||
if xs>ys:
|
||||
pixels[x, y] = colors[board[yd>>5][xd>>5]].mask(0xFFFFFFD7)
|
||||
else:
|
||||
pixels[x, y] = colors[board[yd>>5][xd>>5]].mask(0xFFFFFFC0)
|
||||
# if (xs == 31) or (ys == 31):
|
||||
# if (xs == 0) or (ys == 0):
|
||||
# pixels[x, y] = colors[board[yd>>5][xd>>5]].shiftr(1)
|
||||
# else:
|
||||
# pixels[x, y] = colors[board[yd>>5][xd>>5]].shiftr(2)
|
||||
# elif (not xs) or (not ys):
|
||||
# pixels[x, y] = colors[board[yd>>5][xd>>5]].get()
|
||||
# else:
|
||||
# pixels[x, y] = colors[board[yd>>5][xd>>5]].mask(0xFFFFFFC0)
|
||||
### Next Piece
|
||||
elif x>=nb1.x and x<nb1.x+nb1.width and y>=nb1.y and y<nb1.y+nb1.height:
|
||||
xd = x-nb1.x
|
||||
@@ -395,17 +455,49 @@ for y in range(height):
|
||||
pixels[x, y] = white.get()
|
||||
else:
|
||||
pixels[x, y] = text_bg.get()
|
||||
elif x>=sn1.x and x<sn1.x+sn1.width and y>=sn1.y and y<sn1.y+sn1.height:
|
||||
pixels[x, y] = text_bg.get()
|
||||
####################### player 2
|
||||
### Board
|
||||
elif x>=b2.x and x<b2.x+b2.width and y>=b2.y and y<b2.y+b2.height:
|
||||
# xd = x-b2.x
|
||||
# yd = y-b2.y
|
||||
# pixels[x, y] = colors2[board2[yd>>5][xd>>5]].multiply(sprite_pixels[yd&0b0000000000011111, xd&0b0000000000011111])
|
||||
xd = x-b2.x
|
||||
yd = y-b2.y
|
||||
pixels[x, y] = colors[board2[yd>>5][xd>>5]].multiply(sprite_pixels[yd&0b0000000000011111, xd&0b0000000000011111])
|
||||
xs = xd&0x1F
|
||||
ys = yd&0x1F
|
||||
if (xs == 31) or (ys == 31):
|
||||
if (xs == 0) or (ys == 0):
|
||||
pixels[x, y] = colors2[board2[yd>>5][xd>>5]].shiftr(1)
|
||||
else:
|
||||
pixels[x, y] = colors2[board2[yd>>5][xd>>5]].shiftr(2)
|
||||
elif (not xs) or (not ys):
|
||||
pixels[x, y] = colors2[board2[yd>>5][xd>>5]].get()
|
||||
else:
|
||||
pixels[x, y] = colors2[board2[yd>>5][xd>>5]].mask(0xFFFFFFC0)
|
||||
### Next Piece
|
||||
elif x>=nb2.x and x<nb2.x+nb2.width and y>=nb2.y and y<nb2.y+nb2.height:
|
||||
xd = x-nb2.x
|
||||
yd = y-nb2.y
|
||||
pixels[x, y] = colors[next_board[yd>>5][xd>>5]].multiply(sprite_pixels[yd&0b0000000000011111, xd&0b0000000000011111])
|
||||
pixels[x, y] = colors2[next_board[yd>>5][xd>>5]].multiply(sprite_pixels[yd&0b0000000000011111, xd&0b0000000000011111])
|
||||
### Score
|
||||
elif x>=s2.x and x<s2.x+s2.width and y>=s2.y and y<s2.y+s2.height:
|
||||
yd = y-s2.y
|
||||
if x < (24+s2.x) and a_s[yd>>2][(x-s2.x)>>2]:
|
||||
pixels[x, y] = white.get()
|
||||
elif x<(52+s2.x) and x > (28+s2.x) and a_c[yd>>2][(x-(28+s2.x))>>2]:
|
||||
pixels[x, y] = white.get()
|
||||
elif x<(80+s2.x) and x > (56+s2.x) and a_o[yd>>2][(x-(56+s2.x))>>2]:
|
||||
pixels[x, y] = white.get()
|
||||
elif x<(108+s2.x) and x > (84+s2.x) and a_r[yd>>2][(x-(84+s2.x))>>2]:
|
||||
pixels[x, y] = white.get()
|
||||
elif x > (112+s2.x) and a_e[yd>>2][(x-(112+s2.x))>>2]:
|
||||
pixels[x, y] = white.get()
|
||||
else:
|
||||
pixels[x, y] = text_bg.get()
|
||||
elif x>=sn2.x and x<sn2.x+sn2.width and y>=sn2.y and y<sn2.y+sn2.height:
|
||||
pixels[x, y] = text_bg.get()
|
||||
# ####################### player 2
|
||||
# ### Board
|
||||
# elif x>=b2.x and x<b2.x+b2.width and y>=b2.y and y<b2.y+b2.height:
|
||||
@@ -420,31 +512,31 @@ for y in range(height):
|
||||
####################### BG
|
||||
else:
|
||||
pixels[x, y] = ((x+y)>>3,0,0)
|
||||
offset = 0
|
||||
# offset = 0
|
||||
|
||||
numbers = [a_s, n0, n1, n2, n3, n4, n5, n6, n7, n8, n9]
|
||||
for num in numbers:
|
||||
for y in range(len(num)<<2):
|
||||
for x in range(len(num[y>>2])<<2):
|
||||
if num[y>>2][x>>2]:
|
||||
pixels[x+offset, y] = white.get()
|
||||
else:
|
||||
pixels[x+offset, y] = black.get()
|
||||
offset += (len(num[0])<<2)+4
|
||||
# numbers = [a_s, n0, n1, n2, n3, n4, n5, n6, n7, n8, n9]
|
||||
# for num in numbers:
|
||||
# for y in range(len(num)<<2):
|
||||
# for x in range(len(num[y>>2])<<2):
|
||||
# if num[y>>2][x>>2]:
|
||||
# pixels[x+offset, y] = white.get()
|
||||
# else:
|
||||
# pixels[x+offset, y] = black.get()
|
||||
# offset += (len(num[0])<<2)+4
|
||||
|
||||
letters = [a_s, a_c, a_o, a_r, a_e]
|
||||
offset = 0
|
||||
# letters = [a_s, a_c, a_o, a_r, a_e]
|
||||
# offset = 0
|
||||
|
||||
base_offset = 720-32
|
||||
# base_offset = 720-32
|
||||
|
||||
for letter in letters:
|
||||
for y in range(len(letter)<<2):
|
||||
for x in range(len(letter[y>>2])<<2):
|
||||
if letter[y>>2][x>>2]:
|
||||
pixels[x+offset, y+base_offset] = white.get()
|
||||
else:
|
||||
pixels[x+offset, y+base_offset] = black.get()
|
||||
offset += (len(letter[0])<<2) + 4
|
||||
# for letter in letters:
|
||||
# for y in range(len(letter)<<2):
|
||||
# for x in range(len(letter[y>>2])<<2):
|
||||
# if letter[y>>2][x>>2]:
|
||||
# pixels[x+offset, y+base_offset] = white.get()
|
||||
# else:
|
||||
# pixels[x+offset, y+base_offset] = black.get()
|
||||
# offset += (len(letter[0])<<2) + 4
|
||||
|
||||
|
||||
|
||||
|
||||
+31
-12
File diff suppressed because one or more lines are too long
|
Before Width: | Height: | Size: 50 KiB After Width: | Height: | Size: 13 KiB |
Submodule
+1
Submodule tet-cpu-plan added at 5ffaef21b6
Reference in New Issue
Block a user