Compare commits

...

3 commits

Author SHA1 Message Date
3a70231b9a ich grigs ne hinnnnnnn 2024-01-20 22:39:12 +01:00
1fff6840fb klappt ned :( 2024-01-20 20:48:24 +01:00
27af4863df emil das klappt so ned 2024-01-20 09:48:03 +01:00

59
main.py
View file

@ -5,10 +5,19 @@ from random import randint as ri
pygame.init() pygame.init()
default_font = pygame.font.SysFont("sans", 14) default_font = pygame.font.SysFont("sans", 14)
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()
is_fullscreen = False is_fullscreen = False
fill_screen = True fill_screen = True
show_debug = False show_debug = False
screen = pygame.display.set_mode((0,0),pygame.FULLSCREEN) screen = pygame.display.set_mode((600,500))#(0,0),pygame.FULLSCREEN)
is_fullscreen,screensize = toggle_fullscreen(is_fullscreen)
pygame.display.set_caption("Screensaver") pygame.display.set_caption("Screensaver")
screensize = pygame.display.get_window_size() screensize = pygame.display.get_window_size()
@ -19,14 +28,14 @@ speeds = 1
class DVD(): class DVD():
def __init__(self,scale,speed): def __init__(self,scale,speed):
self.newcolor()
self.dvd = pygame.image.load("dvd-logo.png") self.dvd = pygame.image.load("dvd-logo.png")
self.size = self.dvd.get_size() self.size = self.dvd.get_size()
self.scale = scale self.scale = scale
self.speed = speed self.speed = speed
self.get_sdvd()
self.pos = ri(0,screensize[0]-self.size[0]),ri(0,screensize[1]-self.size[1]) self.pos = ri(0,screensize[0]-self.size[0]),ri(0,screensize[1]-self.size[1])
self.get_dvd()
self.richtung = ["r","u"] self.richtung = ["r","u"]
self.newcolor()
self.render() self.render()
@ -59,33 +68,43 @@ class DVD():
def newcolor(self): def newcolor(self):
self.color = (ri(0,255),ri(0,255),ri(0,255)) self.color = (ri(0,255),ri(0,255),ri(0,255))
def get_sdvd(self): def get_dvd(self):
scaledx = self.size[0]*self.scale scaledx = self.size[0]*self.scale
scaledy = self.size[1]*self.scale scaledy = self.size[1]*self.scale
self.scalesize = (scaledx,scaledy) self.scalesize = (scaledx,scaledy)
self.sdvd = pygame.transform.scale(self.dvd,self.scalesize) self.rendered_dvd = pygame.surface.Surface(self.scalesize, flags=pygame.SRCALPHA)
self.rendered_dvd = pygame.transform.scale(self.dvd,self.scalesize)#(self.scalesize[0],self.scalesize[1]+10))
#self.rendered_dvd.fill(self.color)
#self.rendered_dvd2 = pygame.surface.Surface(self.scalesize, flags=pygame.SRCALPHA)
#_test_ = pygame.transform.threshold(self.rendered_dvd, self.rendered_dvd, (0, 0, 0), (0, 0, 0, 0), self.color, inverse_set=False)
#print(_test_)
#screen.blit(self.rendered_dvd2,self.pos)
screen.blit(self.rendered_dvd,self.pos)
def render(self): def render(self):
self.get_sdvd() self.get_dvd()
pygame.draw.rect(screen,self.color,(self.pos[0],self.pos[1],self.scalesize[0],self.scalesize[1])) pygame.draw.rect(screen,self.color,(self.pos[0],self.pos[1],self.scalesize[0],self.scalesize[1]))
screen.blit(self.sdvd,self.pos) screen.blit(self.rendered_dvd,self.pos)
dvds = [] dvds = []
dvds.append(DVD(1,1)) dvds.append(DVD(1,1))#ri(1,10)))
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()
def get_debug_text(): def get_debug_text():
debug_text = "" def text(text,line_counter):
for index,a in enumerate(globals()): debug_text = default_font.render(str(text), True, (240, 240, 240))
debug_text = default_font.render(f"{str(a)} = {globals()[a]}", True, (240, 240, 240)) screen.blit(debug_text,(0,line_counter*default_font.get_height()))
screen.blit(debug_text,(0,index*default_font.get_height()))
line_counter = 1
globalvars =globals()
for a in globalvars:
text(f"{str(a)} = {str(globalvars[a])}",line_counter)
line_counter += 1
for a in dvds:
text(vars(a),line_counter)
line_counter += 1
running = True running = True
if __name__ == "__main__": if __name__ == "__main__":
@ -111,7 +130,7 @@ if __name__ == "__main__":
if pressed_keys[pygame.K_LEFT] and scales>=0.2: if pressed_keys[pygame.K_LEFT] and scales>=0.2:
scales -= 0.1 scales -= 0.1
if pressed_keys[pygame.K_PLUS] and not preview_pressed_keys[pygame.K_PLUS]: if pressed_keys[pygame.K_PLUS] and not preview_pressed_keys[pygame.K_PLUS]:
dvds.append(DVD(1,1)) dvds.append(DVD(1,1)) #ri(1,30)))
if pressed_keys[pygame.K_MINUS] and not preview_pressed_keys[pygame.K_MINUS] and not len(dvds) == 0: if pressed_keys[pygame.K_MINUS] and not preview_pressed_keys[pygame.K_MINUS] and not len(dvds) == 0:
dvds.pop(0) dvds.pop(0)