Compare commits
3 commits
d84aa6c0d1
...
3a70231b9a
Author | SHA1 | Date | |
---|---|---|---|
3a70231b9a | |||
1fff6840fb | |||
27af4863df |
1 changed files with 39 additions and 20 deletions
59
main.py
59
main.py
|
@ -5,10 +5,19 @@ from random import randint as ri
|
|||
pygame.init()
|
||||
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
|
||||
fill_screen = True
|
||||
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")
|
||||
screensize = pygame.display.get_window_size()
|
||||
|
||||
|
@ -19,14 +28,14 @@ speeds = 1
|
|||
|
||||
class DVD():
|
||||
def __init__(self,scale,speed):
|
||||
self.newcolor()
|
||||
self.dvd = pygame.image.load("dvd-logo.png")
|
||||
self.size = self.dvd.get_size()
|
||||
self.scale = scale
|
||||
self.speed = speed
|
||||
self.get_sdvd()
|
||||
self.pos = ri(0,screensize[0]-self.size[0]),ri(0,screensize[1]-self.size[1])
|
||||
self.get_dvd()
|
||||
self.richtung = ["r","u"]
|
||||
self.newcolor()
|
||||
self.render()
|
||||
|
||||
|
||||
|
@ -59,33 +68,43 @@ class DVD():
|
|||
def newcolor(self):
|
||||
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
|
||||
scaledy = self.size[1]*self.scale
|
||||
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):
|
||||
self.get_sdvd()
|
||||
self.get_dvd()
|
||||
|
||||
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.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():
|
||||
debug_text = ""
|
||||
for index,a in enumerate(globals()):
|
||||
debug_text = default_font.render(f"{str(a)} = {globals()[a]}", True, (240, 240, 240))
|
||||
screen.blit(debug_text,(0,index*default_font.get_height()))
|
||||
def text(text,line_counter):
|
||||
debug_text = default_font.render(str(text), True, (240, 240, 240))
|
||||
screen.blit(debug_text,(0,line_counter*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
|
||||
if __name__ == "__main__":
|
||||
|
@ -111,7 +130,7 @@ if __name__ == "__main__":
|
|||
if pressed_keys[pygame.K_LEFT] and scales>=0.2:
|
||||
scales -= 0.1
|
||||
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:
|
||||
dvds.pop(0)
|
||||
|
||||
|
|
Loading…
Reference in a new issue