mostly done with rendering
This commit is contained in:
parent
78cf579e0f
commit
095a18b0ea
1
.idea/workspace.xml
generated
1
.idea/workspace.xml
generated
@ -8,6 +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/main_window.qml" beforeDir="false" afterPath="$PROJECT_DIR$/src/starsky_presenter/resources/main_window.qml" 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" />
|
<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" />
|
||||||
|
|||||||
@ -6,6 +6,7 @@ from importlib.readers import FileReader
|
|||||||
from importlib.machinery import SourcelessFileLoader
|
from importlib.machinery import SourcelessFileLoader
|
||||||
from io import BufferedReader
|
from io import BufferedReader
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from time import time
|
||||||
|
|
||||||
import yaml
|
import yaml
|
||||||
from random import random, seed
|
from random import random, seed
|
||||||
@ -37,14 +38,15 @@ def cli_main():
|
|||||||
|
|
||||||
star_references = {}
|
star_references = {}
|
||||||
|
|
||||||
print(json.dumps(scenes, indent=4))
|
#print(json.dumps(scenes, indent=4))
|
||||||
print(json.dumps(objects, indent=4))
|
#print(json.dumps(objects, indent=4))
|
||||||
print(json.dumps(scene_data, indent=4))
|
#print(json.dumps(scene_data, indent=4))
|
||||||
|
|
||||||
def setup_star_instance(data: dict) -> Star:
|
def setup_star_instance(data: dict) -> Star:
|
||||||
image_path = f"resources/{data['image']}"
|
image_path = f"resources/{data['image']}"
|
||||||
image = pygame.image.load(reader.open_resource(image_path))
|
image = pygame.image.load(reader.open_resource(image_path))
|
||||||
data['image'] = image
|
data['image'] = image
|
||||||
|
|
||||||
star = Star(**data)
|
star = Star(**data)
|
||||||
star_references[data['sid']] = star
|
star_references[data['sid']] = star
|
||||||
return star
|
return star
|
||||||
@ -58,13 +60,21 @@ def cli_main():
|
|||||||
screen = Screen(stars, background)
|
screen = Screen(stars, background)
|
||||||
control_window = ControlWindow(screen)
|
control_window = ControlWindow(screen)
|
||||||
|
|
||||||
|
last_time = time()
|
||||||
|
|
||||||
while control_window.is_running():
|
while control_window.is_running():
|
||||||
control_window.process_events()
|
control_window.process_events()
|
||||||
screen.update(scene_data)
|
screen.update(scene_data)
|
||||||
|
now = time()
|
||||||
|
print(f"{1/(now - last_time):.02f} fps")
|
||||||
|
last_time = now
|
||||||
|
|
||||||
|
|
||||||
screen.close()
|
screen.close()
|
||||||
control_window.close()
|
control_window.close()
|
||||||
|
pygame.quit()
|
||||||
|
|
||||||
|
exit(0)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -18,11 +18,12 @@ class Star:
|
|||||||
self.offset = offset
|
self.offset = offset
|
||||||
self.image = image
|
self.image = image
|
||||||
|
|
||||||
|
|
||||||
class Screen:
|
class Screen:
|
||||||
def __init__(self, stars: list[Star], background: Surface | None) -> 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), display=1, flags=pygame.FULLSCREEN | pygame.DOUBLEBUF | pygame.WINDOWTAKEFOCUS)
|
||||||
self.clock = pygame.time.Clock()
|
self.clock = pygame.time.Clock()
|
||||||
self.stars = stars
|
self.stars = stars
|
||||||
self.last = time()
|
self.last = time()
|
||||||
@ -30,7 +31,19 @@ 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
|
if background:
|
||||||
|
ratio_x = self.screen.get_width() / background.get_width()
|
||||||
|
ratio_y = self.screen.get_height() / background.get_height()
|
||||||
|
scaled_background = transform.rotozoom(background, 0, max(ratio_x, ratio_y))
|
||||||
|
|
||||||
|
self.bg_pos = (
|
||||||
|
(self.screen.get_width() - scaled_background.get_width()) / 2,
|
||||||
|
(self.screen.get_height() - scaled_background.get_height()) / 2
|
||||||
|
)
|
||||||
|
self.background = scaled_background
|
||||||
|
else:
|
||||||
|
self.background = None
|
||||||
|
self.bg_pos = None
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -49,27 +62,22 @@ 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
|
# first draw the background, if any
|
||||||
if self.background:
|
if self.background:
|
||||||
ratio_x = self.screen.get_width() / self.background.get_width()
|
self.screen.blit(self.background, self.bg_pos)
|
||||||
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
|
# 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
|
||||||
scaled = transform.rotozoom(star.image, star.alpha, star.scale)
|
computed_scale = star.scale * (self.screen.get_width() / star.image.get_width() / 100)
|
||||||
|
scaled = transform.rotozoom(star.image, star.alpha, computed_scale)
|
||||||
(w, h) = scaled.get_size()
|
(w, h) = scaled.get_size()
|
||||||
pos = (star.x*self.screen.get_width() - w/2, star.y*self.screen.get_height() - h/2)
|
pos = (star.x*self.screen.get_width() - w/2, star.y*self.screen.get_height() - h/2)
|
||||||
self.screen.blit(scaled, pos)
|
self.screen.blit(scaled, pos)
|
||||||
|
|
||||||
|
|
||||||
overlay = pygame.surface.Surface((1920, 1080), depth=32)
|
overlay = pygame.surface.Surface((1920, 1080), depth=32)
|
||||||
overlay.set_alpha(int(255 * (1 - self.brightness)))
|
overlay.set_alpha(int(255 * (1 - self.brightness)))
|
||||||
self.screen.blit(overlay, (0, 0))
|
self.screen.blit(overlay, (0, 0))
|
||||||
|
|||||||
@ -8,7 +8,8 @@ ApplicationWindow {
|
|||||||
width: 800
|
width: 800
|
||||||
height: 600
|
height: 600
|
||||||
title: "StarSky Presenter"
|
title: "StarSky Presenter"
|
||||||
flags: Qt.FramelessWindowHint
|
flags: Qt.WindowCloseButtonHint | Qt.WindowStaysOnBottomHint
|
||||||
|
modality: Qt.ApplicationModal
|
||||||
|
|
||||||
Button {
|
Button {
|
||||||
anchors.horizontalCenter: parent.horizontalCenter
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
|
|||||||
@ -1,18 +1,18 @@
|
|||||||
stars:
|
stars:
|
||||||
- sid: star-bg-01
|
- sid: star-1
|
||||||
x: 0.1
|
x: 0.1
|
||||||
y: 0.1
|
y: 0.1
|
||||||
scale: 0.6
|
scale: 2
|
||||||
alpha: 0
|
alpha: 0
|
||||||
rot: 30
|
rot: 30
|
||||||
offset: 0
|
offset: 0
|
||||||
image: BasicStar1.png
|
image: nice-star-1.png
|
||||||
- sid: star-bg-02
|
- sid: star-2
|
||||||
x: 0.3
|
x: 0.25
|
||||||
y: 0.4
|
y: 0.4
|
||||||
scale: 0.8
|
scale: 2
|
||||||
alpha: 25
|
alpha: 25
|
||||||
rot: 29
|
rot: 29
|
||||||
offset: 0
|
offset: 0
|
||||||
image: BasicStar1.png
|
image: nice-star-2.png
|
||||||
background: background-01.jpg
|
background: background-01.jpg
|
||||||
Loading…
x
Reference in New Issue
Block a user