dcoste commited on
Commit
e25aab1
1 Parent(s): 37c2ef4

Streamlit ready. Probably not bug free

Browse files
Files changed (2) hide show
  1. app.py +36 -37
  2. dvd_logo_0002.png +0 -0
app.py CHANGED
@@ -1,69 +1,68 @@
1
  from random import randint
2
  import pygame
3
  import numpy as np
4
- import time
5
 
6
  import os
7
- os.system("pip install -r requirements.txt")
8
- exit = False
9
- # Settings
10
- # SIZE = width, height = 800, 600 # Resolution. (4:3)!
11
  BG_COLOR = (0, 0, 0)
12
  fullscreen = True
13
 
14
  logo = pygame.image.load('dvd_logo_0002.png')
15
- logo = pygame.transform.scale(logo, (200, 100))
16
- clock = pygame.time.Clock()
 
 
 
 
 
17
  img_size = logo.get_rect().size
18
- screen = pygame.display.set_mode()
19
- pygame.display.set_caption('Idle screen DVD bounce')
20
- screen_info = pygame.display.Info()
21
 
22
- if fullscreen:
23
- DISPLAYSURFACE = pygame.display.set_mode((0, 0), pygame.FULLSCREEN)
24
- pygame.mouse.set_visible(False)
25
 
26
- x = randint(50, screen_info.current_w - 200)
27
- y = randint(50, screen_info.current_h - 200)
 
28
  x_speed = 2
29
- y_speed = 2
30
 
31
  dvd_background_color = [255, 255, 255]
32
 
33
 
34
- def random_color_change(surface):
35
- global dvd_background_color
36
-
37
  np_surface = pygame.surfarray.array3d(surface)
38
  for channel in range(np_surface.shape[-1]):
39
  # np_surface[:, :, channel] = randint(0, 255)
40
- random_channel_color = randint(50, 255)
41
  np_surface[:, :, channel] = np.where(
42
- np.logical_and(np_surface[:, :, channel] >= dvd_background_color[channel] - 20,
43
- np_surface[:, :, channel] <= dvd_background_color[channel] + 20),
44
  random_channel_color, np_surface[:, :, channel])
45
- dvd_background_color[channel] = random_channel_color
46
- return pygame.surfarray.make_surface(np_surface)
47
 
48
 
49
- while not exit:
50
  screen.fill(BG_COLOR)
51
 
52
- if ((x + img_size[0] >= screen_info.current_w) or (x <= 0)) and ((y + img_size[1] >= screen_info.current_h) or (y <= 0)):
53
- time.sleep(9999999999)
54
- if (x + img_size[0] >= screen_info.current_w) or (x <= 0):
55
- logo = random_color_change(logo)
 
 
56
  x_speed = -x_speed
57
- if (y + img_size[1] >= screen_info.current_h) or (y <= 0):
58
- logo = random_color_change(logo)
59
  y_speed = -y_speed
 
60
  x += x_speed
61
  y += y_speed
62
  screen.blit(logo, (x, y))
63
- pygame.display.update()
64
- clock.tick(60)
65
- for event in pygame.event.get():
66
- if event.type == pygame.QUIT:
67
- exit = True
68
 
69
- pygame.quit()
 
1
  from random import randint
2
  import pygame
3
  import numpy as np
4
+ import streamlit as st
5
 
6
  import os
7
+
8
+ # os.system("pip install -r requirements.txt")
 
 
9
  BG_COLOR = (0, 0, 0)
10
  fullscreen = True
11
 
12
  logo = pygame.image.load('dvd_logo_0002.png')
13
+ logo = pygame.transform.scale(logo, (100, 200))
14
+
15
+
16
+ logo = pygame.surfarray.array3d(logo)
17
+ logo = np.flip(logo, axis=1)
18
+ logo = pygame.surfarray.make_surface(logo)
19
+
20
  img_size = logo.get_rect().size
21
+ screen_width = 1900
22
+ screen_height = 1080
23
+ screen = pygame.Surface((screen_height, screen_width))
24
 
25
+ screen.fill((0, 0, 0))
 
 
26
 
27
+
28
+ x = randint(0, screen_width - img_size[0])
29
+ y = randint(0, screen_height - img_size[0])
30
  x_speed = 2
31
+ y_speed = 3
32
 
33
  dvd_background_color = [255, 255, 255]
34
 
35
 
36
+ def random_color_change(surface, color_to_be_changed):
 
 
37
  np_surface = pygame.surfarray.array3d(surface)
38
  for channel in range(np_surface.shape[-1]):
39
  # np_surface[:, :, channel] = randint(0, 255)
40
+ random_channel_color = randint(70, 255)
41
  np_surface[:, :, channel] = np.where(
42
+ np.logical_and(np_surface[:, :, channel] >= color_to_be_changed[channel] - 40,
43
+ np_surface[:, :, channel] <= color_to_be_changed[channel]),
44
  random_channel_color, np_surface[:, :, channel])
45
+ color_to_be_changed[channel] = random_channel_color
46
+ return pygame.surfarray.make_surface(np_surface), color_to_be_changed
47
 
48
 
49
+ while True:
50
  screen.fill(BG_COLOR)
51
 
52
+ if ((x + img_size[0] + x_speed >= screen_width) or (x + x_speed <= 0)) and (
53
+ (y + y_speed + img_size[1] >= screen_height) or (y + y_speed <= 0)):
54
+ x -= 1.5 * x_speed
55
+ y -= 1.5 * x_speed
56
+ if (x + img_size[0] >= screen_width) or (x <= 0):
57
+ logo, dvd_background_color = random_color_change(logo, dvd_background_color)
58
  x_speed = -x_speed
59
+ if (y + img_size[1] >= screen_height) or (y <= 0):
60
+ logo, dvd_background_color = random_color_change(logo, dvd_background_color)
61
  y_speed = -y_speed
62
+
63
  x += x_speed
64
  y += y_speed
65
  screen.blit(logo, (x, y))
66
+ screen_np = pygame.surfarray.array3d(screen)
67
+ st.image(screen_np, caption='Idle Bouncing DVD logo')
 
 
 
68
 
 
dvd_logo_0002.png CHANGED