effects
This commit is contained in:
parent
2d6706691d
commit
2aac7f7fac
3 changed files with 160 additions and 36 deletions
122
effects/crazypolys.py
Normal file
122
effects/crazypolys.py
Normal file
|
@ -0,0 +1,122 @@
|
||||||
|
from typing import Any
|
||||||
|
import pygame as pg
|
||||||
|
from effects.effect import Effect, Colors, transform_bounce
|
||||||
|
import random
|
||||||
|
import math
|
||||||
|
from typing import Union, Generator
|
||||||
|
|
||||||
|
|
||||||
|
class CrazyPolys(Effect):
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
bounds: pg.Rect,
|
||||||
|
color: Union[pg.Color, Generator[pg.Color, None, None]],
|
||||||
|
sizes=(100, 500),
|
||||||
|
velocity=(0.1, 1),
|
||||||
|
x_factor=(0.1, 1),
|
||||||
|
y_factor=(0.1, 1),
|
||||||
|
segments=100,
|
||||||
|
*groups: pg.sprite.Group,
|
||||||
|
) -> None:
|
||||||
|
self.min_size = sizes[0]
|
||||||
|
self.max_size = sizes[1]
|
||||||
|
self.min_velocity = velocity[0]
|
||||||
|
self.max_velocity = velocity[1]
|
||||||
|
|
||||||
|
self.velocity = 0.8 # random.randint(self.min_velocity, self.max_velocity)
|
||||||
|
self.ticks = 0.0
|
||||||
|
self.color = color
|
||||||
|
self.size = self.max_size
|
||||||
|
# self.size = (math.sin(self.ticks) / 2 + 0.5) * (
|
||||||
|
# self.max_size - self.min_size
|
||||||
|
# ) + self.min_size
|
||||||
|
image = pg.Surface((self.max_size, self.max_size))
|
||||||
|
image.fill(Colors.Black)
|
||||||
|
image.set_colorkey(Colors.Black)
|
||||||
|
|
||||||
|
self.r = random.randint(1, 50)
|
||||||
|
self.R = self.r * random.randint(1, 5)
|
||||||
|
self.a = random.randint(1, self.r)
|
||||||
|
self.nu = random.choice([-1, 1])
|
||||||
|
|
||||||
|
self.R_nu_r = self.R + self.nu * self.r
|
||||||
|
self.R_nu_r_divr = self.R_nu_r / self.r
|
||||||
|
# self.R = random.randint(1, 50) / 2
|
||||||
|
# self.r = random.randint(1, int(self.R + 0.6)) / 2
|
||||||
|
# self.a = random.randint(1, int(self.r + 0.6))
|
||||||
|
print(f"R:{self.R} r:{self.r} a:{self.a}")
|
||||||
|
|
||||||
|
self.background = pg.Surface((self.max_size, self.max_size))
|
||||||
|
self.background.fill(Colors.Black)
|
||||||
|
# self.background.set_alpha(4)
|
||||||
|
self.background.set_alpha(20)
|
||||||
|
|
||||||
|
super().__init__(
|
||||||
|
image,
|
||||||
|
pg.Rect(
|
||||||
|
bounds.centerx - self.size / 2,
|
||||||
|
bounds.centery - self.size / 2,
|
||||||
|
self.size,
|
||||||
|
self.size,
|
||||||
|
),
|
||||||
|
*groups,
|
||||||
|
)
|
||||||
|
self.bounds = bounds
|
||||||
|
self.bouncer = transform_bounce(
|
||||||
|
bounds=bounds, velocity=velocity, x_factor=x_factor, y_factor=y_factor
|
||||||
|
)
|
||||||
|
next(self.bouncer)
|
||||||
|
|
||||||
|
self.size_f = (self.size * 0.6 - 10) / 2 / (self.R + self.r)
|
||||||
|
self.cursor = self.calc_pos()
|
||||||
|
self.update()
|
||||||
|
|
||||||
|
def calc_pos(self):
|
||||||
|
x = self.max_size / 2 + self.size_f * (
|
||||||
|
(self.R_nu_r) * math.cos(self.ticks)
|
||||||
|
- self.a * self.nu * math.cos(self.R_nu_r_divr * self.ticks)
|
||||||
|
)
|
||||||
|
y = self.max_size / 2 + self.size_f * (
|
||||||
|
(self.R_nu_r) * math.sin(self.ticks)
|
||||||
|
- self.a * math.sin(self.R_nu_r_divr * self.ticks)
|
||||||
|
)
|
||||||
|
# x = self.max_size / 2 + self.size_f * (
|
||||||
|
# (self.R - self.r) * math.cos(self.r / self.R * self.ticks)
|
||||||
|
# + self.a * math.cos((1 - self.r / self.R) * self.ticks)
|
||||||
|
# )
|
||||||
|
# y = self.max_size / 2 + self.size_f * (
|
||||||
|
# (self.R - self.r) * math.sin(self.r / self.R * self.ticks)
|
||||||
|
# + self.a * math.sin((1 - self.r / self.R) * self.ticks)
|
||||||
|
# )
|
||||||
|
return x, y
|
||||||
|
|
||||||
|
def update(self, *args: Any, **kwargs: Any) -> None:
|
||||||
|
# new_size = (math.sin(self.ticks) / 2 + 0.5) * (
|
||||||
|
# self.max_size - self.min_size
|
||||||
|
# ) + self.min_size
|
||||||
|
|
||||||
|
# new_scale = new_size - self.rect.width
|
||||||
|
# self.rect.inflate_ip(new_scale, new_scale)
|
||||||
|
|
||||||
|
self.rect.center = self.bouncer.send(self.rect.size)
|
||||||
|
|
||||||
|
self.image.blit(self.background, (0, 0))
|
||||||
|
|
||||||
|
new_cursor = self.calc_pos()
|
||||||
|
pg.draw.line(
|
||||||
|
self.image,
|
||||||
|
self.color if isinstance(self.color, pg.Color) else next(self.color),
|
||||||
|
self.cursor,
|
||||||
|
new_cursor,
|
||||||
|
width=10,
|
||||||
|
)
|
||||||
|
self.cursor = new_cursor
|
||||||
|
|
||||||
|
# pg.draw.ellipse(
|
||||||
|
# self.image,
|
||||||
|
# self.color if isinstance(self.color, pg.Color) else next(self.color),
|
||||||
|
# ((0, 0), self.rect.size),
|
||||||
|
# )
|
||||||
|
|
||||||
|
self.ticks += self.velocity
|
||||||
|
# self.velocity = random.randint(self.min_velocity, self.max_velocity)
|
|
@ -16,26 +16,38 @@ class Spiro(Effect):
|
||||||
x_factor=(0.1, 1),
|
x_factor=(0.1, 1),
|
||||||
y_factor=(0.1, 1),
|
y_factor=(0.1, 1),
|
||||||
segments=100,
|
segments=100,
|
||||||
*groups: pg.sprite.Group
|
*groups: pg.sprite.Group,
|
||||||
) -> None:
|
) -> None:
|
||||||
self.min_size = sizes[0]
|
self.min_size = sizes[0]
|
||||||
self.max_size = sizes[1]
|
self.max_size = sizes[1]
|
||||||
self.min_velocity = velocity[0]
|
self.min_velocity = velocity[0]
|
||||||
self.max_velocity = velocity[1]
|
self.max_velocity = velocity[1]
|
||||||
|
|
||||||
self.velocity = 0.8 # random.randint(self.min_velocity, self.max_velocity)
|
self.velocity = 0.1 # random.uniform(self.min_velocity, self.max_velocity)
|
||||||
self.ticks = 0.0
|
self.ticks = 0.0
|
||||||
self.color = color
|
self.color = color
|
||||||
self.size = self.max_size
|
self.size = self.max_size
|
||||||
# self.size = (math.sin(self.ticks) / 2 + 0.5) * (
|
|
||||||
# self.max_size - self.min_size
|
|
||||||
# ) + self.min_size
|
|
||||||
image = pg.Surface((self.max_size, self.max_size))
|
image = pg.Surface((self.max_size, self.max_size))
|
||||||
image.fill(Colors.Black)
|
image.fill(Colors.Black)
|
||||||
image.set_colorkey(Colors.Black)
|
image.set_colorkey(Colors.Black)
|
||||||
|
|
||||||
|
self.R = random.randint(self.max_size / 6, self.max_size / 2)
|
||||||
|
self.a = 3/random.randint(4, 10) #random.uniform(0, 1)
|
||||||
|
self.k = 3/random.randint(4, 10) #random.uniform(0, 1)
|
||||||
|
|
||||||
|
self.scan_speed = random.randint(1, 100)
|
||||||
|
|
||||||
|
self.one_minus_k = 1 - self.k
|
||||||
|
self.one_minus_k_div_k = self.one_minus_k / self.k
|
||||||
|
self.ak = self.a * self.k
|
||||||
|
|
||||||
|
print(f"R:{self.R} l:{self.a} k:{self.k}")
|
||||||
|
|
||||||
self.background = pg.Surface((self.max_size, self.max_size))
|
self.background = pg.Surface((self.max_size, self.max_size))
|
||||||
self.background.fill(Colors.Black)
|
self.background.fill(Colors.Black)
|
||||||
self.background.set_alpha(5)
|
# self.background.set_alpha(4)
|
||||||
|
self.background.set_alpha(random.randint(1, 30))
|
||||||
|
|
||||||
super().__init__(
|
super().__init__(
|
||||||
image,
|
image,
|
||||||
pg.Rect(
|
pg.Rect(
|
||||||
|
@ -44,7 +56,7 @@ class Spiro(Effect):
|
||||||
self.size,
|
self.size,
|
||||||
self.size,
|
self.size,
|
||||||
),
|
),
|
||||||
*groups
|
*groups,
|
||||||
)
|
)
|
||||||
self.bounds = bounds
|
self.bounds = bounds
|
||||||
self.bouncer = transform_bounce(
|
self.bouncer = transform_bounce(
|
||||||
|
@ -52,22 +64,17 @@ class Spiro(Effect):
|
||||||
)
|
)
|
||||||
next(self.bouncer)
|
next(self.bouncer)
|
||||||
|
|
||||||
self.R = random.randint(1, 10) / 2
|
|
||||||
self.r = random.randint(1, int(self.R+0.6)) / 2
|
|
||||||
self.a = random.randint(1, 5)
|
|
||||||
print(f'R:{self.R} r:{self.r} a:{self.a}')
|
|
||||||
self.size_f = (self.size*0.6 - 10) / 2 / (self.R + self.r)
|
|
||||||
self.cursor = self.calc_pos()
|
self.cursor = self.calc_pos()
|
||||||
self.update()
|
self.update()
|
||||||
|
|
||||||
def calc_pos(self):
|
def calc_pos(self):
|
||||||
x = self.max_size / 2 + self.size_f * (
|
x = self.max_size / 2 + self.R * (
|
||||||
(self.R - self.r) * math.cos(self.r / self.R * self.ticks)
|
self.one_minus_k * math.cos(self.ticks)
|
||||||
+ self.a * math.cos((1 - self.r / self.R) * self.ticks)
|
+ self.ak * math.cos(self.one_minus_k_div_k * self.ticks)
|
||||||
)
|
)
|
||||||
y = self.max_size / 2 + self.size_f * (
|
y = self.max_size / 2 + self.R * (
|
||||||
(self.R - self.r) * math.sin(self.r / self.R * self.ticks)
|
self.one_minus_k * math.sin(self.ticks)
|
||||||
+ self.a * math.sin((1 - self.r / self.R) * self.ticks)
|
- self.ak * math.sin(self.one_minus_k_div_k * self.ticks)
|
||||||
)
|
)
|
||||||
return x, y
|
return x, y
|
||||||
|
|
||||||
|
@ -79,25 +86,20 @@ class Spiro(Effect):
|
||||||
# new_scale = new_size - self.rect.width
|
# new_scale = new_size - self.rect.width
|
||||||
# self.rect.inflate_ip(new_scale, new_scale)
|
# self.rect.inflate_ip(new_scale, new_scale)
|
||||||
|
|
||||||
# self.rect.center = self.bouncer.send(self.rect.size)
|
self.rect.center = self.bouncer.send(self.rect.size)
|
||||||
|
|
||||||
self.image.blit(self.background, (0, 0))
|
self.image.blit(self.background, (0, 0))
|
||||||
|
|
||||||
new_cursor = self.calc_pos()
|
for _ in range(self.scan_speed):
|
||||||
pg.draw.line(
|
new_cursor = self.calc_pos()
|
||||||
self.image,
|
pg.draw.line(
|
||||||
self.color if isinstance(self.color, pg.Color) else next(self.color),
|
self.image,
|
||||||
self.cursor,
|
self.color if isinstance(self.color, pg.Color) else next(self.color),
|
||||||
new_cursor,
|
self.cursor,
|
||||||
width=10,
|
new_cursor,
|
||||||
)
|
width=10,
|
||||||
self.cursor = new_cursor
|
)
|
||||||
|
self.cursor = new_cursor
|
||||||
|
self.ticks += self.velocity
|
||||||
|
|
||||||
# pg.draw.ellipse(
|
|
||||||
# self.image,
|
|
||||||
# self.color if isinstance(self.color, pg.Color) else next(self.color),
|
|
||||||
# ((0, 0), self.rect.size),
|
|
||||||
# )
|
|
||||||
|
|
||||||
self.ticks += self.velocity
|
|
||||||
# self.velocity = random.randint(self.min_velocity, self.max_velocity)
|
# self.velocity = random.randint(self.min_velocity, self.max_velocity)
|
||||||
|
|
|
@ -74,7 +74,7 @@ class Starfield(Effect):
|
||||||
self.stars: List[Spot] = []
|
self.stars: List[Spot] = []
|
||||||
|
|
||||||
self.randrange = (
|
self.randrange = (
|
||||||
(bounds.width - 2 * self.radius) // (self.radius * 3),
|
(bounds.width - 3 * self.radius) // (self.radius * 2),
|
||||||
(bounds.height - 2 * self.radius) // (self.radius * 2),
|
(bounds.height - 2 * self.radius) // (self.radius * 2),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue