diff --git a/.gitignore b/.gitignore index 3017c73..8fcd85e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,8 @@ output/ *.gif *.mp4 +*.png +*.jpg # ---> Python diff --git a/background.py b/background.py new file mode 100644 index 0000000..d0f1cb7 --- /dev/null +++ b/background.py @@ -0,0 +1,160 @@ +I = 1 +O = 2 +T = 3 +S = 4 +Z = 5 +J = 6 +L = 7 + +# board = [ +# [I,I,I,I,L,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], +# [S,S,L,L,L,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], +# [T,S,S,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], +# [T,T,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], +# [T,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], +# [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], +# [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], +# [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], +# [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], +# [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], +# [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], +# [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], +# [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], +# [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], +# [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], +# [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], +# [0,0,0,0,0,J,0,T,0,0,Z,Z,0,J,0,0,L,0,0,0,0,0,0,0,0,0,0,0,0,0,0,J], +# [J,0,T,T,T,J,T,T,T,Z,Z,Z,Z,J,O,O,L,0,O,O,0,0,0,0,0,Z,Z,T,T,T,T,J], +# ] + +board = [ + [0,0,0,0,0,0,0,0,0,0], + [0,0,0,0,0,0,0,0,0,0], + [0,0,0,0,0,0,0,0,0,0], + [0,0,0,0,0,0,0,0,0,0], + [0,0,0,0,0,0,0,0,0,0], + [0,0,0,0,0,O,O,0,0,0], + [0,0,0,0,0,O,O,0,0,0], + [0,0,0,0,0,0,0,0,0,0], + [0,0,0,0,0,0,0,0,0,0], + [0,0,0,0,0,0,0,0,0,0], + [0,0,0,0,0,0,0,0,0,0], + [0,0,0,0,0,0,0,0,0,0], + [0,0,0,0,0,0,0,0,0,0], + [0,0,0,0,0,0,0,0,0,0], + [0,0,0,0,0,0,0,0,0,0], + [0,0,I,0,0,0,0,0,0,0], + [O,O,I,T,0,0,0,J,J,0], + [O,O,I,T,T,L,L,J,L,0], + [O,O,I,T,I,I,L,J,L,0], + [S,S,S,S,0,S,S,S,S,S] +] + +board_width = len(board[0]) +board_height = len(board) + +class color: + 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] + b = other[2] + return (((self.r * r) >> 8), ((self.g * g) >> 8), ((self.b * b)>>8)) + def shiftr(self, n): + return ((self.r >> n), (self.g >> n), (self.b >>n)) + def mask(self, n): + return ((self.r & n), (self.g & n), (self.b & n)) + +black = color("#000000") +white = color("#ffffff") + +colors = [ + color("#000000"), + color("#00ffff"), + color("#fff200"), + color("#9d00ff"), + color("#00ff00"), + color("#ff0000"), + color("#0000ff"), + color("#ff8000") +] + +width = board_width*32 +height = board_height*32 + +from PIL import Image +img = Image.new("RGB", (width, height)) + +pixels = img.load() + +for y in range(height): + for x in range(width): + xd = x + yd = y + color_internal = colors[board[yd>>5][xd>>5]] + if board[yd>>5][xd>>5] != 0: + xs = xd&0x1F + ys = yd&0x1F + if (xs > 7 and xs < 24) and (ys > 7 and ys < 24): # middle + pixels[x, y] = color_internal.get() + elif (xs > 5 and xs < 26) and (ys > 5 and ys < 26): # mid boarder + pixels[x, y] = color_internal.mask(0xFFFFFFB0) + elif xs+ys<31: # top left edge + if xs>ys: + pixels[x, y] = color_internal.get() + else: + pixels[x, y] = color_internal.mask(0xFFFFFFEF) + else: + if xs>ys: + pixels[x, y] = color_internal.mask(0xFFFFFFD7) + else: + pixels[x, y] = color_internal.mask(0xFFFFFFC0) + else: + pixels[x, y] = (0, 0, 0) + # if (x+y)&1: + # pixels[x, y] = (0, 0, 255) + # else: + # pixels[x, y] = ((x+y)>>3, (((1280+720)>>3)-((x+y)>>3)), 0) + + +img.save("output/folie_16_background.png") +img.show() diff --git a/bg_mult.py b/bg_mult.py new file mode 100644 index 0000000..bb1e11d --- /dev/null +++ b/bg_mult.py @@ -0,0 +1,156 @@ +I = 1 +O = 2 +T = 3 +S = 4 +Z = 5 +J = 6 +L = 7 + +class color: + 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] + b = other[2] + return (((self.r * r) >> 8), ((self.g * g) >> 8), ((self.b * b)>>8)) + def shiftr(self, n): + return ((self.r >> n), (self.g >> n), (self.b >>n)) + def mask(self, n): + return ((self.r & n), (self.g & n), (self.b & n)) + +black = color("#000000") +white = color("#ffffff") + +colors = [ + color("#000000"), + color("#00ffff"), + color("#fff200"), + color("#9d00ff"), + color("#00ff00"), + color("#ff0000"), + color("#0000ff"), + color("#ff8000") +] + +base_board = [ + [I,I,I,I,L,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], + [S,S,L,L,L,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], + [T,S,S,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], + [T,T,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], + [T,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], + [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], + [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], + [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], + [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], + [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], + [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], + [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], + [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], + [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], + [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], + [0,0,0,0,0,J,0,T,0,0,Z,Z,0,J,0,0,L,0,0,0,0,0,0,0,0,0,0,0,0,0,0,J], + [J,0,T,T,T,J,T,T,T,Z,Z,Z,Z,J,O,O,L,0,O,O,0,0,0,0,0,Z,Z,T,0,0,0,J], + [J,J,J,T,J,J,I,I,I,I,Z,Z,J,J,O,O,L,L,O,O,I,I,I,I,Z,Z,T,T,T,0,J,J] +] + +next_piece = [ + [T,T,T], + [0,T,0] +] + +coord = 28 + +board_width = len(base_board[0]) +board_height = len(base_board) + +width = board_width*32 +height = board_height*32 + +from PIL import Image +img2 = Image.open("output.jpg") +pixels2 = img2.load() + +for t in range(len(base_board)-1): + img = Image.new("RGB", (width, height)) + pixels = img.load() + + board = [row[:] for row in base_board] + + for i in range(len(next_piece)): + i_int = i + t + for j in range(len(next_piece[i])): + j_int = j + coord + if board[i_int][j_int] == 0: + board[i_int][j_int] = next_piece[i][j] + + for y in range(height): + for x in range(width): + xd = x + yd = y + color_internal = colors[board[yd>>5][xd>>5]] + if board[yd>>5][xd>>5] != 0: + xs = xd&0x1F + ys = yd&0x1F + if (xs > 7 and xs < 24) and (ys > 7 and ys < 24): # middle + pixels[x, y] = color_internal.get() + elif (xs > 5 and xs < 26) and (ys > 5 and ys < 26): # mid boarder + pixels[x, y] = color_internal.mask(0xFFFFFFB0) + elif xs+ys<31: # top left edge + if xs>ys: + pixels[x, y] = color_internal.get() + else: + pixels[x, y] = color_internal.mask(0xFFFFFFEF) + else: + if xs>ys: + pixels[x, y] = color_internal.mask(0xFFFFFFD7) + else: + pixels[x, y] = color_internal.mask(0xFFFFFFC0) + else: + # if (x+y)&1: + # pixels[x, y] = (0, 0, 255) + # else: + pixels[x, y] = pixels2[x, y]# ((x+y)>>2, (((1280+720)>>2)-((x+y)>>2)), 255) + + + img.save(f"output/folie_{t}_background.png") + if t == 1: + img.show() diff --git a/gpu.py b/gpu.py index 960f808..590b921 100644 --- a/gpu.py +++ b/gpu.py @@ -316,10 +316,10 @@ class coord: def make_next_board(): next_board = [ + [0, 0, 0, 0], + [1, 1, 1, 1], [0, 0, 0, 0], [0, 0, 0, 0], - [0, 1, 0, 0], - [1, 1, 1, 0], ] return next_board @@ -384,42 +384,109 @@ lime = color("#5fdf5f") colors = [ black, cyan, - blue, - orange, yellow, - green, purple, - red + green, + red, + blue, + orange ] -colors2 = [ - black, - color("#0086f3"), - color("#3d4fdc"), - color("#fdab01"), - color("#abcb04"), - color("#02bdcd"), - color("#d20f63"), - color("#fe4b0f"), -] +I=1 +O=2 +T=3 +S=4 +Z=5 +J=6 +L=7 + +colors2 = colors +# colors2 = [ +# black, +# color("#0086f3"), +# color("#3d4fdc"), +# color("#fdab01"), +# color("#abcb04"), +# color("#02bdcd"), +# color("#d20f63"),Z +# color("#fe4b0f"), +# ] text_bg = black -next_board = make_next_board() +# next_board = make_next_board() +next_board = [ + [0, 0, T, 0], + [0, T, T, T], + [0, 0, 0, 0], + [0, 0, 0, 0], + ] nb1 = coord(88, 104, 128, 128) -next_board1 = make_next_board() +# next_board1 = make_next_board() +next_board1 = [ + [0, 0, 0, L], + [0, L, L, L], + [0, 0, 0, 0], + [0, 0, 0, 0], + ] nb2 = coord(1064, 104, 128, 128) -board_height, board_width, board = make_board(len(colors)) +board_height, board_width, _ = make_board(len(colors)) +board = [ + [0,0,0,0,0,0,0,0,0,0], + [0,0,0,0,0,0,0,J,J,0], + [0,0,0,0,0,0,0,J,0,0], + [0,0,0,0,0,0,0,J,0,0], + [0,0,0,0,0,0,0,0,0,0], + [0,0,0,0,0,0,0,0,0,0], + [0,0,0,0,0,0,0,0,0,0], + [0,0,0,0,0,0,0,0,0,0], + [0,0,0,0,0,0,0,0,0,0], + [0,0,0,0,0,0,0,0,0,0], + [0,0,0,0,0,0,0,0,0,0], + [0,0,0,0,0,0,0,0,0,0], + [0,0,0,0,0,0,0,0,0,0], + [0,0,0,0,0,0,0,0,0,0], + [0,0,0,0,0,0,0,0,0,0], + [0,0,0,0,0,0,0,0,0,0], + [0,0,I,0,0,0,0,0,0,0], + [O,O,I,I,I,0,0,0,0,0], + [O,O,I,I,I,L,L,0,L,0], + [O,O,I,I,I,I,L,0,L,0] +] b1 = coord(304, 40, 320, 640) -board2_height, board2_width, board2 = make_board(len(colors2)) +board2_height, board2_width, _ = make_board(len(colors2)) +board2 = [ + [0,0,0,0,0,0,0,0,0,0], + [0,0,0,0,0,0,0,0,0,0], + [0,0,0,0,0,0,0,0,0,0], + [0,0,0,Z,0,0,0,0,0,0], + [0,0,Z,Z,0,0,0,0,0,0], + [0,0,Z,0,0,0,0,0,0,0], + [0,0,0,0,0,0,0,0,0,0], + [0,0,0,0,0,0,0,0,0,0], + [0,0,0,0,0,0,0,0,0,0], + [0,0,0,0,0,0,0,0,0,0], + [0,0,0,0,0,0,0,0,0,0], + [0,0,0,0,0,0,0,0,0,0], + [0,0,0,0,0,0,0,0,0,0], + [0,0,0,0,0,0,0,0,0,0], + [0,0,0,0,0,0,0,0,0,0], + [O,O,0,0,0,O,O,J,J,J], + [O,O,0,O,O,O,O,Z,Z,J], + [J,0,S,S,Z,Z,I,I,I,I], + [S,Z,Z,T,I,J,J,Z,Z,0], + [S,S,Z,Z,I,J,0,0,Z,Z] +] b2 = coord(656, 40, 320, 640) -score0 = make_score() +# score0 = make_score() +score0 = 299 +score1 = 298 s1 = coord(84, 332, 136, 32) sn1 = coord(74, 368, 156, 20) -score1 = make_score() +# score1 = make_score() s2 = coord(1060, 332, 136, 32) sn2 = coord(1050, 368, 156, 20) @@ -443,7 +510,28 @@ img = Image.new("RGB", (width, height)) pixels = img.load() -menu = 1 +menu = 0 + +menu_active0 = [1,0,0,0] +menu_active1 = [0,1,0,0] +menu_active2 = [1,0] + +def menu_get (side, i) -> tuple[int, int, int] | color | None: + if side == "left": + if menu_active0[i] == 0: + return white.get() + else: + return red.get() + elif side == "right": + if menu_active1[i] == 0: + return white.get() + else: + return red.get() + elif side == "middle": + if menu_active2[i] == 0: + return white + else: + return yellow for y in range(height): for x in range(width): @@ -460,9 +548,9 @@ for y in range(height): ys = yd >> 3 if x > mm0.x+3 and y>mm0.y+3 and xd> 3)-ys)<<1 and xs >2: - pixels[x, y] = (255,255,255) + pixels[x, y] = menu_get ("middle", 0).get() elif (xs == ys*2 or xs==((mm0.width-8 >> 3)-ys)<<1) and xs >2 and xs <14: - pixels[x, y] = (32,32,32) + pixels[x, y] = menu_get("middle", 0).shiftr(3) else: pixels[x, y] = black.get() else: @@ -476,30 +564,30 @@ for y in range(height): if x > mm1.x+3 and y>mm1.y+3 and xd 4: # left - pixels[x, y] = white.get() + pixels[x, y] = menu_get("middle", 1).get() elif xs == 11 and ys < 8 and ys > 4: # right - pixels[x, y] = white.get() + pixels[x, y] = menu_get("middle", 1).get() elif ys == 2 and xs < 10 and xs > 4: # top - pixels[x, y] = white.get() + pixels[x, y] = menu_get("middle", 1).get() elif ys == 12 and xs < 10 and xs > 4: # bot - pixels[x, y] = white.get() + pixels[x, y] = menu_get("middle", 1).get() # Orthogonal elif xs+ys == 7 and xs >1 and ys >1: # top left - pixels[x, y] = white.get() + pixels[x, y] = menu_get("middle", 1).get() elif xs+ys == 21 and xs >8 and ys >9: # bot right - pixels[x, y] = white.get() + pixels[x, y] = menu_get("middle", 1).get() elif ys-xs == 7 and xs < 6 and ys > 8: # bot left - pixels[x, y] = white.get() + pixels[x, y] = menu_get("middle", 1).get() elif xs-ys == 7 and xs > 8 and ys < 5: # top right - pixels[x, y] = white.get() + pixels[x, y] = menu_get("middle", 1).get() # Arrow Head elif xs-ys == 4 and xs > 8 and xs < 12: # left - pixels[x, y] = white.get() + pixels[x, y] = menu_get("middle", 1).get() elif xs+ys == 18 and xs > 10 and xs <14: # right - pixels[x, y] = white.get() + pixels[x, y] = menu_get("middle", 1).get() # Aliasing elif (xs==ys==11) or (xs==ys==3) or (xs==11 and ys==3) or (xs==3 and ys==11): - pixels[x, y] = (32,32,32) + pixels[x, y] = menu_get("middle", 1).shiftr(3) else: pixels[x, y] = black.get() else: @@ -590,33 +678,33 @@ for y in range(height): yd = y-lm0.y xs = xd-34 if xd < (24) and a_p[yd>>2][xd>>2]: - pixels[x, y] = white.get() + pixels[x, y] = menu_get("left", 0) elif xd > (33) and a_1[yd>>2][xs>>2]: - pixels[x, y] = white.get() + pixels[x, y] = menu_get("left", 0) elif x >= lm1.x and x < (lm1.x + lm1.width) and y >= lm1.y and y < (lm1.y + lm1.height): xd = x-lm1.x yd = y-lm1.y xs = xd-34 if xd < (24) and a_p[yd>>2][xd>>2]: - pixels[x, y] = white.get() + pixels[x, y] = menu_get("left", 1) elif xd > (33) and a_2[yd>>2][xs>>2]: - pixels[x, y] = white.get() + pixels[x, y] = menu_get("left", 1) elif x >= lm2.x and x < (lm2.x + lm2.width) and y >= lm2.y and y < (lm2.y + lm2.height): xd = x-lm2.x yd = y-lm2.y xs = xd-28 if xd < (24) and a_s[yd>>2][xd>>2]: - pixels[x, y] = white.get() + pixels[x, y] = menu_get("left", 2) elif xd > (27) and a_w[yd>>2][xs>>2]: - pixels[x, y] = white.get() + pixels[x, y] = menu_get("left", 2) elif x >= lm3.x and x < (lm3.x + lm3.width) and y >= lm3.y and y < (lm3.y + lm3.height): xd = x-lm3.x yd = y-lm3.y xs = xd-28 if xd < (24) and a_h[yd>>2][xd>>2]: - pixels[x, y] = white.get() + pixels[x, y] = menu_get("left", 3) elif xd > (27) and a_w[yd>>2][xs>>2]: - pixels[x, y] = white.get() + pixels[x, y] = menu_get("left", 3) ####################### Right Board ### Board elif x>=b2.x and x=b2.y and y>2][xd>>2]: - pixels[x, y] = white.get() + pixels[x, y] = menu_get("right", 0) elif xd > (33) and a_1[yd>>2][xs>>2]: - pixels[x, y] = white.get() + pixels[x, y] = menu_get("right", 0) elif x >= rm1.x and x < (rm1.x + rm1.width) and y >= rm1.y and y < (rm1.y + rm1.height): xd = x-rm1.x yd = y-rm1.y xs = xd-34 if xd < (24) and a_p[yd>>2][xd>>2]: - pixels[x, y] = white.get() + pixels[x, y] = menu_get("right", 1) elif xd > (33) and a_2[yd>>2][xs>>2]: - pixels[x, y] = white.get() + pixels[x, y] = menu_get("right", 1) elif x >= rm2.x and x < (rm2.x + rm2.width) and y >= rm2.y and y < (rm2.y + rm2.height): xd = x-rm2.x yd = y-rm2.y xs = xd-28 if xd < (24) and a_s[yd>>2][xd>>2]: - pixels[x, y] = white.get() + pixels[x, y] = menu_get("right", 2) elif xd > (27) and a_w[yd>>2][xs>>2]: - pixels[x, y] = white.get() + pixels[x, y] = menu_get("right", 2) elif x >= rm3.x and x < (rm3.x + rm3.width) and y >= rm3.y and y < (rm3.y + rm3.height): xd = x-rm3.x yd = y-rm3.y xs = xd-28 if xd < (24) and a_h[yd>>2][xd>>2]: - pixels[x, y] = white.get() + pixels[x, y] = menu_get("right", 3) elif xd > (27) and a_w[yd>>2][xs>>2]: - pixels[x, y] = white.get() + pixels[x, y] = menu_get("right", 3) img.save("output/alpha.png") img.show() diff --git a/graph.py b/graph.py new file mode 100644 index 0000000..984244a --- /dev/null +++ b/graph.py @@ -0,0 +1,91 @@ +import matplotlib.pyplot as plt +import matplotlib.patheffects as path_effects +import matplotlib.ticker as ticker + +# ========================================== +# 0. HELPER FUNCTION +# ========================================== +def format_val(x, pos=None): + """Formats numbers to k/M format for axes and labels""" + if x >= 1_000_000: + return f"{x/1_000_000:.1f}".replace('.0', '') + 'M' + elif x >= 1000: + return f"{x/1000:.1f}".replace('.0', '') + 'k' + return str(int(x)) + +# ========================================== +# 1. EDIT YOUR DATA HERE +# ========================================== +labels = ['Tetris AI test CPU', 'tet_cpu_per_row', '4 tet_cpu_per_row'] +values = [41700, 909000, 909000*4] # e.g., Speed, FPS, Transactions per second (Higher is better) + +# Define your unit here (add a space at the start so it looks clean) +unit_label = "Moves per Second [Moves/sec]" + +brand_color = '#00E5FF' +competitor_color = '#888888' + +multiplier = values[1] / values[0] +max_val = max(values) +black_outline = [path_effects.withStroke(linewidth=3, foreground='black')] + +# ========================================== +# 2. SETUP FIGURE +# ========================================== +fig, ax = plt.subplots(figsize=(10, 4.5)) +fig.patch.set_alpha(0.0) +ax.patch.set_alpha(0.0) + +bars = ax.barh(labels, values, color=[competitor_color, brand_color], height=0.45, zorder=3) + +# ========================================== +# 3. CONFIGURE AXES +# ========================================== +# X-Axis Tick Formatting (The requested change) +ax.xaxis.set_major_formatter(ticker.FuncFormatter(format_val)) + +for spine in ax.spines.values(): + spine.set_visible(False) +ax.spines['bottom'].set_visible(True) +ax.spines['bottom'].set_color('white') +ax.spines['bottom'].set_path_effects(black_outline) + +ax.tick_params(axis='both', colors='white', labelsize=12) +for label in ax.get_xticklabels() + ax.get_yticklabels(): + label.set_path_effects(black_outline) + +ax.xaxis.grid(True, linestyle='--', color='white', alpha=0.3, zorder=0) + +xlabel = ax.set_xlabel(unit_label, color='white', fontsize=12, labelpad=12, fontfamily='monospace') +xlabel.set_path_effects(black_outline) + +# ========================================== +# 4. ADD BAR LABELS & BRACKET +# ========================================== +for bar, val in zip(bars, values): + width = bar.get_width() + txt = ax.text(width - (max_val * 0.02) if width >= (max_val*0.15) else width + (max_val*0.02), + bar.get_y() + bar.get_height()/2, + format_val(val), + ha='right' if width >= (max_val*0.15) else 'left', + va='center', color='white', fontsize=14, fontweight='bold') + txt.set_path_effects(black_outline) + +# Draw Bracket +y0, y1 = [b.get_y() + b.get_height()/2 for b in bars] +x_line, x_tick = max_val * 1.05, max_val * 1.02 +for x, y in zip([x_tick, x_tick, x_line], [y1, y0, [y0, y1]]): + l, = ax.plot([x_tick, x_line] if isinstance(y, (float, int)) else [x_line, x_line], + [y, y] if isinstance(y, (float, int)) else y, color=brand_color, lw=2) + l.set_path_effects(black_outline) + +multiplier_txt = ax.text(x_line + (max_val * 0.03), (y0+y1)/2, f'{multiplier:.1f}x\nFASTER', + ha='left', va='center', color=brand_color, fontsize=22, fontweight='heavy') +multiplier_txt.set_path_effects(black_outline) + +ax.set_xlim(0, max_val * 1.45) +plt.tight_layout() +plt.subplots_adjust(bottom=0.2) + +plt.savefig('final_graph.png', dpi=300, bbox_inches='tight', transparent=True) +plt.show() \ No newline at end of file diff --git a/graph2.py b/graph2.py new file mode 100644 index 0000000..7a72ec4 --- /dev/null +++ b/graph2.py @@ -0,0 +1,92 @@ +import matplotlib.pyplot as plt +import matplotlib.patheffects as path_effects +import matplotlib.ticker as ticker + +# ========================================== +# 0. HELPER FUNCTION +# ========================================== +def format_val(x, pos=None): + """Formats numbers to k/M format for axes and labels""" + if x >= 1_000_000: + return f"{x/1_000_000:.1f}".replace('.0', '') + 'M' + elif x >= 1000: + return f"{x/1000:.1f}".replace('.0', '') + 'k' + return str(int(x)) + +# ========================================== +# 1. EDIT YOUR DATA HERE +# ========================================== +labels = ['Tetris AI test CPU', 'tet_cpu_per_row', '4 tet_cpu_per_row'] +values = [41700, 909000, 909000*4] # e.g., Speed, FPS, Transactions per second (Higher is better) + +# Define your unit here (add a space at the start so it looks clean) +unit_label = "Moves per Second [Moves/sec]" + +# Style choices +brand_color = '#00E5FF' +competitor_color = '#888888' + +max_val = max(values) +# Bracket will compare the first and last (or you can change these indices) +start_val, end_val = values[0], values[-1] +multiplier = end_val / start_val + +black_outline = [path_effects.withStroke(linewidth=3, foreground='black')] + +# ========================================== +# 2. SETUP & DYNAMIC PLOTTING +# ========================================== +fig, ax = plt.subplots(figsize=(10, 6)) # Increased height for more labels +fig.patch.set_alpha(0.0) +ax.patch.set_alpha(0.0) + +# Create color list: grey for all, brand_color for the last one +colors = [competitor_color] * (len(values) - 1) + [brand_color] +bars = ax.barh(labels, values, color=colors, height=0.5, zorder=3) + +# Configure Axis +ax.xaxis.set_major_formatter(ticker.FuncFormatter(format_val)) +for spine in ax.spines.values(): spine.set_visible(False) +ax.spines['bottom'].set_visible(True) +ax.spines['bottom'].set_color('white') +ax.spines['bottom'].set_path_effects(black_outline) + +ax.tick_params(axis='both', colors='white', labelsize=12) +for label in ax.get_xticklabels() + ax.get_yticklabels(): + label.set_path_effects(black_outline) + +ax.xaxis.grid(True, linestyle='--', color='white', alpha=0.3, zorder=0) +xlabel = ax.set_xlabel(unit_label, color='white', fontsize=12, labelpad=12, fontfamily='monospace') +xlabel.set_path_effects(black_outline) + +# Add Labels for each bar +for bar, val in zip(bars, values): + width = bar.get_width() + txt = ax.text(width - (max_val * 0.02) if width >= (max_val*0.15) else width + (max_val*0.02), + bar.get_y() + bar.get_height()/2, + format_val(val), + ha='right' if width >= (max_val*0.15) else 'left', + va='center', color='white', fontsize=12, fontweight='bold') + txt.set_path_effects(black_outline) + +# ========================================== +# 3. DYNAMIC BRACKET (First vs Last) +# ========================================== +y_start, y_end = bars[0].get_y() + bars[0].get_height()/2, bars[-1].get_y() + bars[-1].get_height()/2 +x_line, x_tick = max_val * 1.10, max_val * 1.07 # Shifted further right to accommodate N items + +l1, = ax.plot([x_tick, x_line], [y_end, y_end], color=brand_color, lw=2) +l2, = ax.plot([x_tick, x_line], [y_start, y_start], color=brand_color, lw=2) +l3, = ax.plot([x_line, x_line], [y_start, y_end], color=brand_color, lw=2) +for l in [l1, l2, l3]: l.set_path_effects(black_outline) + +mult_txt = ax.text(x_line + (max_val * 0.03), (y_start+y_end)/2, + f'{multiplier:.1f}x\nFASTER', + ha='left', va='center', color=brand_color, fontsize=18, fontweight='heavy') +mult_txt.set_path_effects(black_outline) + +ax.set_xlim(0, max_val * 1.5) +plt.tight_layout() +plt.subplots_adjust(bottom=0.2) +plt.savefig('dynamic_comparison.png', dpi=300, transparent=True) +plt.show() \ No newline at end of file diff --git a/test.py b/test.py index 0c7bb8b..c31a310 100644 --- a/test.py +++ b/test.py @@ -1,12 +1,21 @@ -import random +import os +import cv2 +import numpy as np from PIL import Image -width = 1280 -height = 720 +width = 200 +height = 400 +fps = 30 # Frames per second +total_frames = 240 # Increased to actually see the animation move -img = Image.new("RGB", (width, height)) +# Ensure output directory exists +os.makedirs("output", exist_ok=True) -pixels = img.load() +# Define the VideoWriter +# 'mp4v' is a widely supported MP4 codec +fourcc = cv2.VideoWriter_fourcc(*"mp4v") +video_path = "output/rainbow.mp4" +video = cv2.VideoWriter(video_path, fourcc, fps, (width, height)) colors = ( (0xFF, 0x00, 0x00), @@ -16,37 +25,30 @@ colors = ( (0x00, 0xFF, 0xFF), (0x00, 0x00, 0xFF), (0x8B, 0x00, 0xFF), - (0xFF, 0x00, 0xFF) -) -colors2 = ( - (0xFF,0x00,0x00), - (0xFF,0x40,0x00), - (0xFF,0x80,0x00), - (0xFF,0xBF,0x00), - (0xFF,0xFF,0x00), - (0xBF,0xFF,0x00), - (0x80,0xFF,0x00), - (0x00,0xFF,0x00), - (0x00,0xFF,0x80), - (0x00,0xFF,0xFF), - (0x00,0x80,0xFF), - (0x00,0x00,0xFF), - (0x40,0x00,0xFF), - (0x80,0x00,0xFF), - (0xFF,0x00,0xFF), - (0xFF,0x00,0x80) + (0xFF, 0x00, 0xFF), ) -for y in range(height): - for x in range(width): - pixels[x, y] = colors[((x+y)>>4)&7] +img = Image.new("RGB", (width, height)) +pixels = img.load() -img.save("output/rainbow.png") -img.show() +frame_num = 0 +while frame_num < total_frames: + for y in range(height): + for x in range(width): + # Adjusted the bit-shift so the animation moves visibly frame-by-frame + pixels[x, y] = colors[((x + y + (frame_num >> 1)) >> 4) & 7] -for y in range(height): - for x in range(width): - pixels[x, y] = colors2[((x+y)>>4)&15] + # 1. Convert PIL Image to a NumPy array + frame_np = np.array(img) -img.save("output/rainbow2.png") -img.show() \ No newline at end of file + # 2. Convert RGB (PIL format) to BGR (OpenCV format) + frame_bgr = cv2.cvtColor(frame_np, cv2.COLOR_RGB2BGR) + + # 3. Write the frame to the video file + video.write(frame_bgr) + + frame_num += 1 + +# Crucial: Release the video writer to finalize and save the file +video.release() +print(f"Video saved successfully to {video_path}") \ No newline at end of file