Skip to content

Commit 57eac1f

Browse files
updated repo
1 parent d494b02 commit 57eac1f

File tree

4 files changed

+178
-4
lines changed

4 files changed

+178
-4
lines changed

README.md

+7-3
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,14 @@ The following Python programs HAVE been turned into YouTube videos:
4747
* `ball creation.py` in: [[2 hour version] 4K Colored Ball Ascension](https://youtu.be/fWKhY3_ynaQ)
4848
* `1000 bouncy balls.py` in: [[1 hour version] 4K Bouncy Balls](https://youtu.be/yC3jELVnigA)
4949
* `3D spinning ball.py` in: [[1 hour version] 4K Rainbow Lava Ball](https://youtu.be/CCIVQxMbuWg) and [[1 hour version] 4K Rainbow Plasma](https://youtu.be/GOypjQRR1B8)
50-
* `24 Christmas SPecial.py` in [[1 hour version] 4K Cosmic Snowflake - Christmas Special!](https://youtu.be/XhryrwTfaz0)
50+
* `24 Christmas Special.py` in [[1 hour version] 4K Cosmic Snowflake - Christmas Special!](https://youtu.be/XhryrwTfaz0)
5151
* `sphere sphere.py` in: [[5 hour version] 4K Rainbow Spheres](https://youtu.be/ukyNrSWsPN4)
52-
* `circle ascension.py` in: To be released
53-
* `gravity.py` in: To be released
52+
* `circle ascension.py` in: To be released!
53+
* `gravity.py` in: [[1 hour version] 4K Rainbow Space Simulator](https://youtu.be/0qp7vAs4ors)
54+
* `3d perlin mesh.py` in: [[1 hour version] 4K Rainbow Fabric](https://youtu.be/xjkVZqJLu2k)
55+
* `patterned.py` in: [[1 hour version] 4K Rainbow Spiral](https://youtu.be/9kpoJontjyo)
56+
* `growing lines.py` in: [[1 hour version] 4K Coloured Paint Run](https://youtu.be/yBY-8U4jwBQ)
57+
* `spinner3.py` in: To be released!
5458

5559
The following Python programs WILL LIKELY be turned into YouTube videos soon:
5660
* `Colored Pixels.py`

src/patterned.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import pmma
22
import math
3+
import random
34

45
pmma.set_clean_profiling(False)
56
pmma.set_profile_result_path(r"H:\Downloads\twtwo profile.txt")
@@ -44,7 +45,9 @@ def pythag(x, y):
4445
circles[i].set_center(pos, format=pmma.Constants.OPENGL_COORDINATES)
4546

4647
for i in range(len(circles)):
47-
circles[i].render()
48+
if random.choice([True, False]):
49+
#circles[i].generate_random_color()
50+
circles[i].render()
4851

4952
pmma.compute()
5053

src/spinner2.py

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import pygame
2+
import math
3+
import time
4+
import pmma
5+
6+
def create_gradient_surface(length, width, start_color, end_color):
7+
"""Creates a horizontal gradient surface."""
8+
surface = pygame.Surface((length, width), pygame.SRCALPHA)
9+
for x in range(length):
10+
t = x / length
11+
color = (
12+
int(start_color[0] * (1 - t) + end_color[0] * t),
13+
int(start_color[1] * (1 - t) + end_color[1] * t),
14+
int(start_color[2] * (1 - t) + end_color[2] * t),
15+
255
16+
)
17+
pygame.draw.line(surface, color, (x, 0), (x, width))
18+
return surface
19+
20+
def blit_rotated_gradient(surface, start_pos, end_pos, start_color, end_color, width):
21+
"""Blit a rotated gradient onto the screen between two points."""
22+
dx = end_pos[0] - start_pos[0]
23+
dy = end_pos[1] - start_pos[1]
24+
length = int((dx ** 2 + dy ** 2) ** 0.5)
25+
26+
gradient = create_gradient_surface(length, width, start_color, end_color)
27+
28+
angle = -pygame.math.Vector2(dx, dy).angle_to((1, 0)) # Find the angle
29+
rotated_gradient = pygame.transform.rotate(gradient, angle)
30+
31+
rect = rotated_gradient.get_rect(center=((start_pos[0] + end_pos[0]) // 2,
32+
(start_pos[1] + end_pos[1]) // 2))
33+
34+
surface.blit(rotated_gradient, rect.topleft)
35+
36+
# Pygame setup
37+
pygame.init()
38+
screen = pygame.display.set_mode((1920, 1080), pygame.FULLSCREEN)
39+
clock = pygame.time.Clock()
40+
41+
inner_color = pmma.ColorConverter()
42+
outer_color = pmma.ColorConverter()
43+
radius = pmma.Perlin()
44+
45+
now_time = 0
46+
start = time.perf_counter()
47+
running = True
48+
while running:
49+
rx = 1920 // 2 + int(math.sin(now_time) * radius.generate_1D_perlin_noise(now_time, new_range=[0, 1080 / 2]))
50+
ry = 1080 // 2 + int(math.cos(now_time) * radius.generate_1D_perlin_noise(now_time, new_range=[0, 1080 / 2]))
51+
52+
blit_rotated_gradient(
53+
screen,
54+
(1920 // 2, 1080 // 2),
55+
(rx, ry),
56+
inner_color.generate_color_from_perlin_noise(format=pmma.Constants.RGB),
57+
outer_color.generate_color_from_perlin_noise(format=pmma.Constants.RGB),
58+
20)
59+
60+
rx = 1920 // 2 + int(math.sin(now_time + math.pi) * radius.generate_1D_perlin_noise(now_time, new_range=[0, 1080 / 2]))
61+
ry = 1080 // 2 + int(math.cos(now_time + math.pi) * radius.generate_1D_perlin_noise(now_time, new_range=[0, 1080 / 2]))
62+
63+
blit_rotated_gradient(
64+
screen,
65+
(1920 // 2, 1080 // 2),
66+
(rx, ry),
67+
inner_color.generate_color_from_perlin_noise(format=pmma.Constants.RGB),
68+
outer_color.generate_color_from_perlin_noise(format=pmma.Constants.RGB),
69+
20)
70+
71+
pygame.display.flip()
72+
73+
for event in pygame.event.get():
74+
if event.type == pygame.QUIT:
75+
running = False
76+
77+
now_time = time.perf_counter() - start
78+
clock.tick(60)
79+
80+
pygame.quit()

src/spinner3.py

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import pygame
2+
import math
3+
import time
4+
import pmma
5+
6+
def create_gradient_surface(length, width, start_color, end_color):
7+
"""Creates a horizontal gradient surface."""
8+
surface = pygame.Surface((length, width), pygame.SRCALPHA)
9+
for x in range(length):
10+
t = x / length
11+
color = (
12+
int(start_color[0] * (1 - t) + end_color[0] * t),
13+
int(start_color[1] * (1 - t) + end_color[1] * t),
14+
int(start_color[2] * (1 - t) + end_color[2] * t),
15+
255
16+
)
17+
pygame.draw.line(surface, color, (x, 0), (x, width))
18+
return surface
19+
20+
def blit_rotated_gradient(surface, start_pos, end_pos, start_color, end_color, width):
21+
"""Blits a correctly positioned and rotated gradient line."""
22+
# Compute length of the line
23+
dx = end_pos[0] - start_pos[0]
24+
dy = end_pos[1] - start_pos[1]
25+
length = int(math.sqrt(dx ** 2 + dy ** 2))
26+
27+
# Create the horizontal gradient
28+
gradient = create_gradient_surface(length, width, start_color, end_color)
29+
30+
# Find the angle in degrees
31+
angle = math.degrees(math.atan2(dy, dx))
32+
33+
# Rotate the gradient surface
34+
rotated_gradient = pygame.transform.rotate(gradient, -angle)
35+
36+
# Get the new bounding box and recenter it
37+
rotated_rect = rotated_gradient.get_rect(center=((start_pos[0] + end_pos[0]) // 2,
38+
(start_pos[1] + end_pos[1]) // 2))
39+
40+
# Blit the rotated gradient at the corrected position
41+
surface.blit(rotated_gradient, rotated_rect.topleft)
42+
43+
# Pygame setup
44+
pygame.init()
45+
screen = pygame.display.set_mode((1920, 1080), pygame.FULLSCREEN)
46+
clock = pygame.time.Clock()
47+
48+
inner_color = pmma.ColorConverter()
49+
outer_color = pmma.ColorConverter()
50+
radius = pmma.Perlin()
51+
52+
now_time = 0
53+
start = time.perf_counter()
54+
running = True
55+
while running:
56+
rx = 1920 // 2 + int(math.sin(now_time) * radius.generate_1D_perlin_noise(now_time/5, new_range=[0, 1080 / 2]))
57+
ry = 1080 // 2 + int(math.cos(now_time) * radius.generate_1D_perlin_noise(now_time/5, new_range=[0, 1080 / 2]))
58+
59+
blit_rotated_gradient(
60+
screen,
61+
(1920 // 2, 1080 // 2),
62+
(rx, ry),
63+
inner_color.generate_color_from_perlin_noise(now_time/7, format=pmma.Constants.RGB),
64+
outer_color.generate_color_from_perlin_noise(now_time/7, format=pmma.Constants.RGB),
65+
10)
66+
67+
rx = 1920 // 2 + int(math.sin(now_time + math.pi) * radius.generate_1D_perlin_noise(now_time/5, new_range=[0, 1080 / 2]))
68+
ry = 1080 // 2 + int(math.cos(now_time + math.pi) * radius.generate_1D_perlin_noise(now_time/5, new_range=[0, 1080 / 2]))
69+
70+
blit_rotated_gradient(
71+
screen,
72+
(1920 // 2, 1080 // 2),
73+
(rx, ry),
74+
inner_color.generate_color_from_perlin_noise(now_time/7, format=pmma.Constants.RGB),
75+
outer_color.generate_color_from_perlin_noise(now_time/7, format=pmma.Constants.RGB),
76+
10)
77+
78+
pygame.display.flip()
79+
80+
for event in pygame.event.get():
81+
if event.type == pygame.QUIT:
82+
running = False
83+
84+
now_time = time.perf_counter() - start
85+
clock.tick(60)
86+
87+
pygame.quit()

0 commit comments

Comments
 (0)