added background functionality

This commit is contained in:
Linus Vogel 2025-12-06 16:14:22 +01:00
parent eb6547eb1a
commit 7403c84df8
6 changed files with 35 additions and 17 deletions

24
.idea/workspace.xml generated
View File

@ -8,7 +8,7 @@
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/starsky_presenter/entry.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/starsky_presenter/entry.py" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/starsky_presenter/entry.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/starsky_presenter/entry.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/starsky_presenter/projection/screen.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/starsky_presenter/projection/screen.py" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/starsky_presenter/projection/screen.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/starsky_presenter/projection/screen.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/starsky_presenter/resources/scenes.yml" beforeDir="false" afterPath="$PROJECT_DIR$/src/starsky_presenter/resources/scenes.yml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/starsky_presenter/resources/objects.yml" beforeDir="false" afterPath="$PROJECT_DIR$/src/starsky_presenter/resources/objects.yml" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -33,18 +33,18 @@
<option name="hideEmptyMiddlePackages" value="true" /> <option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" /> <option name="showLibraryContents" value="true" />
</component> </component>
<component name="PropertiesComponent"><![CDATA[{ <component name="PropertiesComponent">{
"keyToString": { &quot;keyToString&quot;: {
"ModuleVcsDetector.initialDetectionPerformed": "true", &quot;ModuleVcsDetector.initialDetectionPerformed&quot;: &quot;true&quot;,
"RunOnceActivity.ShowReadmeOnStart": "true", &quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;,
"RunOnceActivity.TerminalTabsStorage.copyFrom.TerminalArrangementManager": "true", &quot;RunOnceActivity.TerminalTabsStorage.copyFrom.TerminalArrangementManager&quot;: &quot;true&quot;,
"RunOnceActivity.git.unshallow": "true", &quot;RunOnceActivity.git.unshallow&quot;: &quot;true&quot;,
"git-widget-placeholder": "main", &quot;git-widget-placeholder&quot;: &quot;main&quot;,
"last_opened_file_path": "/home/linus/Desktop/HomeLabProjects/StarSkyPresenter/src/starsky_presenter/main.py", &quot;last_opened_file_path&quot;: &quot;/home/linus/Desktop/HomeLabProjects/StarSkyPresenter/src/starsky_presenter/main.py&quot;,
"settings.editor.selected.configurable": "preferences.pluginManager", &quot;settings.editor.selected.configurable&quot;: &quot;preferences.pluginManager&quot;,
"uv run.StarSky Presenter.executor": "Run" &quot;uv run.StarSky Presenter.executor&quot;: &quot;Run&quot;
} }
}]]></component> }</component>
<component name="RecentsManager"> <component name="RecentsManager">
<key name="CopyFile.RECENT_KEYS"> <key name="CopyFile.RECENT_KEYS">
<recent name="$PROJECT_DIR$/resources" /> <recent name="$PROJECT_DIR$/resources" />

View File

@ -52,7 +52,10 @@ def cli_main():
stars = [ setup_star_instance(star) for star in objects["stars"] ] stars = [ setup_star_instance(star) for star in objects["stars"] ]
screen = Screen(stars) # load the background image
background = pygame.image.load(reader.open_resource(f"resources/{objects['background']}"))
screen = Screen(stars, background)
control_window = ControlWindow(screen) control_window = ControlWindow(screen)
while control_window.is_running(): while control_window.is_running():

View File

@ -1,7 +1,7 @@
import json import json
import pygame import pygame
from pygame import transform, gfxdraw, Vector2 from pygame import transform, gfxdraw, Vector2, Surface
from math import sin, cos, pi from math import sin, cos, pi
from time import time, sleep from time import time, sleep
@ -19,7 +19,7 @@ class Star:
self.image = image self.image = image
class Screen: class Screen:
def __init__(self, stars: list[Star]) -> None: def __init__(self, stars: list[Star], background: Surface | None) -> None:
if not pygame.get_init(): if not pygame.get_init():
pygame.init() pygame.init()
self.screen = pygame.display.set_mode((1920, 1080)) self.screen = pygame.display.set_mode((1920, 1080))
@ -30,6 +30,8 @@ class Screen:
self.active_scene = 0 self.active_scene = 0
self.last_scene = 0 self.last_scene = 0
self.scene_time: float = 0 self.scene_time: float = 0
self.background = background
def update(self, scene_data): def update(self, scene_data):
@ -47,7 +49,19 @@ class Screen:
star.rot = weight*new[star.sid]['rot'] + (1-weight)*old[star.sid]['rot'] star.rot = weight*new[star.sid]['rot'] + (1-weight)*old[star.sid]['rot']
star.scale = weight*new[star.sid]['scale'] + (1-weight)*old[star.sid]['scale'] star.scale = weight*new[star.sid]['scale'] + (1-weight)*old[star.sid]['scale']
# first draw the background, if any
if self.background:
ratio_x = self.screen.get_width() / self.background.get_width()
ratio_y = self.screen.get_height() / self.background.get_height()
scaled_background = transform.rotozoom(self.background, 0, max(ratio_x, ratio_y))
bg_pos = (
(self.screen.get_width() - scaled_background.get_width()) / 2,
(self.screen.get_height() - scaled_background.get_height()) / 2
)
self.screen.blit(scaled_background, bg_pos)
# draw all the star objects
for star in self.stars: for star in self.stars:
update_star_scene(star, scene_data[self.last_scene], scene_data[self.active_scene], weight) update_star_scene(star, scene_data[self.last_scene], scene_data[self.active_scene], weight)
star.alpha += star.rot * delta star.alpha += star.rot * delta

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 412 KiB

View File

@ -6,7 +6,7 @@ stars:
alpha: 0 alpha: 0
rot: 30 rot: 30
offset: 0 offset: 0
image: star.png image: BasicStar1.png
- sid: star-bg-02 - sid: star-bg-02
x: 0.3 x: 0.3
y: 0.4 y: 0.4
@ -14,4 +14,5 @@ stars:
alpha: 25 alpha: 25
rot: 29 rot: 29
offset: 0 offset: 0
image: star.png image: BasicStar1.png
background: background-01.jpg