mirror of
https://github.com/freedoom/freedoom.git
synced 2025-09-06 19:25:46 -04:00
Blacken all Python files
Using the black code reformatter, pass it over all our Python files. This allows for a consistent style across the code base. Exception: lumps/dmxgus/stats.py, for readability.
This commit is contained in:
parent
6b486b6332
commit
4701d8f351
30 changed files with 2528 additions and 2102 deletions
|
@ -33,73 +33,82 @@ R3 = 1.0 / 3
|
|||
R6 = 1.0 / 6
|
||||
PI = 3.141592
|
||||
|
||||
|
||||
def ihs_to_rgb(i, h, s):
|
||||
i = (i * 422) / 255
|
||||
h = (h * 2 * PI) / 255
|
||||
s = (s * 208.2066) / 255
|
||||
i = (i * 422) / 255
|
||||
h = (h * 2 * PI) / 255
|
||||
s = (s * 208.2066) / 255
|
||||
|
||||
b, x = s * math.cos(h), s * math.sin(h)
|
||||
b, x = s * math.cos(h), s * math.sin(h)
|
||||
|
||||
return (
|
||||
R3 * i - R6 * b - R2 * x,
|
||||
R3 * i - R6 * b + R2 * x,
|
||||
R3 * i + R6 * 2 * b,
|
||||
)
|
||||
|
||||
return (R3 * i - R6 * b - R2 * x,
|
||||
R3 * i - R6 * b + R2 * x,
|
||||
R3 * i + R6 * 2 * b)
|
||||
|
||||
# New palette builder
|
||||
|
||||
|
||||
def make_pal_range(i, h, s, n):
|
||||
|
||||
map_function = lambda x: ihs_to_rgb(i * (n - x) / n,
|
||||
h,
|
||||
s * (n - x) / n),
|
||||
map_function = (lambda x: ihs_to_rgb(i * (n - x) / n, h, s * (n - x) / n),)
|
||||
|
||||
return map(map_function, range(n))
|
||||
|
||||
return map(map_function, range(n))
|
||||
|
||||
# Very crude traversal of the IHS colour ball
|
||||
|
||||
def make_palette_new():
|
||||
result = []
|
||||
|
||||
result += make_pal_range(255, 0, 0, 32)
|
||||
|
||||
for i in range(7):
|
||||
result += make_pal_range(127, 171 + (i + 1) * 256 / 7, 255, 16)
|
||||
|
||||
for i in range(7):
|
||||
result += make_pal_range(256, (i + 1) * 256 / 7, 127, 16)
|
||||
def make_palette_new():
|
||||
result = []
|
||||
|
||||
result += make_pal_range(255, 0, 0, 32)
|
||||
|
||||
for i in range(7):
|
||||
result += make_pal_range(127, 171 + (i + 1) * 256 / 7, 255, 16)
|
||||
|
||||
for i in range(7):
|
||||
result += make_pal_range(256, (i + 1) * 256 / 7, 127, 16)
|
||||
|
||||
|
||||
# Return palette read from named file
|
||||
|
||||
|
||||
def read_palette(filename):
|
||||
f = open(filename, "rb")
|
||||
f = open(filename, "rb")
|
||||
|
||||
colors = []
|
||||
colors = []
|
||||
|
||||
for i in range(256):
|
||||
data = f.read(3)
|
||||
color = struct.unpack("BBB", data)
|
||||
for i in range(256):
|
||||
data = f.read(3)
|
||||
color = struct.unpack("BBB", data)
|
||||
|
||||
colors.append(color)
|
||||
colors.append(color)
|
||||
|
||||
f.close()
|
||||
f.close()
|
||||
|
||||
return colors
|
||||
|
||||
return colors
|
||||
|
||||
def make_palette(filename):
|
||||
if filename is None:
|
||||
return make_palette_new
|
||||
else:
|
||||
return read_palette(filename)
|
||||
if filename is None:
|
||||
return make_palette_new
|
||||
else:
|
||||
return read_palette(filename)
|
||||
|
||||
|
||||
# Old palette builder
|
||||
#sub make_pal_range($$$$$$)
|
||||
#{
|
||||
# sub make_pal_range($$$$$$)
|
||||
# {
|
||||
# my ($rs,$gs,$bs,$re,$ge,$be) = @_;
|
||||
# return map { my $e = $_/16; my $s = 1-$e;
|
||||
# [$rs*$s + $re*$e, $gs*$s + $ge*$e, $bs*$s + $be * $e] } (1..16);
|
||||
#}
|
||||
# }
|
||||
#
|
||||
#sub make_palette ()
|
||||
#{
|
||||
# sub make_palette ()
|
||||
# {
|
||||
# my @p = (
|
||||
# make_pal_range(0,0,0,0,0,0), # hmmm
|
||||
# make_pal_range(255,255,255,255,0,0), # pinks
|
||||
|
@ -118,57 +127,61 @@ def make_palette(filename):
|
|||
# make_pal_range(0,0,0,0,0,0), # hmmm
|
||||
# make_pal_range(0,0,0,0,0,0)); # hmmm
|
||||
# return \@p;
|
||||
#}
|
||||
# }
|
||||
|
||||
# Now the PLAYPAL stuff - take the main palette and construct biased versions
|
||||
# for the palette translation stuff
|
||||
|
||||
# Bias an entire palette
|
||||
|
||||
|
||||
def bias_palette_towards(palette, target, p):
|
||||
def bias_rgb(rgb):
|
||||
r = []
|
||||
|
||||
def bias_rgb(rgb):
|
||||
r = []
|
||||
for i in range(3):
|
||||
r.append(rgb[i] * (1 - p) + target[i] * p)
|
||||
|
||||
for i in range(3):
|
||||
r.append(rgb[i] * (1 - p) + target[i] * p)
|
||||
return r
|
||||
|
||||
return r
|
||||
return map(bias_rgb, palette)
|
||||
|
||||
return map(bias_rgb, palette)
|
||||
|
||||
# Encode palette in the 3-byte RGB triples format expected by the engine
|
||||
|
||||
|
||||
def clamp_pixval(v):
|
||||
if v < 0:
|
||||
return 0
|
||||
elif v > 255:
|
||||
return 255
|
||||
else:
|
||||
return int(v)
|
||||
if v < 0:
|
||||
return 0
|
||||
elif v > 255:
|
||||
return 255
|
||||
else:
|
||||
return int(v)
|
||||
|
||||
|
||||
def output_palette(pal):
|
||||
|
||||
for color in palette:
|
||||
color = tuple(map(clamp_pixval, color))
|
||||
|
||||
encoded = struct.pack("BBB", *color)
|
||||
os.write(sys.stdout.fileno(), encoded)
|
||||
for color in palette:
|
||||
color = tuple(map(clamp_pixval, color))
|
||||
|
||||
encoded = struct.pack("BBB", *color)
|
||||
os.write(sys.stdout.fileno(), encoded)
|
||||
|
||||
|
||||
# Main program - make a base palette, then do the biased versions
|
||||
|
||||
if len(sys.argv) < 2:
|
||||
print("Usage: %s <base filename> > playpal.lmp" % sys.argv[0])
|
||||
sys.exit(1)
|
||||
print("Usage: %s <base filename> > playpal.lmp" % sys.argv[0])
|
||||
sys.exit(1)
|
||||
|
||||
base_pal = read_palette(sys.argv[1])
|
||||
|
||||
# From st_stuff.c, Copyright 1999 id Software, license GPL
|
||||
#define STARTREDPALS 1
|
||||
#define STARTBONUSPALS 9
|
||||
#define NUMREDPALS 8
|
||||
#define NUMBONUSPALS 4
|
||||
#define RADIATIONPAL 13
|
||||
# define STARTREDPALS 1
|
||||
# define STARTBONUSPALS 9
|
||||
# define NUMREDPALS 8
|
||||
# define NUMBONUSPALS 4
|
||||
# define RADIATIONPAL 13
|
||||
|
||||
palettes = []
|
||||
|
||||
|
@ -179,21 +192,20 @@ palettes.append(base_pal)
|
|||
# STARTREDPALS
|
||||
|
||||
for i in range(8):
|
||||
p = (i + 1) / 8.0
|
||||
p = (i + 1) / 8.0
|
||||
|
||||
palettes.append(bias_palette_towards(base_pal, (255, 0, 0), p))
|
||||
palettes.append(bias_palette_towards(base_pal, (255, 0, 0), p))
|
||||
|
||||
# STARTBONUSPALS
|
||||
|
||||
for i in range(4):
|
||||
p = (i + 1) * 0.4 / 4
|
||||
p = (i + 1) * 0.4 / 4
|
||||
|
||||
palettes.append(bias_palette_towards(base_pal, (128, 128, 128), p))
|
||||
palettes.append(bias_palette_towards(base_pal, (128, 128, 128), p))
|
||||
|
||||
# RADIATIONPAL
|
||||
|
||||
palettes.append(bias_palette_towards(base_pal, (0, 255, 0), 0.2))
|
||||
|
||||
for palette in palettes:
|
||||
output_palette(palette)
|
||||
|
||||
output_palette(palette)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue