working on background
This commit is contained in:
parent
39606abcd7
commit
8affb416da
1
.idea/.idea.StarSkyPresenter/.idea/.name
generated
1
.idea/.idea.StarSkyPresenter/.idea/.name
generated
@ -1 +0,0 @@
|
||||
StarSkyPresenter
|
||||
@ -15,7 +15,7 @@ public partial class MainScript : Node2D
|
||||
|
||||
private Dictionary<string, Star> _stars = new Dictionary<string, Star>();
|
||||
private List<Scene> _scenes = new List<Scene>();
|
||||
private Sprite2D _background = null;
|
||||
private TextureRect _background = null;
|
||||
|
||||
// Called when the node enters the scene tree for the first time.
|
||||
public override void _Ready()
|
||||
@ -80,13 +80,19 @@ public partial class MainScript : Node2D
|
||||
this._stars.Clear();
|
||||
|
||||
Image bgImage = Image.LoadFromFile("resources/" + obj_conf.background);
|
||||
GD.Print("bgImage: " + bgImage);
|
||||
GD.Print("Resource Path: " + "resources/" + obj_conf.background);
|
||||
ImageTexture bgTexture = ImageTexture.CreateFromImage(bgImage);
|
||||
this._background = new Sprite2D();
|
||||
this._background.SetTexture(bgTexture);
|
||||
projection.AddChild(this._background);
|
||||
this._background.Position = Vector2.Zero;
|
||||
this._background.Scale = new Vector2(1, 1) * 100;
|
||||
this._background.ZIndex = 5;
|
||||
TextureRect background = this.GetNode<TextureRect>("/root/Main/Projection/Background");
|
||||
//this._background = new TextureRect();
|
||||
background.SetTexture(bgTexture);
|
||||
background.Position = Vector2.Zero;
|
||||
background.Size = projection.GetSize();
|
||||
background.Visible = true;
|
||||
//background.ZIndex = 5;
|
||||
//this.GetNode<Node>("/root/Main/Projection").AddChild(this._background);
|
||||
|
||||
|
||||
|
||||
foreach (StarConfig star_config in obj_conf.stars)
|
||||
{
|
||||
|
||||
0
build/lib/controller/__init__.py
Normal file
0
build/lib/controller/__init__.py
Normal file
28
build/lib/controller/controller.py
Normal file
28
build/lib/controller/controller.py
Normal file
@ -0,0 +1,28 @@
|
||||
from PyQt6.QtCore import QObject, pyqtSlot
|
||||
|
||||
from time import time
|
||||
|
||||
|
||||
class Controller(QObject):
|
||||
def __init__(self, window, parent=None):
|
||||
super().__init__(parent)
|
||||
self.window = window
|
||||
self.last_close_press = 0
|
||||
self.successful_clicks = 0
|
||||
|
||||
@pyqtSlot()
|
||||
def close_application(self):
|
||||
now = time()
|
||||
if now - self.last_close_press < 0.2:
|
||||
self.successful_clicks += 1
|
||||
else:
|
||||
self.successful_clicks = 0
|
||||
|
||||
if self.successful_clicks > 1:
|
||||
self.window.running = False
|
||||
|
||||
self.last_close_press = now
|
||||
|
||||
@pyqtSlot(int)
|
||||
def select_scene(self, scene: int):
|
||||
self.window.selected_scene = scene
|
||||
29
build/lib/controller/window.py
Normal file
29
build/lib/controller/window.py
Normal file
@ -0,0 +1,29 @@
|
||||
from PyQt6.QtGui import QGuiApplication
|
||||
from PyQt6.QtQml import QQmlApplicationEngine
|
||||
|
||||
from src.controller.controller import Controller
|
||||
from src.projection.screen import Screen
|
||||
|
||||
|
||||
class ControlWindow:
|
||||
def __init__(self):
|
||||
self.app = QGuiApplication([])
|
||||
self.running = True
|
||||
|
||||
self.engine = QQmlApplicationEngine(self.app)
|
||||
self.controller = Controller(self)
|
||||
self.engine.quit.connect(self.app.quit)
|
||||
self.engine.rootContext().setContextProperty("controller_backend", self.controller)
|
||||
self.engine.load("resources/main_window.qml")
|
||||
|
||||
|
||||
def process_events(self):
|
||||
return self.app.processEvents()
|
||||
|
||||
def is_running(self):
|
||||
return self.running
|
||||
|
||||
def close(self):
|
||||
self.app.quit()
|
||||
self.app.exit(0)
|
||||
self.app.processEvents()
|
||||
44
build/lib/main.py
Normal file
44
build/lib/main.py
Normal file
@ -0,0 +1,44 @@
|
||||
import sys
|
||||
|
||||
import json
|
||||
from random import random, seed
|
||||
|
||||
from pygame.transform import scale
|
||||
import pygame
|
||||
|
||||
from src.controller.window import ControlWindow
|
||||
from src.projection.screen import Screen, Star
|
||||
|
||||
|
||||
def cli_main():
|
||||
seed(43)
|
||||
image = pygame.image.load('resources/star.png')
|
||||
|
||||
stars = [
|
||||
Star(**{
|
||||
"_id": i,
|
||||
"x": random(),
|
||||
"y": random(),
|
||||
"alpha": random() * 360,
|
||||
"rot": random() * 360,
|
||||
"scale": random() * 0.5 + 0.25,
|
||||
"offset": random(),
|
||||
"image": image
|
||||
})
|
||||
for i in range(4)
|
||||
]
|
||||
|
||||
control_window = ControlWindow()
|
||||
screen = Screen(stars)
|
||||
|
||||
while control_window.is_running():
|
||||
control_window.process_events()
|
||||
screen.update()
|
||||
|
||||
screen.close()
|
||||
control_window.close()
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
cli_main()
|
||||
0
build/lib/projection/__init__.py
Normal file
0
build/lib/projection/__init__.py
Normal file
50
build/lib/projection/screen.py
Normal file
50
build/lib/projection/screen.py
Normal file
@ -0,0 +1,50 @@
|
||||
import pygame
|
||||
from pygame import transform, gfxdraw, Vector2
|
||||
from math import sin, cos, pi
|
||||
|
||||
from time import time, sleep
|
||||
from random import random
|
||||
|
||||
class Star:
|
||||
def __init__(self, _id: int, x: int, y: int, alpha: float, rot: float, scale: float, offset: float, image: pygame.Surface):
|
||||
self.id = _id
|
||||
self.x = x
|
||||
self.y = y
|
||||
self.rot = rot
|
||||
self.alpha = alpha
|
||||
self.scale = scale
|
||||
self.offset = offset
|
||||
self.image = image
|
||||
|
||||
class Screen:
|
||||
def __init__(self, stars: list[Star]) -> None:
|
||||
if not pygame.get_init():
|
||||
pygame.init()
|
||||
self.screen = pygame.display.set_mode((1920, 1080))
|
||||
self.clock = pygame.time.Clock()
|
||||
self.stars = stars
|
||||
self.last = time()
|
||||
self.brightness = 1.0
|
||||
|
||||
|
||||
def update(self):
|
||||
self.screen.fill((0, 0, 0))
|
||||
now = time()
|
||||
delta = now - self.last
|
||||
self.last = now
|
||||
for star in self.stars:
|
||||
star.alpha += star.rot * delta
|
||||
scaled = transform.rotozoom(star.image, star.alpha, star.scale)
|
||||
(w, h) = scaled.get_size()
|
||||
pos = (star.x*self.screen.get_width() - w/2, star.y*self.screen.get_height() - h/2)
|
||||
self.screen.blit(scaled, pos)
|
||||
|
||||
overlay = pygame.surface.Surface((1920, 1080), depth=32)
|
||||
overlay.set_alpha(int(255 * (1 - self.brightness)))
|
||||
self.screen.blit(overlay, (0, 0))
|
||||
|
||||
pygame.display.flip()
|
||||
self.clock.tick(60)
|
||||
|
||||
def close(self):
|
||||
pygame.quit()
|
||||
@ -63,3 +63,7 @@ oversampling_override = 1.0
|
||||
position = Vector2i(0, 36)
|
||||
size = Vector2i(1920, 1080)
|
||||
script = ExtResource("2_0e48y")
|
||||
|
||||
[node name="Background" type="TextureRect" parent="Projection"]
|
||||
offset_right = 40.0
|
||||
offset_bottom = 40.0
|
||||
|
||||
8
src/starsky.egg-info/PKG-INFO
Normal file
8
src/starsky.egg-info/PKG-INFO
Normal file
@ -0,0 +1,8 @@
|
||||
Metadata-Version: 2.4
|
||||
Name: starsky
|
||||
Version: 0.1.3
|
||||
Summary: Add your description here
|
||||
Requires-Python: >=3.13
|
||||
Description-Content-Type: text/markdown
|
||||
Requires-Dist: pygame>=2.6.1
|
||||
Requires-Dist: pyqt6>=6.10.0
|
||||
14
src/starsky.egg-info/SOURCES.txt
Normal file
14
src/starsky.egg-info/SOURCES.txt
Normal file
@ -0,0 +1,14 @@
|
||||
README.md
|
||||
pyproject.toml
|
||||
src/main.py
|
||||
src/controller/__init__.py
|
||||
src/controller/controller.py
|
||||
src/controller/window.py
|
||||
src/projection/__init__.py
|
||||
src/projection/screen.py
|
||||
src/starsky.egg-info/PKG-INFO
|
||||
src/starsky.egg-info/SOURCES.txt
|
||||
src/starsky.egg-info/dependency_links.txt
|
||||
src/starsky.egg-info/entry_points.txt
|
||||
src/starsky.egg-info/requires.txt
|
||||
src/starsky.egg-info/top_level.txt
|
||||
1
src/starsky.egg-info/dependency_links.txt
Normal file
1
src/starsky.egg-info/dependency_links.txt
Normal file
@ -0,0 +1 @@
|
||||
|
||||
2
src/starsky.egg-info/entry_points.txt
Normal file
2
src/starsky.egg-info/entry_points.txt
Normal file
@ -0,0 +1,2 @@
|
||||
[console_scripts]
|
||||
starsky = main:cli_main
|
||||
2
src/starsky.egg-info/requires.txt
Normal file
2
src/starsky.egg-info/requires.txt
Normal file
@ -0,0 +1,2 @@
|
||||
pygame>=2.6.1
|
||||
pyqt6>=6.10.0
|
||||
3
src/starsky.egg-info/top_level.txt
Normal file
3
src/starsky.egg-info/top_level.txt
Normal file
@ -0,0 +1,3 @@
|
||||
controller
|
||||
main
|
||||
projection
|
||||
BIN
src/starsky_presenter/__pycache__/__init__.cpython-313.pyc
Normal file
BIN
src/starsky_presenter/__pycache__/__init__.cpython-313.pyc
Normal file
Binary file not shown.
BIN
src/starsky_presenter/__pycache__/entry.cpython-313.pyc
Normal file
BIN
src/starsky_presenter/__pycache__/entry.cpython-313.pyc
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user