Compare commits
3
Commits
fe9072221b
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ede364bdbe | ||
|
|
c050194be4 | ||
|
|
4503f99135 |
@@ -1,6 +1,8 @@
|
||||
output/
|
||||
*.gif
|
||||
*.mp4
|
||||
*.png
|
||||
*.jpg
|
||||
|
||||
|
||||
# ---> Python
|
||||
|
||||
+171
@@ -0,0 +1,171 @@
|
||||
import math
|
||||
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,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,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,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,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],
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,Z,S,L,L,L,J,I,I,I,I,0,J,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] = (int((x + y) * 255 / ((width - 1) + (height - 1))), int((1 - (x + y) / (width + height - 2)) * 255), 0)
|
||||
|
||||
|
||||
img.save("output/folie_16_background.png")
|
||||
img.show()
|
||||
+165
@@ -0,0 +1,165 @@
|
||||
import math
|
||||
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,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,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,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,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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,T,S,O,O,L,L,Z,Z,S,L,L,L,J,I,I,I,I,0,J,J]
|
||||
]
|
||||
|
||||
next_piece = [
|
||||
[T,T,T],
|
||||
[0,T,0]
|
||||
]
|
||||
|
||||
coord = 44
|
||||
|
||||
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[math.floor(x/1.5), math.floor(y/1.5)]#((x+y)>>2, (((1280+720)>>2)-((x+y)>>2)), 255)
|
||||
#
|
||||
|
||||
img.save(f"output/folie_{t}_background.png")
|
||||
if t == 1:
|
||||
img.show()
|
||||
@@ -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<mm0.width-4 and yd<mm0.height-4:
|
||||
if xs <ys*2 and xs<((mm0.width-8 >> 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<mm1.width-8 and yd<mm1.height-8:
|
||||
# vert/horizontal
|
||||
if xs == 2 and ys < 10 and ys > 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.x+b2.width and y>=b2.y and y<b2.y+b2.height:
|
||||
@@ -702,33 +790,33 @@ for y in range(height):
|
||||
yd = y-rm0.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", 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()
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
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
|
||||
# ==========================================
|
||||
# Define primary labels and subtext descriptions
|
||||
labels_main = ['Bitboard Tetris', 'TET-CPU']
|
||||
subtexts = ['AMD R7-7735H', '50Mhz']
|
||||
|
||||
# Combine them with newline characters
|
||||
labels = [f"{main}\n{sub}" for main, sub in zip(labels_main, subtexts)]
|
||||
|
||||
values = [41700, 909000] # 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
|
||||
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)
|
||||
|
||||
# Set base size for x-axis ticks
|
||||
ax.tick_params(axis='x', colors='white', labelsize=12)
|
||||
|
||||
# Set larger font size specifically for Y-axis labels (Option 1)
|
||||
ax.tick_params(axis='y', colors='white', labelsize=18)
|
||||
|
||||
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)
|
||||
|
||||
# Set x-axis limit to end around 1.1M
|
||||
ax.set_xlim(0, 1_100_000)
|
||||
|
||||
plt.tight_layout()
|
||||
plt.subplots_adjust(bottom=0.2)
|
||||
|
||||
plt.savefig('final_graph.png', dpi=300, bbox_inches='tight', transparent=True)
|
||||
plt.show()
|
||||
@@ -0,0 +1,145 @@
|
||||
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_main = ['RTX 40 Series¹', 'RTX 40 Series²', 'RTX 40 Series²', '4 TET-FPGA', '4 TET-FPGA'][::-1]
|
||||
subtexts = ['60FPS', '60FPS', '360FPS', '60FPS (Worst-Case)', '60FPS'][::-1]
|
||||
note = ['competitor', 'competitor', 'competitor', 'ours', 'ours'][::-1]
|
||||
|
||||
invert_faster = False
|
||||
invert_ours = True
|
||||
|
||||
# Combine main titles and subtexts with newline characters
|
||||
labels = [f"{main}\n{sub}" for main, sub in zip(labels_main, subtexts)]
|
||||
|
||||
values = [57, 35, 17, 24.8, 12.8][::-1] # Base values (e.g., Delay Part 1)
|
||||
values_extra = [0, 0, 0, 25, 17][::-1] # Extra add-on values (e.g., Delay Part 2)
|
||||
|
||||
# Define your unit here (add a space at the start so it looks clean)
|
||||
unit_label = "Delay in [ms]"
|
||||
|
||||
# Style choices
|
||||
brand_color = '#00E5FF'
|
||||
competitor_color = '#00FF00'
|
||||
extra_color = '#FF0000' # Color for extra segments (ours)
|
||||
extra_color_extra = "#0E0E0E" # Color for extra segments (competitor)
|
||||
|
||||
black_outline = [path_effects.withStroke(linewidth=3, foreground='black')]
|
||||
|
||||
# ==========================================
|
||||
# 2. SETUP & DYNAMIC PLOTTING
|
||||
# ==========================================
|
||||
fig, ax = plt.subplots(figsize=(10, 6))
|
||||
fig.patch.set_alpha(0.0)
|
||||
ax.patch.set_alpha(0.0)
|
||||
|
||||
# Create color lists dynamically based on the 'note' array
|
||||
colors = [brand_color if n == 'ours' else competitor_color for n in note]
|
||||
extra_colors = [extra_color if n == 'ours' else extra_color_extra for n in note]
|
||||
|
||||
# Plot base bars and stacked extra bars
|
||||
bars_base = ax.barh(labels, values, color=colors, height=0.5, zorder=3)
|
||||
bars_extra = ax.barh(labels, values_extra, left=values, color=extra_colors, height=0.5, zorder=3)
|
||||
|
||||
# Calculate total combined values for limits and bracket positioning
|
||||
total_values = [v + e for v, e in zip(values, values_extra)]
|
||||
max_val = max(total_values)
|
||||
|
||||
# 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='x', colors='white', labelsize=12)
|
||||
ax.tick_params(axis='y', colors='white', labelsize=18)
|
||||
|
||||
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 and text inside/outside the extra segment
|
||||
for bar_base, bar_ext, v_base, v_ext in zip(bars_base, bars_extra, values, values_extra):
|
||||
base_width = bar_base.get_width()
|
||||
extra_width = bar_ext.get_width()
|
||||
total_width = base_width + extra_width
|
||||
|
||||
if v_ext > 0:
|
||||
# 1. Label at the very end of the total bar (just base+extra numbers)
|
||||
end_txt = ax.text(total_width + (max_val * 0.02),
|
||||
bar_base.get_y() + bar_base.get_height()/2,
|
||||
f"{format_val(total_width)} ({format_val(v_base)}+{format_val(v_ext)})",
|
||||
ha='left',
|
||||
va='center', color='white', fontsize=10, fontweight='bold')
|
||||
end_txt.set_path_effects(black_outline)
|
||||
|
||||
# 2. Text "[Peripherals]" centered horizontally inside the red/extra bar segment
|
||||
mid_extra_x = base_width + (extra_width / 2.0)
|
||||
in_txt = ax.text(mid_extra_x,
|
||||
bar_base.get_y() + bar_base.get_height()/2,
|
||||
"[Peripherals]",
|
||||
ha='center',
|
||||
va='center', color='white', fontsize=9, fontweight='bold')
|
||||
in_txt.set_path_effects(black_outline)
|
||||
else:
|
||||
# Standard label for bars without an extra segment
|
||||
end_txt = ax.text(total_width + (max_val * 0.02),
|
||||
bar_base.get_y() + bar_base.get_height()/2,
|
||||
format_val(total_width),
|
||||
ha='left',
|
||||
va='center', color='white', fontsize=10, fontweight='bold')
|
||||
end_txt.set_path_effects(black_outline)
|
||||
|
||||
# ==========================================
|
||||
# 3. DYNAMIC BRACKET (First vs Last based on totals)
|
||||
# ==========================================
|
||||
y_start = bars_base[0].get_y() + bars_base[0].get_height()/2
|
||||
y_end = bars_base[-1].get_y() + bars_base[-1].get_height()/2
|
||||
x_line, x_tick = max_val * 1.15, max_val * 1.12
|
||||
|
||||
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)
|
||||
|
||||
start_val, end_val = values[0], values[-1]
|
||||
multiplier = end_val / start_val
|
||||
|
||||
if (invert_faster):
|
||||
mult_txt = ax.text(x_line + (max_val * 0.03), (y_start+y_end)/2,
|
||||
f'{(1/multiplier):.1f}x\nFASTER',
|
||||
ha='left', va='center', color=brand_color, fontsize=18, fontweight='heavy')
|
||||
else:
|
||||
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)
|
||||
|
||||
# Set x-axis limit to comfortably fit the stacked bars, labels, and bracket
|
||||
ax.set_xlim(0, max_val * 1.40)
|
||||
|
||||
plt.tight_layout()
|
||||
plt.subplots_adjust(bottom=0.2)
|
||||
plt.savefig('dynamic_comparison.png', dpi=300, transparent=True)
|
||||
plt.show()
|
||||
@@ -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):
|
||||
img = Image.new("RGB", (width, height))
|
||||
pixels = img.load()
|
||||
|
||||
frame_num = 0
|
||||
while frame_num < total_frames:
|
||||
for y in range(height):
|
||||
for x in range(width):
|
||||
pixels[x, y] = colors[((x+y)>>4)&7]
|
||||
# Adjusted the bit-shift so the animation moves visibly frame-by-frame
|
||||
pixels[x, y] = colors[((x + y + (frame_num >> 1)) >> 4) & 7]
|
||||
|
||||
img.save("output/rainbow.png")
|
||||
img.show()
|
||||
# 1. Convert PIL Image to a NumPy array
|
||||
frame_np = np.array(img)
|
||||
|
||||
for y in range(height):
|
||||
for x in range(width):
|
||||
pixels[x, y] = colors2[((x+y)>>4)&15]
|
||||
# 2. Convert RGB (PIL format) to BGR (OpenCV format)
|
||||
frame_bgr = cv2.cvtColor(frame_np, cv2.COLOR_RGB2BGR)
|
||||
|
||||
img.save("output/rainbow2.png")
|
||||
img.show()
|
||||
# 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}")
|
||||
Reference in New Issue
Block a user