starfield add
This commit is contained in:
parent
0dffaf7039
commit
a8210a13d0
6 changed files with 122 additions and 14 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -18,6 +18,6 @@ nuitka-crash-report.xml
|
|||
combined_config.txt
|
||||
firefox_config.txt
|
||||
test/
|
||||
assets/
|
||||
lang/
|
||||
test.py
|
||||
test.py
|
||||
download/
|
BIN
assets/icon.png
Normal file
BIN
assets/icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 30 KiB |
BIN
assets/logo.png
Normal file
BIN
assets/logo.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 24 KiB |
BIN
assets/pattern.png
Normal file
BIN
assets/pattern.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 540 KiB |
|
@ -1,13 +1,16 @@
|
|||
import threading
|
||||
from customtkinter import *
|
||||
from tkinter import PhotoImage
|
||||
from PIL import Image, ImageTk
|
||||
|
||||
import download_main
|
||||
from star_field import StarField
|
||||
|
||||
def run_installer(download_folder_tmp):
|
||||
global visible_widgets # Declare visible_widgets as a global variable
|
||||
global visible_widgets, tab_combobox # Declare tab_combobox as a global variable
|
||||
|
||||
app = CTk()
|
||||
app.geometry("600x600")
|
||||
app.geometry("800x600")
|
||||
|
||||
set_default_color_theme("dark-blue")
|
||||
set_appearance_mode("dark")
|
||||
|
@ -33,6 +36,28 @@ def run_installer(download_folder_tmp):
|
|||
# Pack the label to display it
|
||||
progress_label.pack(pady=20, padx=20)
|
||||
|
||||
# Function to load and display an image
|
||||
def display_image():
|
||||
img = PhotoImage(file="./assets/icon.png") # Specify the path to your image
|
||||
|
||||
# Calculate the center position
|
||||
canvas_width = canvas.winfo_width()
|
||||
canvas_height = canvas.winfo_height()
|
||||
image_width = img.width()
|
||||
image_height = img.height()
|
||||
|
||||
x_center = (app.winfo_width() - image_width) // 2
|
||||
y_center = (app.winfo_height() - image_height) // 2
|
||||
|
||||
# Display the image at the center
|
||||
canvas.create_image((app.winfo_width() - 400) // 2, y_center, anchor="nw", image=img)
|
||||
canvas.image = img # Keep a reference to avoid garbage collection
|
||||
|
||||
def display_star_field():
|
||||
# Create an instance of the StarField class
|
||||
global star_field # Keep a reference to avoid garbage collection
|
||||
star_field = StarField(app, 400, 600)
|
||||
star_field.canvas.pack(side="left", fill="y") # Pack the StarField canvas on the left side
|
||||
|
||||
# Dictionary to store tabs and their widgets
|
||||
tabs = {
|
||||
|
@ -62,8 +87,19 @@ def run_installer(download_folder_tmp):
|
|||
# List to store the currently visible widgets
|
||||
visible_widgets = []
|
||||
|
||||
# Variable to store the CTkProgressBar in Tab3
|
||||
progress_bar = None
|
||||
def display_star_field(container):
|
||||
# Create an instance of the StarField class
|
||||
global star_field # Keep a reference to avoid garbage collection
|
||||
star_field = StarField(app, 400, 600)
|
||||
star_field.canvas.pack(side="left", fill="y") # Pack the StarField canvas on the left side
|
||||
|
||||
def create_widgets_for_current_tab(container):
|
||||
current_tab = tab_combobox.get()
|
||||
widget_specs = tabs.get(current_tab, [])
|
||||
widgets = [create_widget(spec, container) for spec in widget_specs]
|
||||
for widget in widgets:
|
||||
widget.pack(pady=20, padx=20)
|
||||
return widgets
|
||||
|
||||
# Function to switch to a specified tab
|
||||
def switch_to_tab(tab_name):
|
||||
|
@ -130,11 +166,21 @@ def run_installer(download_folder_tmp):
|
|||
# For other widget classes, create them without additional details
|
||||
return spec(master=master)
|
||||
|
||||
def display_star_field(container):
|
||||
# Create an instance of the StarField class
|
||||
global star_field # Keep a reference to avoid garbage collection
|
||||
star_field = StarField(container, 400, 600) # Use container as the parent
|
||||
star_field.canvas.pack(side="left", fill="y") # Pack the StarField canvas on the left side
|
||||
|
||||
# Create a container frame for widgets
|
||||
container = CTkFrame(app)
|
||||
container.pack()
|
||||
container.pack(side="right") # Place the container on the right side
|
||||
|
||||
# Create a combobox to select the current tab
|
||||
# Display the StarField initially
|
||||
display_star_field(container)
|
||||
|
||||
|
||||
# Create a combobox to select the current tab
|
||||
tab_combobox = CTkComboBox(master=app, values=list(tabs.keys()))
|
||||
tab_combobox.set(list(tabs.keys())[0])
|
||||
tab_combobox.pack_forget() # Hide the combobox
|
||||
|
@ -142,12 +188,6 @@ def run_installer(download_folder_tmp):
|
|||
# Initialize the visible widgets with the widgets from the initial tab
|
||||
visible_widgets = create_widgets_for_current_tab()
|
||||
|
||||
# Button to trigger the gradual slide-to-right effect
|
||||
CTkButton(master=app, text="Next", command=switch_to_next_tab).pack(pady=10)
|
||||
# Button to trigger the gradual slide-to-left effect
|
||||
CTkButton(master=app, text="Previous", command=switch_to_previous_tab).pack(pady=10)
|
||||
|
||||
app.mainloop()
|
||||
|
||||
# # Example usage
|
||||
# run_installer("your_download_folder")
|
||||
|
|
68
src/star_field.py
Normal file
68
src/star_field.py
Normal file
|
@ -0,0 +1,68 @@
|
|||
import math
|
||||
from tkinter import Canvas
|
||||
from random import randrange # Add this import statement
|
||||
|
||||
class Star:
|
||||
__slots__ = ['x', 'y', 'z', 'id', 'radius', 'fill']
|
||||
|
||||
def __init__(self, x, y, z) -> None:
|
||||
super().__init__()
|
||||
self.id = None
|
||||
self.x = x
|
||||
self.y = y
|
||||
self.z = z
|
||||
self.radius = 1
|
||||
self.fill = 0
|
||||
|
||||
class StarField:
|
||||
def __init__(self, master, width, height, depth=32, num_stars=500):
|
||||
self.master = master
|
||||
self.fov = 180 * math.pi / 180
|
||||
self.view_distance = 0
|
||||
self.stars = []
|
||||
self.width = width
|
||||
self.height = height
|
||||
self.max_depth = depth
|
||||
self.center_x = width / 2
|
||||
self.center_y = height / 2
|
||||
self.circular_mask_radius = min(self.center_x, self.center_y)
|
||||
self.canvas = Canvas(master, width=width, height=height, bg="#000000")
|
||||
self.canvas.pack()
|
||||
|
||||
for x in range(num_stars):
|
||||
star = Star(x=randrange(-self.width, self.width),
|
||||
y=randrange(-self.height, self.height),
|
||||
z=randrange(1, self.max_depth))
|
||||
star.id = self.canvas.create_oval(star.x - star.radius, star.y - star.radius,
|
||||
star.x + star.radius, star.y + star.radius, fill='#FFFFFF')
|
||||
self.stars.append(star)
|
||||
|
||||
self.draw()
|
||||
|
||||
def draw(self):
|
||||
for star in self.stars:
|
||||
# move depth
|
||||
star.z -= 0.19
|
||||
star.radius = (1 - float(star.z) / self.max_depth) * 1.7
|
||||
star.fill = int((1 - float(star.z) / self.max_depth) * 255)
|
||||
|
||||
# reset depth
|
||||
if star.z <= 0:
|
||||
star.x = randrange(-self.width, self.width)
|
||||
star.y = randrange(-self.height, self.height)
|
||||
star.z = self.max_depth
|
||||
star.radius = 1
|
||||
star.fill = 0
|
||||
|
||||
# Transforms this 3D point to 2D using a perspective projection.
|
||||
factor = self.fov / (self.view_distance + star.z)
|
||||
x = star.x * factor + self.center_x
|
||||
y = -star.y * factor + self.center_y
|
||||
|
||||
# Check if the star is inside the circular mask
|
||||
distance_to_center = math.sqrt((x - self.center_x) ** 2 + (y - self.center_y) ** 2)
|
||||
if distance_to_center <= self.circular_mask_radius:
|
||||
self.canvas.coords(star.id, x - star.radius, y - star.radius, x + star.radius, y + star.radius)
|
||||
self.canvas.itemconfig(star.id, fill='#%02x%02x%02x' % (star.fill, star.fill, star.fill))
|
||||
|
||||
self.canvas.after(30, self.draw)
|
Reference in a new issue