-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_gen.py
78 lines (59 loc) · 2.74 KB
/
main_gen.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
# Importing Libraries
import math
import random
import numpy as np
from PyQt5.QtGui import QColor, QPen
from PyQt5.QtCore import QPointF
import painter
from utils import QColor_HSV, save, Perlin2D
# Draw function with 2 positional arguments and 5 keyword arguments
def draw(width, height, color=200, backgroundColor=(0, 0, 0), perlinFactorW=2, perlinFactorH=2, step=0.001):
# Randomly select an integer between 0 and 100000000
seed = random.randint(0, 100000000)
# Set the random seed for repeatability
np.random.seed(seed)
p = painter.Painter(width, height)
# Draw the background color
p.fillRect(0, 0, width, height, QColor(*backgroundColor))
# Pen Color
p.setPen(QPen(QColor(150, 150, 225, 5), 2))
# Generating Noise
p_noise = Perlin2D(width, height, perlinFactorW, perlinFactorH)
# Angle Calculations
MAX_LENGTH = 2 * width # helps to draw inside the frame
STEP_SIZE = step * max(width, height) # used to generate chaotic features
NUM = int(width * height / 1000)
POINTS = [(random.randint(0, width - 1), random.randint(0, height - 1)) for i in range(NUM)]
for k, (x_s, y_s) in enumerate(POINTS):
print(f'{100 * (k + 1) / len(POINTS):.1f}'.rjust(5) + '% Complete', end='\r')
# The current line length tracking variable
c_len = 0
# Actually draw the flow field
while c_len < MAX_LENGTH:
# Set the pen colour for this segment
sat = 200 * (MAX_LENGTH - c_len) / MAX_LENGTH
hue = (color + 130 * (height - y_s) / height) % 360
p.setPen(QPen(QColor_HSV(hue, sat, 255, 20), 2))
# Angle between -pi and pi
angle = p_noise[int(x_s), int(y_s)] * math.pi
# Compute the new point
x_f = x_s + STEP_SIZE * math.cos(angle)
y_f = y_s + STEP_SIZE * math.sin(angle)
# Draw the line
p.drawLine(QPointF(x_s, y_s), QPointF(x_f, y_f))
# Update the line length
c_len += math.sqrt((x_f - y_s) ** 2 + (y_f - y_s) ** 2)
# Break from the loop if the new point is outside our image bounds
# Or if we've exceeded the line length, otherwise update the point
if x_f < 0 or x_f >= width or y_f < 0 or y_f >= height or c_len > MAX_LENGTH:
break
else:
x_s, y_s = x_f, y_f
save(p, fname=f'image_{seed}', folder='.', overwrite=True)
return seed
# Generate a random float
random_float = random.random()
random_float_scaled = random_float * (0.35 - 0.001) + 0.001
seed_value = draw(3000, 2000, color=random.randint(10, 500), perlinFactorW=4, perlinFactorH=5, step=random_float_scaled)
# Print the seed value for reference
print("Generated Seed Value:", seed_value)