Skip to content

Commit e719f2e

Browse files
new effect!
1 parent 6f273f4 commit e719f2e

File tree

1 file changed

+84
-0
lines changed

1 file changed

+84
-0
lines changed

src/spiraly.py

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import pygame
2+
import math
3+
import pmma
4+
5+
pygame.init()
6+
pmma.init()
7+
8+
display = pygame.display.set_mode((0, 0), pygame.FULLSCREEN)
9+
10+
clock = pygame.time.Clock()
11+
12+
class Line:
13+
def __init__(self, x, y, dx, dy, seed):
14+
self.start = (x, y)
15+
self.dir = (dx, dy)
16+
self.points = [self.start] * 2
17+
self.color = pmma.ColorConverter()
18+
self.color.set_red_seed(seed)
19+
self.color.set_green_seed(seed+10)
20+
self.color.set_blue_seed(seed+20)
21+
self.dx_offset = pmma.Perlin(seed)
22+
self.dy_offset = pmma.Perlin(seed+10)
23+
self.new = True
24+
25+
def update(self):
26+
pygame.draw.lines(display, self.color.generate_color_from_perlin_noise(pmma.get_application_run_time()/500, format=pmma.Constants.RGB, color_range=[0, 255]), False, self.points, width=3)
27+
if self.points[-1][0] < 0 or self.points[-1][0] > display.get_width() or self.points[-1][1] < 0 or self.points[-1][1] > display.get_height():
28+
self.new = False
29+
return
30+
31+
self.points.append((
32+
self.points[-1][0] + self.dir[0] * self.dx_offset.generate_1D_perlin_noise(self.dir[0]*len(self.points)/100, new_range=[0, 3]),
33+
self.points[-1][1] + self.dir[1] * self.dy_offset.generate_1D_perlin_noise(self.dir[1]*len(self.points)/100, new_range=[0, 3])))
34+
35+
lines = []
36+
n = 0
37+
38+
def generate_lines(radius=50, num_points=200):
39+
global lines, n
40+
screen_width, screen_height = display.get_size()
41+
cx, cy = screen_width // 2, screen_height // 2
42+
new = [
43+
Line(cx + int(radius * math.cos(2 * math.pi * i / num_points)),
44+
cy + int(radius * math.sin(2 * math.pi * i / num_points)),
45+
math.cos(2 * math.pi * i / num_points),
46+
math.sin(2 * math.pi * i / num_points),
47+
n)
48+
for i in range(num_points)
49+
]
50+
lines.extend(new)
51+
n += 1
52+
53+
generate_lines()
54+
55+
surface = pygame.Surface(display.get_size(), pygame.SRCALPHA)
56+
alpha = 255
57+
while True:
58+
for event in pygame.event.get():
59+
if event.type == pygame.QUIT:
60+
pygame.quit()
61+
quit()
62+
63+
display.fill((0, 0, 0))
64+
if alpha >= 0 and alpha <= 255:
65+
surface.set_alpha(alpha)
66+
display.blit(surface, (0, 0))
67+
alpha -= 0.5
68+
69+
new = True
70+
for line in lines:
71+
line.update()
72+
new &= not line.new
73+
74+
if new:
75+
lines = []
76+
generate_lines()
77+
78+
pmma.compute()
79+
pygame.display.update()
80+
81+
if new:
82+
surface.blit(display, (0, 0))
83+
alpha = 255
84+
clock.tick(60)

0 commit comments

Comments
 (0)