Skip to content

Commit b371900

Browse files
new and improved effects!
1 parent 36907b1 commit b371900

File tree

3 files changed

+143
-4
lines changed

3 files changed

+143
-4
lines changed

Diff for: src/growing lines.py

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import pygame
2+
import pmma
3+
import time
4+
import random
5+
6+
pygame.init()
7+
pmma.init()
8+
9+
now_time = 0
10+
display = pygame.display.set_mode((0, 0), pygame.FULLSCREEN)
11+
clock = pygame.time.Clock()
12+
seed = random.randint(0, 1000000)
13+
max_lifetime = 0
14+
15+
class Line:
16+
def __init__(self, x_pos):
17+
global max_lifetime
18+
self.x_noise = pmma.Perlin(seed=seed)
19+
self.y_noise = pmma.Perlin(seed=seed)
20+
self._x_pos = x_pos
21+
self.point = [x_pos, display.get_height() // 2]
22+
self.lifetime = random.randint(10, 30)
23+
max_lifetime = max(max_lifetime, self.lifetime)
24+
color = pmma.ColorConverter()
25+
self.color = color.generate_random_color()
26+
27+
def render(self):
28+
pygame.draw.circle(display, self.color, self.point, 5 * (1-(now_time / self.lifetime)))
29+
self.point[0] += self.x_noise.generate_2D_perlin_noise(self._x_pos / 2000, now_time / 10, new_range=[-2, 2])
30+
self.point[1] += self.y_noise.generate_2D_perlin_noise(self._x_pos / 2000, -now_time / 10, new_range=[-2, 2])
31+
32+
lines = []
33+
for x in range(0, display.get_width(), 10):
34+
lines.append(Line(x))
35+
36+
s = time.perf_counter()
37+
while True:
38+
for event in pygame.event.get():
39+
if event.type == pygame.QUIT:
40+
pygame.quit()
41+
pmma.quit()
42+
quit()
43+
44+
#display.fill((0, 0, 0))
45+
46+
if now_time > max_lifetime:
47+
seed = random.randint(0, 1000000)
48+
max_lifetime = 0
49+
now_time = 0
50+
s = time.perf_counter()
51+
display.fill((0, 0, 0))
52+
lines = []
53+
for x in range(0, display.get_width(), 10):
54+
lines.append(Line(x))
55+
56+
for line in lines:
57+
line.render()
58+
59+
pygame.display.update()
60+
clock.tick(60)
61+
62+
now_time = time.perf_counter() - s

Diff for: src/patterned pygame.py

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import pmma
2+
import math
3+
import pygame
4+
import time
5+
6+
pygame.init()
7+
8+
display = pygame.display.set_mode((0, 0), pygame.FULLSCREEN)
9+
10+
noise = pmma.Perlin()
11+
12+
class Circle:
13+
def __init__(self):
14+
self.radius = 0
15+
self.color = [0, 0, 0]
16+
self.position = [0, 0]
17+
18+
circles = []
19+
for _ in range(7500): # 750
20+
circle = Circle()
21+
circle.radius = 10
22+
circle.color = [255, 255, 255]
23+
circle.position = [display.get_width() // 2, display.get_height() // 2]
24+
circles.append(circle)
25+
26+
offset = 0
27+
28+
def pythag(x, y):
29+
return math.sqrt((x*x)+(y*y))
30+
31+
ROOT_TWO = 2**0.5
32+
33+
clock = pygame.time.Clock()
34+
35+
now_time = 0
36+
37+
while True:
38+
s = time.perf_counter()
39+
for event in pygame.event.get():
40+
if event.type == pygame.QUIT:
41+
pygame.quit()
42+
quit()
43+
if event.type == pygame.KEYDOWN:
44+
if event.key == pygame.K_ESCAPE:
45+
pygame.quit()
46+
quit()
47+
48+
display.fill([0, 0, 0])
49+
50+
for i in range(len(circles)):
51+
a = ((1/360)*i)
52+
pos = [(math.sin(i+offset)*a)/ (display.get_width() / display.get_height()), math.cos(i+offset)*a]
53+
distance = pythag(abs(pos[0]), abs(pos[1])) - circle.radius
54+
if distance < ROOT_TWO:
55+
size = noise.generate_1D_perlin_noise(-distance + now_time/2, new_range=[1, 50]) * (distance / ROOT_TWO)
56+
size = max(size, 1)
57+
circles[i].radius = size
58+
circles[i].position = [display.get_width() / 2 + pos[0] * display.get_width() / 2, display.get_height() / 2 + pos[1] * display.get_height() / 2]
59+
60+
for i in range(len(circles)):
61+
pygame.draw.circle(display, circles[i].color, circles[i].position, circles[i].radius)
62+
63+
pygame.display.flip()
64+
65+
clock.tick(2000)
66+
e = time.perf_counter()
67+
now_time = e-s
68+
print(clock.get_fps())
69+
70+
pmma.quit()

Diff for: src/patterned.py

+11-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import pmma
22
import math
33

4-
pmma.init()
4+
pmma.set_clean_profiling(False)
5+
pmma.set_profile_result_path(r"H:\Downloads\twtwo profile.txt")
6+
pmma.init(general_profile_application=True)
7+
#pmma.init(general_profile_application=False, use_c_acceleration=True)
58

69
display = pmma.Display()
7-
display.create()
10+
display.create(vsync=False)
811

912
events = pmma.Events()
1013

@@ -15,6 +18,7 @@
1518
circle = pmma.RadialPolygon()
1619
circle.set_radius(10)
1720
circle.generate_random_color()
21+
circle.set_center((0, 0), pmma.Constants.OPENGL_COORDINATES)
1822
circles.append(circle)
1923

2024
offset = 0
@@ -38,9 +42,12 @@ def pythag(x, y):
3842
size = max(size, 1)
3943
circles[i].set_radius(size)
4044
circles[i].set_center(pos, format=pmma.Constants.OPENGL_COORDINATES)
41-
circles[i].render()
45+
46+
for i in range(len(circles)):
47+
circles[i].render()
4248

4349
pmma.compute()
44-
display.refresh()
50+
51+
display.refresh(lower_refresh_rate_when_minimized=False, lower_refresh_rate_when_unfocused=False, refresh_rate=6000)
4552

4653
pmma.quit()

0 commit comments

Comments
 (0)