-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsquare implosion.py
90 lines (67 loc) · 2.66 KB
/
square implosion.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
import pmma
import math
import numpy as np
import time
import pygame
pmma.init(log_information=True)
display = pygame.display.set_mode((0, 0), flags=pygame.FULLSCREEN)
#display = pygame.display.set_mode((1280, 720))
clock = pygame.time.Clock()
advmath = pmma.Math()
noise = pmma.Perlin()
r_noise = pmma.Perlin()
g_noise = pmma.Perlin()
b_noise = pmma.Perlin()
class Triangle:
def __init__(self):
self.center = display.get_width() / 2, display.get_height() / 2
self.radius = min(display.get_width(), display.get_height()) / 2
#self.radius = advmath.pythag(display.get_size())
def draw(self, theta):
angles = np.array([0, np.pi/2, np.pi, np.pi*(1.5)]) #square
# Calculate the coordinates of the vertices
vertices = []
for angle in angles:
x = self.center[0] + self.radius * np.cos(angle)
y = self.center[1] + self.radius * np.sin(angle)
vertices.append([x, y])
# Draw the equilateral triangle
vertices = np.array(vertices)
# Rotation matrix
rotation_matrix = np.array([[np.cos(theta), -np.sin(theta)],
[np.sin(theta), np.cos(theta)]])
# Subtract the center, apply rotation, and then add the center back
rotated_vertices = np.dot(vertices - self.center, rotation_matrix) + self.center
color = r_noise.generate_1D_perlin_noise(time.perf_counter(), new_range=[0, 255]), g_noise.generate_1D_perlin_noise(time.perf_counter(), new_range=[0, 255]), b_noise.generate_1D_perlin_noise(time.perf_counter(), new_range=[0, 255])
pygame.draw.polygon(
display,
(color),
rotated_vertices,
width=7)
for vertex in rotated_vertices:
pygame.draw.circle(display, (0, 0, 0), vertex, 50)
triangle_shape = Triangle()
K = 75 #50
TAU = 2 * math.pi
def scaler():
surface = pygame.transform.smoothscale(display, (display.get_width()-K, display.get_height()-K))
display.fill([0, 0, 0])
display.blit(surface, ((display.get_width() - surface.get_width())/2, (display.get_height() - surface.get_height())/2))
angle = 0
scale = 15 # 30
while pmma.Backpack.running:
scaler()
#display.fill([0, 0, 0])
for event in pygame.event.get():
if event.type == pygame.QUIT:
pmma.quit()
quit()
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
pmma.quit()
quit()
triangle_shape.draw(angle)
angle += noise.generate_1D_perlin_noise(time.perf_counter(), new_range=[-1/scale, 1/scale])
clock.tick(75)
pygame.display.flip()
pmma.compute()