-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlinear without fade.py
242 lines (203 loc) · 7.49 KB
/
linear without fade.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
from math import floor
from ctypes import c_int64
import random
import pygame
import numpy as np
import numba
GRADIENTS2 = np.array([
5, 2, 2, 5,
-5, 2, -2, 5,
5, -2, 2, -5,
-5, -2, -2, -5,
], dtype=np.int64)
GRADIENTS3 = np.array([
-11, 4, 4, -4, 11, 4, -4, 4, 11,
11, 4, 4, 4, 11, 4, 4, 4, 11,
-11, -4, 4, -4, -11, 4, -4, -4, 11,
11, -4, 4, 4, -11, 4, 4, -4, 11,
-11, 4, -4, -4, 11, -4, -4, 4, -11,
11, 4, -4, 4, 11, -4, 4, 4, -11,
-11, -4, -4, -4, -11, -4, -4, -4, -11,
11, -4, -4, 4, -11, -4, 4, -4, -11,
], dtype=np.int64)
GRADIENTS4 = np.array([
3, 1, 1, 1, 1, 3, 1, 1, 1, 1, 3, 1, 1, 1, 1, 3,
-3, 1, 1, 1, -1, 3, 1, 1, -1, 1, 3, 1, -1, 1, 1, 3,
3, -1, 1, 1, 1, -3, 1, 1, 1, -1, 3, 1, 1, -1, 1, 3,
-3, -1, 1, 1, -1, -3, 1, 1, -1, -1, 3, 1, -1, -1, 1, 3,
3, 1, -1, 1, 1, 3, -1, 1, 1, 1, -3, 1, 1, 1, -1, 3,
-3, 1, -1, 1, -1, 3, -1, 1, -1, 1, -3, 1, -1, 1, -1, 3,
3, -1, -1, 1, 1, -3, -1, 1, 1, -1, -3, 1, 1, -1, -1, 3,
-3, -1, -1, 1, -1, -3, -1, 1, -1, -1, -3, 1, -1, -1, -1, 3,
3, 1, 1, -1, 1, 3, 1, -1, 1, 1, 3, -1, 1, 1, 1, -3,
-3, 1, 1, -1, -1, 3, 1, -1, -1, 1, 3, -1, -1, 1, 1, -3,
3, -1, 1, -1, 1, -3, 1, -1, 1, -1, 3, -1, 1, -1, 1, -3,
-3, -1, 1, -1, -1, -3, 1, -1, -1, -1, 3, -1, -1, -1, 1, -3,
3, 1, -1, -1, 1, 3, -1, -1, 1, 1, -3, -1, 1, 1, -1, -3,
-3, 1, -1, -1, -1, 3, -1, -1, -1, 1, -3, -1, -1, 1, -1, -3,
3, -1, -1, -1, 1, -3, -1, -1, 1, -1, -3, -1, 1, -1, -1, -3,
-3, -1, -1, -1, -1, -3, -1, -1, -1, -1, -3, -1, -1, -1, -1, -3,
], dtype=np.int64)
STRETCH_CONSTANT2 = -0.211324865405187
SQUISH_CONSTANT2 = 0.366025403784439
STRETCH_CONSTANT3 = -1.0 / 6
SQUISH_CONSTANT3 = 1.0 / 3
STRETCH_CONSTANT4 = -0.138196601125011
SQUISH_CONSTANT4 = 0.309016994374947
NORM_CONSTANT2 = 47
NORM_CONSTANT3 = 103
NORM_CONSTANT4 = 30
@numba.njit(cache=True)
def extrapolate2(perm, xsb, ysb, dx, dy):
index = perm[(perm[xsb & 0xFF] + ysb) & 0xFF] & 0x0E
g1, g2 = GRADIENTS2[index : index + 2]
return g1 * dx + g2 * dy
@numba.njit(cache=True)
def generatekey(x, y, perm):
stretch_offset = (x + y) * STRETCH_CONSTANT2
xs = x + stretch_offset
ys = y + stretch_offset
xsb = floor(xs)
ysb = floor(ys)
squish_offset = (xsb + ysb) * SQUISH_CONSTANT2
xb = xsb + squish_offset
yb = ysb + squish_offset
xins = xs - xsb
yins = ys - ysb
in_sum = xins + yins
dx0 = x - xb
dy0 = y - yb
value = 0
dx1 = dx0 - 1 - SQUISH_CONSTANT2
dy1 = dy0 - 0 - SQUISH_CONSTANT2
attn1 = 2 - dx1 * dx1 - dy1 * dy1
if attn1 > 0:
attn1 *= attn1
value += attn1 * attn1 * extrapolate2(perm, xsb + 1, ysb + 0, dx1, dy1)
dx2 = dx0 - 0 - SQUISH_CONSTANT2
dy2 = dy0 - 1 - SQUISH_CONSTANT2
attn2 = 2 - dx2 * dx2 - dy2 * dy2
if attn2 > 0:
attn2 *= attn2
value += attn2 * attn2 * extrapolate2(perm, xsb + 0, ysb + 1, dx2, dy2)
if in_sum <= 1:
zins = 1 - in_sum
if zins > xins or zins > yins:
if xins > yins:
xsv_ext = xsb + 1
ysv_ext = ysb - 1
dx_ext = dx0 - 1
dy_ext = dy0 + 1
else:
xsv_ext = xsb - 1
ysv_ext = ysb + 1
dx_ext = dx0 + 1
dy_ext = dy0 - 1
else:
xsv_ext = xsb + 1
ysv_ext = ysb + 1
dx_ext = dx0 - 1 - 2 * SQUISH_CONSTANT2
dy_ext = dy0 - 1 - 2 * SQUISH_CONSTANT2
else:
zins = 2 - in_sum
if zins < xins or zins < yins:
if xins > yins:
xsv_ext = xsb + 2
ysv_ext = ysb + 0
dx_ext = dx0 - 2 - 2 * SQUISH_CONSTANT2
dy_ext = dy0 + 0 - 2 * SQUISH_CONSTANT2
else:
xsv_ext = xsb + 0
ysv_ext = ysb + 2
dx_ext = dx0 + 0 - 2 * SQUISH_CONSTANT2
dy_ext = dy0 - 2 - 2 * SQUISH_CONSTANT2
else:
dx_ext = dx0
dy_ext = dy0
xsv_ext = xsb
ysv_ext = ysb
xsb += 1
ysb += 1
dx0 = dx0 - 1 - 2 * SQUISH_CONSTANT2
dy0 = dy0 - 1 - 2 * SQUISH_CONSTANT2
attn0 = 2 - dx0 * dx0 - dy0 * dy0
if attn0 > 0:
attn0 *= attn0
value += attn0 * attn0 * extrapolate2(perm, xsb, ysb, dx0, dy0)
attn_ext = 2 - dx_ext * dx_ext - dy_ext * dy_ext
if attn_ext > 0:
attn_ext *= attn_ext
value += attn_ext * attn_ext * extrapolate2(perm, xsv_ext, ysv_ext, dx_ext, dy_ext)
return value / NORM_CONSTANT2
def overflow(x):
return c_int64(x).value
def getseed(seed):
perm = np.zeros(256, dtype=np.int64)
perm_grad_index3 = np.zeros(256, dtype=np.int64)
source = np.arange(256)
seed = overflow(seed * 6364136223846793005 + 1442695040888963407)
seed = overflow(seed * 6364136223846793005 + 1442695040888963407)
seed = overflow(seed * 6364136223846793005 + 1442695040888963407)
for i in range(255, -1, -1):
seed = overflow(seed * 6364136223846793005 + 1442695040888963407)
r = int((seed + 31) % (i + 1))
if r < 0:
r += i + 1
perm[i] = source[r]
perm_grad_index3[i] = int((perm[i] % (len(GRADIENTS3) / 3)) * 3)
source[r] = source[i]
return perm
pygame.init()
display = pygame.display.set_mode((1920, 1080), pygame.FULLSCREEN)
clock = pygame.time.Clock()
class Line():
def __init__(self, instance=0):
self.line_data = []
self.updown = random.randint(0, 1)
self.seed = getseed(random.randint(0, 99999))
self.x = 0
self.y = random.randint(0, 999)
self.col = [random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)]
self.instance = instance
def update(self):
if len(self.line_data) > 1080:
del self.line_data[0]
def append(self):
self.line_data.append((1920/2) + ((generatekey(self.x/500, -self.x/500, self.seed)+generatekey(-self.x/500, self.x/500, self.seed)+generatekey(-self.x/500, -self.x/500, self.seed))/3)*(3000/2))
self.x += 1
def draw(self):
l = []
for i in range(len(self.line_data)):
l.append([self.line_data[i], i])
if len(l) >= 3:
pygame.draw.aalines(display, [int((1+generatekey(self.x/500, self.y, self.seed))*(255/2)), int((1+generatekey(self.x/500, -self.y, self.seed))*(255/2)), int((1+generatekey(-self.x/500, self.y, self.seed))*(255/2))], False, l)
# or display
size = 200
window_size = (1920, 1080)
lines = Line(0)
while True:
'''Surface = pygame.Surface(window_size)
Surface.fill((0, 0, 0))
Surface.set_colorkey((0, 0, 0))
Surface2 = pygame.Surface(window_size)
Surface2.fill((0, 0, 0))
Surface.set_alpha(255) # 75
Surface2.set_alpha(1)'''
lines.update()
lines.append()
#Surface.convert_alpha()
#Surface2.convert_alpha()
#display.fill((0, 0, 0))
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
pygame.quit()
quit()
lines.draw()
#display.blit(Surface2, (0, 0))
#display.blit(Surface, (0, 0))
pygame.display.flip()
#clock.tick(2000)