File size: 2,565 Bytes
67316fb
 
 
e25aab1
67316fb
37c2ef4
77ab196
e25aab1
bec1327
 
67316fb
 
 
 
77ab196
e25aab1
 
 
 
 
67316fb
77ab196
 
e25aab1
67316fb
e25aab1
67316fb
e25aab1
77ab196
67316fb
e25aab1
67316fb
9ea7d32
 
 
 
 
 
 
 
 
 
67316fb
 
e25aab1
67316fb
 
9ea7d32
67316fb
9ea7d32
e25aab1
67316fb
e25aab1
 
67316fb
 
77ab196
 
c06407a
67316fb
 
722d60b
 
9ea7d32
 
77ab196
9ea7d32
67316fb
77ab196
9ea7d32
67316fb
e25aab1
67316fb
77ab196
67316fb
77ab196
67316fb
e25aab1
77ab196
c06407a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
from random import randint
import pygame
import numpy as np
import streamlit as st

import os
import time

os.system("pip install -r requirements.txt")
os.system("pip install --upgrade pip")
BG_COLOR = (0, 0, 0)
fullscreen = True

logo = pygame.image.load('dvd_logo_0002.png')
logo = pygame.transform.scale(logo, (50, 100))

logo = pygame.surfarray.array3d(logo)
logo = np.flip(logo, axis=1)
logo = pygame.surfarray.make_surface(logo)

img_size = logo.get_rect().size
screen_width = 850
screen_height = 540
screen = pygame.Surface((screen_height, screen_width))

screen.fill((0, 0, 0))

x = randint(0, screen_width - img_size[0])
y = randint(0, screen_height - img_size[1])
x_speed = 2
y_speed = 3



np_logo = pygame.surfarray.array3d(logo)

# Inverse the colors so that the background of the DVD logo is black and the letters are white
np_logo = np.where(np_logo >= 200, 0, np_logo+200)

dvd_letters_color = [255, 255, 255]
dvd_background_color = [0, 0, 0]
logo = pygame.surfarray.make_surface(np_logo)


def random_color_change(surface, color_to_be_changed):
    np_surface = pygame.surfarray.array3d(surface)
    for channel in range(np_surface.shape[-1]):
        random_channel_color = randint(30, 240)
        np_surface[:, :, channel] = np.where(
            np.logical_and(np_surface[:, :, channel] >= color_to_be_changed[channel]-20,
                           np_surface[:, :, channel] <= color_to_be_changed[channel]),
            random_channel_color, np_surface[:, :, channel])
        color_to_be_changed[channel] = random_channel_color
    return pygame.surfarray.make_surface(np_surface), color_to_be_changed


st_display_img = st.empty()

while True:
    screen.fill(BG_COLOR)

    if ((x + img_size[1] + x_speed >= screen_width) or (x + x_speed <= 0)) and \
            ((y + y_speed + img_size[0] >= screen_height) or (y + y_speed <= 0)):
        x -= int(4.5 * x_speed + 7)
        y -= int(3.5 * y_speed + 7)
    if (x + img_size[0] >= screen_height) or (x <= 0):
        logo, dvd_letters_color = random_color_change(logo, dvd_letters_color)
        x_speed = -x_speed
    if (y + img_size[1] >= screen_width) or (y <= 0):
        logo, dvd_letters_color = random_color_change(logo, dvd_letters_color)
        y_speed = -y_speed

    x += x_speed
    x = np.clip(x, 0, screen_height - img_size[0])
    y += y_speed
    y = np.clip(y, 0, screen_width - img_size[1])
    screen.blit(logo, (x, y))
    screen_np = pygame.surfarray.array3d(screen)
    st_display_img.image(screen_np, caption='Idle screen bouncing DVD logo')
    time.sleep(0.03)