diff --git a/main.py b/main.py index 05fb252..bf23e22 100755 --- a/main.py +++ b/main.py @@ -16,6 +16,7 @@ def toggle_fullscreen(is_fullscreen): is_fullscreen = False fill_screen = True show_debug = False +inverse = False screen = pygame.display.set_mode((600,500))#(0,0),pygame.FULLSCREEN) is_fullscreen,screensize = toggle_fullscreen(is_fullscreen) pygame.display.set_caption("Screensaver") @@ -34,25 +35,24 @@ class DVD(): self.scale = scale self.speed = speed 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.render() 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.newcolor() - if self.pos[0] <= 0: + if dvdx <= 0: self.richtung[0] = "r" self.newcolor() - if self.pos[1]+self.scalesize[1] >= screensize[1]: + if dvdy+self.scalesize[1] >= screensize[1]: self.richtung[1] = "o" self.newcolor() - if self.pos[1] <= 0: + if dvdy <= 0: self.richtung[1] = "u" self.newcolor() - dvdx,dvdy = self.pos if self.richtung[0] == "r": dvdx += self.speed @@ -63,30 +63,30 @@ class DVD(): else: dvdy -= self.speed self.pos = dvdx,dvdy - return dvdx,dvdy + def newcolor(self): self.color = (ri(0,255),ri(0,255),ri(0,255)) - def get_dvd(self): - scaledx = self.size[0]*self.scale - scaledy = self.size[1]*self.scale - 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.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 get_dvd(self,inverse): + scaledx = self.size[0] * self.scale + scaledy = self.size[1] * self.scale + self.scalesize = (scaledx, scaledy) - def render(self): - self.get_dvd() + self.sdvd = pygame.Surface(self.scalesize, flags=pygame.SRCALPHA) - 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) + pygame.draw.rect(self.sdvd, self.color, (0, 0, self.scalesize[0], self.scalesize[1])) + 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) + dvds = [] dvds.append(DVD(1,1))#ri(1,10))) @@ -119,6 +119,8 @@ if __name__ == "__main__": fill_screen = not fill_screen if pressed_keys[pygame.K_d] and not preview_pressed_keys[pygame.K_d]: 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(): is_fullscreen,screensize = toggle_fullscreen(is_fullscreen) if pressed_keys[pygame.K_UP] and speeds>=0: @@ -146,7 +148,7 @@ if __name__ == "__main__": a.speed = speeds a.scale = scales a.moving() - a.render() + a.get_dvd(inverse) if show_debug: get_debug_text()