Загрузка данных


import tkinter as tk
import random

class LoadingAnimation:
    def __init__(self):
        self.root = tk.Tk()
        self.root.title("")
        self.root.attributes('-fullscreen', True)
        self.root.overrideredirect(True)
        self.root.attributes('-transparentcolor', '#123456')
        self.root.configure(bg='#123456')

        self.screen_width = self.root.winfo_screenwidth()
        self.screen_height = self.root.winfo_screenheight()

        self.window_width = 800
        self.window_height = 220
        self.left = (self.screen_width - self.window_width) // 2
        self.top = (self.screen_height - self.window_height) // 2
        self.right = self.left + self.window_width
        self.bottom = self.top + self.window_height

        self.bar_height = 30
        self.bar_y = self.top + (self.window_height - self.bar_height) // 2
        self.bar_left = self.left + 30

        self.close_width = 20
        self.close_height = 20
        self.close_x = self.right - 30
        self.close_y = self.top + 5

        self.total_duration = 37.5
        self.blue_screen_duration = 3.0
        self.fade_duration = 2.0
        self.loading_start = 4.0
        self.loading_end = 28.0
        self.effect_start = 28.0
        self.fps = 60
        self.delta_time = 1.0 / self.fps
        self.elapsed = 0.0

        self.keyframes = [
            (self.loading_start, 0.0),
            (7.0, 0.10),
            (9.0, 0.10),
            (11.0, 0.25),
            (13.0, 0.25),
            (15.0, 0.35),
            (17.0, 0.35),
            (19.0, 0.50),
            (22.0, 0.70),
            (24.0, 0.85),
            (self.loading_end, 1.0),
        ]

        self.lines = [
            "IP: 192.168.1.100",
            "IPv4: 192.168.1.100",
            "Шлюз: 192.168.1.1",
            "DNS: 8.8.8.8",
            "Подключение установлено",
            "Мы выезжаем"
        ]
        self.current_line_index = 0
        self.current_char_index = 0
        self.text_displayed = ""

        self.text_animation_running = False
        self.text_completed = False

        self.canvas = tk.Canvas(
            self.root,
            width=self.screen_width,
            height=self.screen_height,
            highlightthickness=0,
            bg='#123456'
        )
        self.canvas.pack()

        self.animate()

        self.root.bind('<Escape>', lambda e: self.stop())

        self.root.mainloop()

    def draw_blue_screen(self, fade_factor):
        r = int(0 + (0x12 - 0) * fade_factor)
        g = int(0x44 + (0x34 - 0x44) * fade_factor)
        b = int(0xcc + (0x56 - 0xcc) * fade_factor)
        bg_color = f'#{r:02x}{g:02x}{b:02x}'

        self.canvas.create_rectangle(0, 0, self.screen_width, self.screen_height,
                                     fill=bg_color, outline='')

        r2 = int(255 + (0x12 - 255) * fade_factor)
        g2 = int(255 + (0x34 - 255) * fade_factor)
        b2 = int(255 + (0x56 - 255) * fade_factor)
        obj_color = f'#{r2:02x}{g2:02x}{b2:02x}'

        logo_size = 120
        logo_x = self.screen_width // 2 - logo_size // 2
        logo_y = self.screen_height // 2 - logo_size - 40
        gap = 6
        half = logo_size // 2 - gap // 2
        self.canvas.create_rectangle(logo_x, logo_y, logo_x + half, logo_y + half,
                                     fill=obj_color, outline='')
        self.canvas.create_rectangle(logo_x + half + gap, logo_y, logo_x + logo_size, logo_y + half,
                                     fill=obj_color, outline='')
        self.canvas.create_rectangle(logo_x, logo_y + half + gap, logo_x + half, logo_y + logo_size,
                                     fill=obj_color, outline='')
        self.canvas.create_rectangle(logo_x + half + gap, logo_y + half + gap,
                                     logo_x + logo_size, logo_y + logo_size,
                                     fill=obj_color, outline='')

        self.canvas.create_text(
            self.screen_width // 2, logo_y + logo_size + 60,
            text='Добро пожаловать в установщик Windows 9',
            font=('Arial', 28, 'bold'), fill=obj_color
        )

    def draw_window(self):
        self.canvas.create_rectangle(
            self.left, self.top, self.right, self.bottom,
            outline='#444', width=2, fill='#f0f0f0'
        )
        self.canvas.create_text(
            self.left + 10, self.top + 20,
            anchor='w', text='Установка Windows 9',
            font=('Arial', 14, 'bold'), fill='#333'
        )
        self.canvas.create_rectangle(
            self.close_x, self.close_y,
            self.close_x + self.close_width, self.close_y + self.close_height,
            fill='#ff4444', outline=''
        )
        self.canvas.create_text(
            self.close_x + self.close_width//2, self.close_y + self.close_height//2,
            text='✕', fill='white', font=('Arial', 10),
            anchor='center'
        )

    def draw_progress_bar(self, length):
        start_x = self.bar_left
        end_x = start_x + length
        if end_x <= self.screen_width:
            self.draw_segment(start_x, end_x)
        else:
            self.draw_segment(start_x, self.screen_width)
            self.draw_segment(0, end_x - self.screen_width)

    def draw_segment(self, x_start, x_end):
        if x_start >= x_end:
            return
        self.canvas.create_rectangle(
            x_start, self.bar_y,
            x_end, self.bar_y + self.bar_height,
            fill='#00cc44', outline=''
        )

    def draw_progress_text(self, progress):
        length = progress * self.screen_width
        window_inner_width = self.window_width - 60
        percent = (length / window_inner_width) * 100
        if percent > 999:
            percent = 999
        text = f"{int(percent)}%"
        self.canvas.create_text(
            self.right - 20, self.bottom - 30,
            anchor='e', text=text,
            font=('Arial', 18, 'bold'), fill='#333'
        )

    def get_progress(self, time_sec):
        for i in range(len(self.keyframes) - 1):
            t1, p1 = self.keyframes[i]
            t2, p2 = self.keyframes[i+1]
            if t1 <= time_sec <= t2:
                fraction = (time_sec - t1) / (t2 - t1)
                return p1 + (p2 - p1) * fraction
        return 1.0

    def update_text(self):
        if self.current_line_index >= len(self.lines):
            self.text_completed = True
            self.text_animation_running = False
            return

        current_line = self.lines[self.current_line_index]
        if self.current_char_index < len(current_line):
            self.text_displayed += current_line[self.current_char_index]
            self.current_char_index += 1
        else:
            self.current_line_index += 1
            self.current_char_index = 0
            if self.current_line_index < len(self.lines):
                self.text_displayed += "\n"
            else:
                self.text_completed = True
                self.text_animation_running = False
                return

        if self.text_animation_running:
            self.root.after(80, self.update_text)

    def draw_effect_with_text(self):
        r = random.randint(0, 255)
        g = random.randint(0, 255)
        b = random.randint(0, 255)
        color = f'#{r:02x}{g:02x}{b:02x}'
        self.canvas.configure(bg=color)
        self.canvas.create_rectangle(0, 0, self.screen_width, self.screen_height,
                                     fill=color, outline='')
        self.canvas.create_text(
            self.screen_width // 2, self.screen_height // 2,
            text=self.text_displayed,
            font=('Courier', 22, 'bold'),
            fill='black',
            anchor='center',
            justify='left'
        )

    def animate(self):
        self.canvas.delete("all")
        self.elapsed += self.delta_time
        if self.elapsed > self.total_duration:
            self.elapsed = self.total_duration

        if self.elapsed < self.blue_screen_duration:
            self.draw_blue_screen(fade_factor=0.0)

        elif self.elapsed < self.blue_screen_duration + self.fade_duration:
            fade = (self.elapsed - self.blue_screen_duration) / self.fade_duration
            self.draw_blue_screen(fade_factor=fade)

        elif self.elapsed < self.loading_end:
            mouse_x = self.root.winfo_pointerx()
            mouse_y = self.root.winfo_pointery()
            if (self.close_x - 5 <= mouse_x <= self.close_x + self.close_width + 5 and
                self.close_y - 5 <= mouse_y <= self.close_y + self.close_height + 5):
                min_x = self.left + 10
                max_x = self.right - 30 - self.close_width
                min_y = self.top + 5
                max_y = self.top + 50
                if max_x > min_x and max_y > min_y:
                    self.close_x = random.randint(min_x, max_x)
                    self.close_y = random.randint(min_y, max_y)

            self.draw_window()
            progress = self.get_progress(self.elapsed)
            length = progress * self.screen_width
            self.draw_progress_bar(length)
            self.draw_progress_text(progress)

        else:
            if not self.text_animation_running and not self.text_completed:
                self.text_animation_running = True
                self.update_text()
            self.draw_effect_with_text()

        if self.elapsed >= self.total_duration:
            self.root.after(500, self.stop)
            return

        self.root.after(int(1000 / self.fps), self.animate)

    def stop(self):
        self.root.destroy()



LoadingAnimation()