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$/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/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>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -33,18 +33,18 @@
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent"><![CDATA[{
"keyToString": {
"ModuleVcsDetector.initialDetectionPerformed": "true",
"RunOnceActivity.ShowReadmeOnStart": "true",
"RunOnceActivity.TerminalTabsStorage.copyFrom.TerminalArrangementManager": "true",
"RunOnceActivity.git.unshallow": "true",
"git-widget-placeholder": "main",
"last_opened_file_path": "/home/linus/Desktop/HomeLabProjects/StarSkyPresenter/src/starsky_presenter/main.py",
"settings.editor.selected.configurable": "preferences.pluginManager",
"uv run.StarSky Presenter.executor": "Run"
<component name="PropertiesComponent">{
&quot;keyToString&quot;: {
&quot;ModuleVcsDetector.initialDetectionPerformed&quot;: &quot;true&quot;,
&quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;,
&quot;RunOnceActivity.TerminalTabsStorage.copyFrom.TerminalArrangementManager&quot;: &quot;true&quot;,
&quot;RunOnceActivity.git.unshallow&quot;: &quot;true&quot;,
&quot;git-widget-placeholder&quot;: &quot;main&quot;,
&quot;last_opened_file_path&quot;: &quot;/home/linus/Desktop/HomeLabProjects/StarSkyPresenter/src/starsky_presenter/main.py&quot;,
&quot;settings.editor.selected.configurable&quot;: &quot;preferences.pluginManager&quot;,
&quot;uv run.StarSky Presenter.executor&quot;: &quot;Run&quot;
}
}]]></component>
}</component>
<component name="RecentsManager">
<key name="CopyFile.RECENT_KEYS">
<recent name="$PROJECT_DIR$/resources" />

View File

@ -52,7 +52,10 @@ def cli_main():
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)
while control_window.is_running():

View File

@ -1,7 +1,7 @@
import json
import pygame
from pygame import transform, gfxdraw, Vector2
from pygame import transform, gfxdraw, Vector2, Surface
from math import sin, cos, pi
from time import time, sleep
@ -19,7 +19,7 @@ class Star:
self.image = image
class Screen:
def __init__(self, stars: list[Star]) -> None:
def __init__(self, stars: list[Star], background: Surface | None) -> None:
if not pygame.get_init():
pygame.init()
self.screen = pygame.display.set_mode((1920, 1080))
@ -30,6 +30,8 @@ class Screen:
self.active_scene = 0
self.last_scene = 0
self.scene_time: float = 0
self.background = background
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.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:
update_star_scene(star, scene_data[self.last_scene], scene_data[self.active_scene], weight)
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
rot: 30
offset: 0
image: star.png
image: BasicStar1.png
- sid: star-bg-02
x: 0.3
y: 0.4
@ -14,4 +14,5 @@ stars:
alpha: 25
rot: 29
offset: 0
image: star.png
image: BasicStar1.png
background: background-01.jpg