prerender glow effect into logo background

This commit is contained in:
ohsqueezy 2022-11-02 23:19:14 -04:00
parent e85d8ee74f
commit d95b31a19b
2 changed files with 21 additions and 33 deletions

50
NS.py
View File

@ -883,12 +883,12 @@ class Video(Sprite):
gifs.append(Image.open(path)) gifs.append(Image.open(path))
print(gifs[-1].info) print(gifs[-1].info)
self.gif_index = 0 self.gif_index = 0
self.mask = Surface([diameter] * 2, SRCALPHA) mask = Surface([diameter] * 2, SRCALPHA)
rect = self.mask.get_rect() rect = mask.get_rect()
alpha = int(self.get_configuration("display", "attract-gif-alpha") * 255) alpha = int(self.get_configuration("display", "attract-gif-alpha") * 255)
filled_circle(self.mask, rect.centerx, rect.centery, rect.centerx, (0, 0, 0, alpha)) filled_circle(mask, rect.centerx, rect.centery, rect.centerx, (0, 0, 0, alpha))
filled_circle(self.mask, rect.centerx, rect.centery, rect.centerx - 2, (255, 255, 255, alpha)) filled_circle(mask, rect.centerx, rect.centery, rect.centerx - 2, (255, 255, 255, alpha))
self.add_frame(self.mask) self.add_frame(mask)
if not self.get_configuration("system", "minimize-load-time"): if not self.get_configuration("system", "minimize-load-time"):
self.play() self.play()
# preload GIF frames scaled instead of loading each frame like before # preload GIF frames scaled instead of loading each frame like before
@ -899,8 +899,8 @@ class Video(Sprite):
gif.seek(ii) gif.seek(ii)
frame_scaled = smoothscale( frame_scaled = smoothscale(
fromstring(gif.convert("RGBA").tobytes(), gif.size, "RGBA"), fromstring(gif.convert("RGBA").tobytes(), gif.size, "RGBA"),
(self.mask.get_width(), int(gif.width * gif.height / self.mask.get_width()))) (mask.get_width(), int(gif.width * gif.height / mask.get_width())))
copy = self.mask.copy() copy = mask.copy()
rect = frame_scaled.get_rect() rect = frame_scaled.get_rect()
rect.bottom = copy.get_rect().bottom rect.bottom = copy.get_rect().bottom
copy.blit(frame_scaled, rect, None, BLEND_RGBA_MIN) copy.blit(frame_scaled, rect, None, BLEND_RGBA_MIN)
@ -930,32 +930,26 @@ class Logo(Sprite):
def __init__(self, parent): def __init__(self, parent):
""" """
Load the logo and add locations at regular offsets until the screen is covered to create a tile fill effect. Create a second Load the logo and create a glowing version by creating multiple frames, each with a glow effect blended onto it.
Sprite that will display a glow effect that can be blended into the main layer.
""" """
Sprite.__init__(self, parent) Sprite.__init__(self, parent, 60)
dsr = self.get_display_surface().get_rect() dsr = self.get_display_surface().get_rect()
self.load_from_path(self.get_resource("Title_tile.png"), True) mask = pygame.image.load(self.get_resource("Title_tile.png")).convert()
palette = (255, 255, 255), (255, 255, 128), (255, 255, 0)
thickness = 8
for offset in range(len(palette)):
tile = mask.copy()
for x in range(0, dsr.w, thickness):
tile.fill(palette[(offset + x) % len(palette)], (x, 0, thickness, dsr.h), pygame.BLEND_RGB_MIN)
self.add_frame(tile)
for y in range(0, dsr.h + self.location.h, self.location.h): for y in range(0, dsr.h + self.location.h, self.location.h):
for x in range(0, dsr.w + self.location.w, self.location.w): for x in range(0, dsr.w + self.location.w, self.location.w):
if x != 0 or y != 0: if x != 0 or y != 0:
self.add_location((x, y)) self.add_location((x, y))
# Create a screen sized Sprite to create a glowing animation drawn onto blank frames
if self.get_configuration("display", "effects"):
self.effect = Sprite(self, 100)
palette = (255, 255, 255), (255, 255, 128), (255, 255, 0)
thickness = 8
for offset in range(len(palette)):
frame = Surface(dsr.size)
for x in range(0, dsr.w, thickness):
frame.fill(palette[(offset + x) % len(palette)], (x, 0, thickness, dsr.h))
self.effect.add_frame(frame)
def update(self): def update(self):
""" """
Scroll the tiles, wrapping at the edges of the screen. Draw the effect layer beneath the logo tile and blend with the logo Scroll the tiles, wrapping at the edges of the screen.
if effects are on.
""" """
# Wrap around motion effect # Wrap around motion effect
self.move(-2, 2) self.move(-2, 2)
@ -963,13 +957,7 @@ class Logo(Sprite):
self.move(self.location.w) self.move(self.location.w)
if self.location.top > 0: if self.location.top > 0:
self.move(dy=-self.location.h) self.move(dy=-self.location.h)
Sprite.update(self)
# Blend with the effect layer if effects are on
if self.get_configuration("display", "effects"):
self.effect.update()
Sprite.update(self, flags=BLEND_RGBA_MIN)
else:
Sprite.update(self)
class Title(Animation): class Title(Animation):

4
config
View File

@ -25,8 +25,8 @@ caption = Scrapeboard
show-framerate = no show-framerate = no
dimensions = 800, 450 dimensions = 800, 450
fullscreen = no fullscreen = no
attract-gif-alpha = 0.95 attract-gif-alpha = 1.0
effects = False effects = True
[system] [system]
# will force set display->effects to off # will force set display->effects to off