-
Notifications
You must be signed in to change notification settings - Fork 4
/
methods.py
131 lines (117 loc) · 4.84 KB
/
methods.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
from PIL import Image
import random
def setupRand(intensity):
def randy():
return random.randint(-intensity,intensity)
return randy
#TODO: think about moving each method into a function to clean up
def do_method(METHOD:str,rgba,iteration:int=1,intensity:int=50): # sourcery skip: extract-duplicate-method, low-code-quality, use-itertools-product
newData = []
if intensity==0: intensity=1 # prevents problems later on
rand = setupRand(intensity)
data = rgba.getdata()
match METHOD.lower():
case "alpha":
newData = [
(
item[0] + rand(),
item[1] + rand(), # Used fo a tiny bit of static so that you can use this more than once
item[2] + rand(),
255-iteration
) for item in data
]
case "static":
newData = [
(
item[0] + random.randint(-intensity, intensity),
item[1] + random.randint(-intensity, intensity),
item[2] + random.randint(-intensity, intensity),
item[3],
)
for item in data
]
# WIP new method (has issues i need to figure out)
# square_size = 3
# width, height = rgba.size
# static_image = Image.new('RGBA', (width, height))
# for x in range(0, width, square_size):
# for y in range(0, height, square_size):
# static_color = (random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))
# static_image.paste(static_color, (x, y, min(x + square_size, width), min(y + square_size, height)))
# data = Image.blend(static_image, rgba, 255/intensity)
# newData = data.getdata()
case "tstatic":
newData = [
(
item[0],
item[1],
item[2],
item[3] - random.randint(0, intensity),
)
for item in data
]
case "shadow":
newData = [
(
item[0] + rand(),
item[1] + rand(), # Used fo a tiny bit of static
item[2] + rand(),
item[3] - (random.randint(250,255)-round((item[0]+item[1]+item[2])/3)),
)
for item in data
]
case "light":
newData = [
(
item[0] + rand(),
item[1] + rand(), # Used fo a tiny bit of static
item[2] + rand(),
item[3] - (random.randint(250,255)-round(255-(item[0]+item[1]+item[2])/3)),
)
for item in data
]
case "test": # WIP filter method
image = rgba
width, height = image.size
for y in range(height):
for x in range(width):
r, g, b, a = image.getpixel((x, y))
r+=rand();g+=rand();b+=rand()
if y % 2 == 0: b = 0
if y % 3 == 0 or x % 3 == 0: a = 0
if x % 2 != 0:
image.putpixel((x, y), (0,g,b,a))
else:
image.putpixel((x, y), (r,0,b,a))
newData = image.getdata()
case "test2": # WIP filter method
image = rgba
width, height = image.size
count = 0
for y in range(height):
for x in range(width):
r, g, b, a = image.getpixel((x, y))
r+=rand();g+=rand();b+=rand()
count+=1
if count == 1:
g,b = 0,0
elif count == 2:
r,b = 0,0
elif count == 3:
r,g = 0,0
else:
r,g,b=0,0,0
count=0
if y % 4 == 0 or x % 4 == 0: a = round((r+g+b)/3)
image.putpixel((x, y), (r,g,b,a))
newData = image.getdata()
case "default": # Sets a random pixel
for item in data: newData.append(item)
ran = random.randint(0, len(newData))
newData[ran]=(random.randint(0,item[0]),random.randint(0,item[1]),random.randint(0,item[2]), item[3])
case _: # Default to random pixel
print('INVALID METHOD SET, DEFAULTING TO RANDOM COLOR (default) METHOD')
for item in data: newData.append(item)
ran = random.randint(0, len(newData))
newData[ran]=(random.randint(0,item[0]),random.randint(0,item[1]),random.randint(0,item[2]), item[3])
return newData