es gehts mit den durchsichtigkeit
This commit is contained in:
parent
3a70231b9a
commit
595c2dc386
1 changed files with 28 additions and 26 deletions
46
main.py
46
main.py
|
@ -16,6 +16,7 @@ def toggle_fullscreen(is_fullscreen):
|
||||||
is_fullscreen = False
|
is_fullscreen = False
|
||||||
fill_screen = True
|
fill_screen = True
|
||||||
show_debug = False
|
show_debug = False
|
||||||
|
inverse = False
|
||||||
screen = pygame.display.set_mode((600,500))#(0,0),pygame.FULLSCREEN)
|
screen = pygame.display.set_mode((600,500))#(0,0),pygame.FULLSCREEN)
|
||||||
is_fullscreen,screensize = toggle_fullscreen(is_fullscreen)
|
is_fullscreen,screensize = toggle_fullscreen(is_fullscreen)
|
||||||
pygame.display.set_caption("Screensaver")
|
pygame.display.set_caption("Screensaver")
|
||||||
|
@ -34,25 +35,24 @@ class DVD():
|
||||||
self.scale = scale
|
self.scale = scale
|
||||||
self.speed = speed
|
self.speed = speed
|
||||||
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.get_dvd(False)
|
||||||
self.richtung = ["r","u"]
|
self.richtung = ["r","u"]
|
||||||
self.render()
|
|
||||||
|
|
||||||
|
|
||||||
def moving(self):
|
def moving(self):
|
||||||
if self.pos[0]+self.scalesize[0] >= screensize[0]:
|
dvdx,dvdy = self.pos
|
||||||
|
if dvdx+self.scalesize[0] >= screensize[0]:
|
||||||
self.richtung[0] = "l"
|
self.richtung[0] = "l"
|
||||||
self.newcolor()
|
self.newcolor()
|
||||||
if self.pos[0] <= 0:
|
if dvdx <= 0:
|
||||||
self.richtung[0] = "r"
|
self.richtung[0] = "r"
|
||||||
self.newcolor()
|
self.newcolor()
|
||||||
if self.pos[1]+self.scalesize[1] >= screensize[1]:
|
if dvdy+self.scalesize[1] >= screensize[1]:
|
||||||
self.richtung[1] = "o"
|
self.richtung[1] = "o"
|
||||||
self.newcolor()
|
self.newcolor()
|
||||||
if self.pos[1] <= 0:
|
if dvdy <= 0:
|
||||||
self.richtung[1] = "u"
|
self.richtung[1] = "u"
|
||||||
self.newcolor()
|
self.newcolor()
|
||||||
dvdx,dvdy = self.pos
|
|
||||||
|
|
||||||
if self.richtung[0] == "r":
|
if self.richtung[0] == "r":
|
||||||
dvdx += self.speed
|
dvdx += self.speed
|
||||||
|
@ -63,30 +63,30 @@ class DVD():
|
||||||
else:
|
else:
|
||||||
dvdy -= self.speed
|
dvdy -= self.speed
|
||||||
self.pos = dvdx,dvdy
|
self.pos = dvdx,dvdy
|
||||||
return dvdx,dvdy
|
|
||||||
|
|
||||||
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_dvd(self):
|
def get_dvd(self,inverse):
|
||||||
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.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.sdvd = pygame.Surface(self.scalesize, flags=pygame.SRCALPHA)
|
||||||
#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):
|
pygame.draw.rect(self.sdvd, self.color, (0, 0, self.scalesize[0], self.scalesize[1]))
|
||||||
self.get_dvd()
|
self.sdvd.blit(pygame.transform.scale(self.dvd, self.scalesize), (0, 0))
|
||||||
|
tempdvd = pygame.PixelArray(self.sdvd)
|
||||||
|
if inverse :
|
||||||
|
tempdvd.replace(self.color, (0,0,0,0))
|
||||||
|
tempdvd.replace((0,0,0), self.color)
|
||||||
|
else:
|
||||||
|
tempdvd.replace((0,0,0), (0,0,0,0))
|
||||||
|
del tempdvd
|
||||||
|
|
||||||
|
screen.blit(self.sdvd, self.pos)
|
||||||
|
|
||||||
pygame.draw.rect(screen,self.color,(self.pos[0],self.pos[1],self.scalesize[0],self.scalesize[1]))
|
|
||||||
screen.blit(self.rendered_dvd,self.pos)
|
|
||||||
|
|
||||||
dvds = []
|
dvds = []
|
||||||
dvds.append(DVD(1,1))#ri(1,10)))
|
dvds.append(DVD(1,1))#ri(1,10)))
|
||||||
|
@ -119,6 +119,8 @@ if __name__ == "__main__":
|
||||||
fill_screen = not fill_screen
|
fill_screen = not fill_screen
|
||||||
if pressed_keys[pygame.K_d] and not preview_pressed_keys[pygame.K_d]:
|
if pressed_keys[pygame.K_d] and not preview_pressed_keys[pygame.K_d]:
|
||||||
show_debug = not show_debug
|
show_debug = not show_debug
|
||||||
|
if pressed_keys[pygame.K_i] and not preview_pressed_keys[pygame.K_i]:
|
||||||
|
inverse = not inverse
|
||||||
if pressed_keys[pygame.K_f] and screen.get_size():
|
if pressed_keys[pygame.K_f] and screen.get_size():
|
||||||
is_fullscreen,screensize = toggle_fullscreen(is_fullscreen)
|
is_fullscreen,screensize = toggle_fullscreen(is_fullscreen)
|
||||||
if pressed_keys[pygame.K_UP] and speeds>=0:
|
if pressed_keys[pygame.K_UP] and speeds>=0:
|
||||||
|
@ -146,7 +148,7 @@ if __name__ == "__main__":
|
||||||
a.speed = speeds
|
a.speed = speeds
|
||||||
a.scale = scales
|
a.scale = scales
|
||||||
a.moving()
|
a.moving()
|
||||||
a.render()
|
a.get_dvd(inverse)
|
||||||
|
|
||||||
if show_debug:
|
if show_debug:
|
||||||
get_debug_text()
|
get_debug_text()
|
||||||
|
|
Loading…
Reference in a new issue