commit d4d4d96a8e47fe95d5571cd85067c76ccc9ce1f8 Author: Megamichi Date: Thu Jan 18 21:34:58 2024 +0100 first commit diff --git a/dvd-logo.png b/dvd-logo.png new file mode 100644 index 0000000..0607dd4 Binary files /dev/null and b/dvd-logo.png differ diff --git a/main.py b/main.py new file mode 100644 index 0000000..fd16065 --- /dev/null +++ b/main.py @@ -0,0 +1,100 @@ +import pygame +from random import randint as ri +def scale(vaktor): + scaledx = dvdsizex*vaktor + scaledy = dvdsizey*vaktor + return (scaledx,scaledy) +pygame.init() + +is_fullscreen = True +fill_screen = True +screen = pygame.display.set_mode((0,0),pygame.FULLSCREEN) +pygame.display.set_caption("Screensaver") +x,y = pygame.display.get_window_size() + +clock = pygame.time.Clock() + +dvd = pygame.image.load("dvd-logo.png") +dvdsizex,dvdsizey = dvd.get_size() + +dvdscale = 1 +dvdscalesize = scale(dvdscale) +dvdscaled = pygame.transform.scale(dvd,dvdscalesize) +dvdx,dvdy = ri(0,x-dvdsizex),ri(0,y-dvdsizey) +wobspeed = 3 + +richtung = ["r","u"] +def randcolor(): + return (ri(0,255),ri(0,255),ri(0,255)) + +def moving(richtung,wobx,woby): + if richtung[0] == "r": + wobx += wobspeed + else: + wobx -= wobspeed + if richtung[1] =="u": + woby += wobspeed + else: + woby -=wobspeed + return wobx,woby + +def toggle_fullscreen(is_fullscreen): + if is_fullscreen: + pygame.display.set_mode((600,500),pygame.RESIZABLE) + else: + pygame.display.set_mode((0,0),pygame.FULLSCREEN) + is_fullscreen = not is_fullscreen + return is_fullscreen,pygame.display.get_window_size() + +running = True +if __name__ == "__main__": + color = randcolor() + while running: + if fill_screen: + screen.fill((0,0,0)) + pressed_keys = pygame.key.get_pressed() + + if pressed_keys[pygame.K_ESCAPE]: + exit() + if pressed_keys[pygame.K_SPACE] and not preview_pressed_keys[pygame.K_SPACE]: + fill_screen = not fill_screen + if pressed_keys[pygame.K_f] and screen.get_size(): + is_fullscreen,(x,y) = toggle_fullscreen(is_fullscreen) + if pressed_keys[pygame.K_UP] and wobspeed>=0: + wobspeed += 1 + if pressed_keys[pygame.K_DOWN] and wobspeed>=1: + wobspeed -= 1 + if pressed_keys[pygame.K_RIGHT] and dvdscale>0.1: + dvdscale += 0.1 + dvdscalesize = scale(dvdscale) + if pressed_keys[pygame.K_LEFT] and dvdscale>=0.2: + dvdscale -= 0.1 + dvdscalesize = scale(dvdscale) + + preview_pressed_keys = pressed_keys + + for event in pygame.event.get(): + if event.type == pygame.QUIT: + exit() + if event.type == pygame.WINDOWRESIZED: + x,y = pygame.display.get_window_size() + + if dvdx+dvdscalesize[0] >= x: + richtung[0] = "l" + color = randcolor() + if dvdx <= 0: + richtung[0] = "r" + color = randcolor() + if dvdy+dvdscalesize[1] >= y: + richtung[1] = "o" + color = randcolor() + if dvdy <= 0: + richtung[1] = "u" + color = randcolor() + + dvdx,dvdy = moving(richtung,dvdx,dvdy) + pygame.draw.rect(screen,color,(dvdx,dvdy,dvdscalesize[0],dvdscalesize[1])) + dvdscaled = pygame.transform.scale(dvd,dvdscalesize) + screen.blit(dvdscaled,(dvdx,dvdy)) + pygame.display.update() + clock.tick(60) \ No newline at end of file