-
Notifications
You must be signed in to change notification settings - Fork 6
/
ColorPerlin.py
89 lines (72 loc) · 3.09 KB
/
ColorPerlin.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
import PIL, random, sys, argparse, math
from PIL import Image, ImageDraw
import noise
r = lambda: random.randint(30,235)
rc = lambda: ('#%02X%02X%02X' % (r(),r(),r()))
def main():
parser = argparse.ArgumentParser()
parser.add_argument("--width", default=1500, type=int)
parser.add_argument("--height", default=1500, type=int)
parser.add_argument("-s", "--scale", default=200.0, type=float)
parser.add_argument("-o", "--octaves", default=6, type=int)
parser.add_argument("-p", "--persistence", default=.5, type=float)
parser.add_argument("-l", "--lacunarity", default=2.0, type=float)
parser.add_argument("-b", "--base", default=0, type=int)
parser.add_argument("-md", "--max_distance", default=900.0, type=float)
parser.add_argument("-a", "--alter", default=0, type=int)
args = parser.parse_args()
random.seed()
offset = random.randint(1, 100) * random.randint(1, 1000)
width, height = args.width, args.height
octaves = args.octaves
persistence = args.persistence
lacunarity = args.lacunarity
scale = args.scale
base = args.base
alter = args.alter
max_distance = args.max_distance
pil_image = Image.new('RGBA', (width, height))
pixels = pil_image.load()
cl = []
for i in range(10):
cl.append((r(), r(), r()))
for i in range(pil_image.size[0]):
for j in range(pil_image.size[1]):
# Generates a value from -1 to 1
pixel_value = noise.pnoise2((offset+i)/scale,
(offset+j)/scale,
octaves,
persistence,
lacunarity,
width,
height,
base)
distance_from_center = math.sqrt(math.pow((i - width/2), 2) + math.pow((j - height/2), 2))
gradient_perc = distance_from_center/max_distance
pixel_value -= math.pow(gradient_perc, 3)
if (int(pixel_value * 100.0) > 40):
pixels[i, j] = cl[5]
elif (int(pixel_value * 100.0) > 30):
pixels[i, j] = cl[4]
elif (int(pixel_value * 100.0) > 20):
pixels[i, j] = cl[3]
elif (int(pixel_value * 100.0) > 10):
pixels[i, j] = cl[2]
elif (int(pixel_value * 100.0) > 0):
pixels[i, j] = cl[1]
elif (int(pixel_value * 100.0) > -10):
pixels[i, j] = cl[4]
elif (int(pixel_value * 100.0) > -20):
pixels[i, j] = cl[3]
elif (int(pixel_value * 100.0) > -30):
pixels[i, j] = cl[2]
elif (int(pixel_value * 100.0) > -40):
pixels[i, j] = cl[1]
else:
pixels[i, j] = (20, 30, 35)
pil_image.save('Examples/Color-' + str(offset) + '-w-' + str(width) + '-h-' + str(height) + '.png')
if __name__ == "__main__":
main()
# 52 minutes - Definitely my maybe
# -> 1:07
# watch endsceen -> credits