-
Notifications
You must be signed in to change notification settings - Fork 0
/
noiseTest.py
78 lines (62 loc) · 1.88 KB
/
noiseTest.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
# noiseTest.py
# made by Laban Lundquist
from PIL import Image
import random, time
class cell:
def __init__(self, color=(0)):
self.color = color
def addTuples(arg1, arg2):
return (arg1[0] + arg2[0], arg1[1] + arg2[1])
try:
resolutionInput = int(input("Resolution: "))
resolution = (resolutionInput, resolutionInput)
except:
resolution = (64, 64)
resolution = addTuples(resolution, (40, 40))
# start timer
t1 = time.time()
cells = {}
for w in range(resolution[0]):
for h in range(resolution[1]):
cells[(w, h)] = cell(0)
img = Image.new("L", (resolution[0], resolution[1]), 0)
try:
density = int(input("Density (higher numbers will result in lower densities, lowest is 1): "))
if density == 0: density = 1
except:
density = 0
for w in range(resolution[0]):
for h in range(resolution[1]):
if random.randint(0, density) == 0:
cells[(w, h)].color = 255
offsets = (
(-1, 1),
(0, 1),
(1, 1),
(1, 0),
(1, -1),
(0, -1),
(-1, -1),
(-1, 0)
)
intensity = int(input("Intensity: "))
for _ in range(intensity):
for w in range(resolution[0]):
for h in range(resolution[1]):
for i in range(8):
try:
if cells[addTuples((w, h), offsets[i])].color > 200:
cells[(w, h)].color = 199
else:
cells[(w, h)].color = int(((cells[addTuples((w, h), offsets[i])].color + cells[(w, h)].color) / 2))
except:
pass
for w in range(resolution[0]):
for h in range(resolution[1]):
img.putpixel((w, h), cells[(w, h)].color)
img = img.crop((20, 20, resolution[0]-20, resolution[1]-20))
img.save("image.png")
# end timer
t2 = time.time()
print(f"Finished at: {round(t2-t1, 2)}")
img.show()