def __init__(self,screen_width,screen_height,size="big",colors=["red"],background_color=(0,0,0),speed=0.005,direction="Vertical",music_filepath="",password="",recursion=0) : ''' Run the rollers animation with the given settings. ''' self.screen_width=screen_width # Get screen height for the fullscreen display size. self.screen_height=screen_height # Get screen width for the fullscreen display size. self.size=size # Get the given size: ["little"|"middle"|"big"]. self.colors=colors # Get the given color(s) for the rollers to display and their count. self.background_color=background_color # Get the given display background color. self.speed=speed # Get the given rollers animation speed for the sleep() function argument. self.direction=direction # Get the given rollers direction: ["Horizontal"|"Vertical"]. self.password=password # Get the given password hash self.password_entry="" self.password_recursion=recursion self.password_check=Password() self.runner=True # Control animation keep-alive variable. ''' The rollers are driven in two times: -) from border to center (from color to white) : self.up -) from center to border (from white to color) : self.down and the color is [de|in]crement with the steps : self.incr to form a roller. ''' if self.size == 'big' : self.up=64 self.down=64 self.incr=4 elif self.size == "middle" : self.up=32 self.down=32 self.incr=8 elif self.size == "little" : self.up=16 self.down=16 self.incr=16 pygame.init() self.screen=pygame.display.set_mode((0,0),pygame.FULLSCREEN,32) if music_filepath : self.play_backgroound_music(music_filepath) if direction == "Vertical" and len(colors) == 1 : # Rollers running vertical and only one is selected. self.run_vertical() elif direction == "Vertical" and len(colors) > 1 : # Rollers running vertical and more than one is selected. self.run_multi_vertical() elif direction == "Horizontal" and len(colors) == 1 : # Rollers running horizontal and only one is selected. self.run_horizontal() elif direction == "Horizontal" and len(colors) > 1 : # Rollers running horizontal and more than one is selected. self.run_multi_horizontal()
def __init__(self,screen_width,screen_height,mode=1,size="big",color_balls=['red','blue','yellow'],background_color=(0,0,0),speed=0.05,music_filepath="",password="",recursion=0) : ''' Run the balls animation with the given settings. ''' self.screen_width=screen_width # Get screen width for the fullscreen display size. self.screen_height=screen_height # Get screen height for the fullscreen display size. self.mode=mode # Get the mode [ Circle == 0 | Halo == 1 ] ''' Computing the ball size in relationship with the given size ["little"|"middle"|"big"]. ''' if size == "big" : self.ball_size=16*8 if mode : self.inter_spacing=32 # A quarter of the balls size for the Halo mode. else : self.inter_spacing=0 elif size == "middle" : self.ball_size=16*4 if mode : self.inter_spacing=16 # A quarter of the balls size for the Halo mode. else : self.inter_spacing=0 elif size == "little" : self.ball_size=16*2 if mode : self.inter_spacing=8 # A quarter of the balls size for the Halo mode. else : self.inter_spacing=0 ''' Compute the balls colors in relation ship of the selected colors. ''' colors_dict={"red":((255,0,0),(255,127,127)), "green":((0,255,0),(127,255,127)), "blue":((0,0,255),(127,127,255)), "yellow":((255,255,0),(255,255,127)), "pink":((255,0,255),(255,127,255)), "turkish":((0,255,255),(127,255,255))} self.color_balls=[] for v in color_balls : self.color_balls.append(colors_dict.get(v)[0]) self.color_balls.append(colors_dict.get(v)[1]) self.background_color=background_color # Get the given display background color. self.speed=speed # Get the given balls animation speed for the sleep() function argument. self.direction="Vertical" # Set the direction arbitraly. Because the algorithm can draw the balls Horizontal but not implemented in the programm. self.password=password # Get the given password hash self.password_entry="" self.password_recursion=recursion self.password_check=Password() self.runner=True # Control animation keep-alive variable. pygame.init() self.screen=pygame.display.set_mode((0,0),pygame.FULLSCREEN,32) self.init_balls(self.direction) if music_filepath : self.play_backgroound_music(music_filepath) self.run()
class Balls() : def __init__(self,screen_width,screen_height,mode=1,size="big",color_balls=['red','blue','yellow'],background_color=(0,0,0),speed=0.05,music_filepath="",password="",recursion=0) : ''' Run the balls animation with the given settings. ''' self.screen_width=screen_width # Get screen width for the fullscreen display size. self.screen_height=screen_height # Get screen height for the fullscreen display size. self.mode=mode # Get the mode [ Circle == 0 | Halo == 1 ] ''' Computing the ball size in relationship with the given size ["little"|"middle"|"big"]. ''' if size == "big" : self.ball_size=16*8 if mode : self.inter_spacing=32 # A quarter of the balls size for the Halo mode. else : self.inter_spacing=0 elif size == "middle" : self.ball_size=16*4 if mode : self.inter_spacing=16 # A quarter of the balls size for the Halo mode. else : self.inter_spacing=0 elif size == "little" : self.ball_size=16*2 if mode : self.inter_spacing=8 # A quarter of the balls size for the Halo mode. else : self.inter_spacing=0 ''' Compute the balls colors in relation ship of the selected colors. ''' colors_dict={"red":((255,0,0),(255,127,127)), "green":((0,255,0),(127,255,127)), "blue":((0,0,255),(127,127,255)), "yellow":((255,255,0),(255,255,127)), "pink":((255,0,255),(255,127,255)), "turkish":((0,255,255),(127,255,255))} self.color_balls=[] for v in color_balls : self.color_balls.append(colors_dict.get(v)[0]) self.color_balls.append(colors_dict.get(v)[1]) self.background_color=background_color # Get the given display background color. self.speed=speed # Get the given balls animation speed for the sleep() function argument. self.direction="Vertical" # Set the direction arbitraly. Because the algorithm can draw the balls Horizontal but not implemented in the programm. self.password=password # Get the given password hash self.password_entry="" self.password_recursion=recursion self.password_check=Password() self.runner=True # Control animation keep-alive variable. pygame.init() self.screen=pygame.display.set_mode((0,0),pygame.FULLSCREEN,32) self.init_balls(self.direction) if music_filepath : self.play_backgroound_music(music_filepath) self.run() def play_backgroound_music(self,filepath) : pygame.mixer.init() pygame.mixer.music.load(filepath) pygame.mixer.music.play(-1) def init_balls(self,direction) : self.balls=[] # Container for the balls coordinates because they change. self.balls_colors=[] # Container for the balls colors because they change. self.balls_control=[] # Container for the balls bouncing control. self.balls_overvalue=[] # Container for the balls bouncing highest value who can change. self.balls_as_bounce=[] # Container for the balls bouncing timer. if direction == "Vertical" : counter=0 while counter < self.screen_width-self.ball_size : # Compute a count of how many balls we display. counter += self.ball_size offset=self.screen_width-counter # Offset value compute from the border the the first ball ( must be divided by 2 for centering the balls). i=int(round(offset / 2.)) # Iterator start at the 1/2 from the screen border. while i < self.screen_width-int(round(offset / 2.)): '''loop for settings the balls coordinates,colors,start bouncing settings.''' ii=randrange(self.ball_size,self.screen_height-self.ball_size,self.ball_size) # Random highest y value for bouncing. self.balls.append([[i,ii],[self.ball_size,self.ball_size]]) # Setting ball coordinates. self.balls_colors.append(choice(self.color_balls)) # Random ball color. self.balls_control.append("down") # Setting bouncing direction. self.balls_overvalue.append(ii) # Setting highest y value for bouncing. self.balls_as_bounce.append(0) # Bouncing control value. i += self.ball_size # Go to next ball. elif direction == "Horizontal" : counter=0 while counter < self.screen_height-self.ball_size : # Compute a count of how many balls we display. counter += self.ball_size offset=self.screen_height-counter # Offset value compute from the border the the first ball ( must be divided by 2 for centering the balls). ii=int(round(offset / 2.)) # Iterator start at the 1/2 from the screen border. while ii < self.screen_height-int(round(offset / 2.)) : # self.screen_height-(self.spaces*4) to compute for compatibility i=randrange(self.ball_size,self.screen_width-self.ball_size,self.ball_size) # Random highest x value for bouncing. self.balls.append([[i,ii],[self.ball_size,self.ball_size]]) # Setting ball coordinates. self.balls_colors.append(choice(self.color_balls)) # Random ball color. self.balls_control.append("down") # Setting bouncing direction. self.balls_overvalue.append(i) # Setting highest x value for bouncing. self.balls_as_bounce.append(0) # Bouncing timer control value. ii += self.ball_size # Go to next ball. def change_color(self,color) : ''' Color changing function ''' ret=[] for v in color : if ( v == 0) : ret.append(127) elif (v == 127) : ret.append(0) else : ret.append(255) return (ret[0],ret[1],ret[2]) def run(self) : while self.runner : # Balls animation mainloop. self.screen.fill(self.background_color) # Background color filling. i=0 # Iterator over all balls. while i < len(self.balls) : # Big loop do for all balls configurating. if self.balls_control[i] == "down" : # Ball bouncing getting down. if self.direction == "Vertical" : self.balls[i][0][1] += self.ball_size # Increment y value from ball. elif self.direction == "Horizontal" : self.balls[i][0][0] += self.ball_size # Increment x value from ball. elif self.balls_control[i] == "up" : # Ball bouncing getting up. if self.direction == "Vertical" : self.balls[i][0][1] -= self.ball_size # Decrement y value from ball. elif self.direction == "Horizontal" : self.balls[i][0][0] -= self.ball_size # Decrement x value from ball. if self.direction == "Vertical" : ii=self.screen_height-self.ball_size # Offset from down. while ii >= self.balls[i][0][1] : # Draw balls loop. rect=((self.balls[i][0][0],ii),(self.ball_size,self.ball_size)) pygame.draw.ellipse(self.screen,self.balls_colors[i],rect,0) if self.inter_spacing : # In case of halo mode draw the halo. pygame.draw.ellipse(self.screen,self.background_color,rect,self.inter_spacing) ii -= self.ball_size # Go to next ball in the same column. if self.balls[i][0][1] >= self.screen_height-self.ball_size : # Ball at the ground. self.balls_colors[i]=self.change_color(self.balls_colors[i]) # Change the ball color because the ball reach the ground. self.balls_control[i]="up" # Change bouncing direction because the ball reach the ground. self.balls_as_bounce[i] += 1 # Change ball bouncing timer. if self.balls_as_bounce[i] > 3 : # The ball as bounce 3 times. self.balls_as_bounce[i] = 0 # Reset ball bouncing timer. self.balls_overvalue[i]=randrange(self.ball_size,self.screen_height-self.ball_size,self.ball_size) # Change highest y value for bouncing. self.balls_colors[i]=choice((self.color_balls)) # Change the ball color because as bounce 3 times. elif self.balls[i][0][1] == self.balls_overvalue[i] : # Ball at the top. self.balls_colors[i]=self.change_color(self.balls_colors[i]) # Change the ball color because the ball reach the top. self.balls_control[i]="down" # Change bouncing direction because the ball reach the top. elif self.direction == "Horizontal" : ii=self.screen_width-self.ball_size # Offset from the left. while ii >= self.balls[i][0][0] : # Draw balls loop. rect=((ii,self.balls[i][0][1]),(self.ball_size,self.ball_size)) pygame.draw.ellipse(self.screen,self.balls_colors[i],rect,0) if self.inter_spacing : # In case of halo mode draw the halo. pygame.draw.ellipse(self.screen,self.background_color,rect,self.inter_spacing) ii -= self.ball_size # Go to next ball in the same line. if self.balls[i][0][0] >= self.screen_width-self.ball_size : # Ball at the right border. self.balls_colors[i]=self.change_color(self.balls_colors[i]) # Change the ball color because the ball reach the ground. self.balls_control[i]="up" # Change bouncing direction because the ball reach the ground. self.balls_as_bounce[i] += 1 # Change ball bouncing timer. if self.balls_as_bounce[i] > 3 : # The ball as bounce 3 times. self.balls_as_bounce[i] = 0 # Reset ball bouncing timer. self.balls_overvalue[i]=randrange(self.ball_size,self.screen_width-self.ball_size,self.ball_size) # Change highest x value for bouncing. self.balls_colors[i]=choice((self.color_balls)) # Change the ball color because as bounce 3 times. elif self.balls[i][0][0] == self.balls_overvalue[i] : # Ball at the max left value. self.balls_colors[i]=self.change_color(self.balls_colors[i]) # Change the ball color because the ball reach the left limit. self.balls_control[i]="down" # Change bouncing direction because the ball reach the left limit. i += 1 # Go to next ball. for event in pygame.event.get() : if event.type == KEYDOWN : if event.key == K_RETURN : if self.password : if self.password_check.gen_password_hash(self.password_entry,self.password_recursion) == self.password : self.runner=False try : pygame.mixer.music.stop() except : pass else : self.password_entry="" else : try : pygame.mixer.music.stop() except : pass self.runner=False else : if self.password : char=get_char(event.key) if not char : self.password_entry="" else : if not type(char) == bool : self.password_entry += char pygame.display.update() sleep(self.speed) pygame.display.quit()
def __init__( self, screen_width, screen_height, square=1, size="little", color_rect=(0, 0, 255), color_fill=(255, 255, 0), background_color=(0, 0, 0), rand_color=False, speed=0.05, music_filepath="", password="", recursion=0, ): """ """ self.screen_width = screen_width # Get screen height for the fullscreen display size. self.screen_height = screen_height # Get screen width for the fullscreen display size. self.square = square # Get the mode [ rectangles == 0 | squares == 1 ] """ Compute the [rectangle|squares] in relation ship of the selected size ["little"|"middle"|"big"]. """ if size == "big": if square: factor = 8 # Factor for squares size computing. else: factor = 4 # Factor for rectangle (bars) size computing. elif size == "middle": if square: factor = 4 # Factor for squares size computing. else: factor = 2 # Factor for rectangle (bars) size computing. elif size == "little": if square: factor = 2 # Factor for squares size computing. else: factor = 1 # Factor for rectangle (bars) size computing. square_list = [] # Temporary container for squares size computing. for v in [16, 8, 4, 2]: # Finding the right size of the rectangles (bars) and spaces between them, in relationship to the screen resolution width. try: assert self.screen_width % v == 0 self.spaces = v self.rect_width = v * factor square_list.append(v) break except: pass for v in [16, 8, 4, 2]: # Finding the right size of the rectangles (bars) and spaces between them, in relationship to the screen resolution height. try: assert self.screen_height % v == 0 self.rect_heigth = v * factor square_list.append(v) break except: pass if not square_list: # The resolution not match with the algorithm we can't define the sizes. return if square: # Finding the right size of the squares and spaces between them, in relationship to the screen resolution height. self.spaces, self.rect_width, self.rect_heigth = ( min(square_list), min(square_list) * factor, min(square_list) * factor, ) self.color_rect = color_rect # Get the given background [rectangles (bars) | squares] color. self.color_fill = color_fill # Get the given foreground [rectangles (bars) | squares] color. self.background_color = background_color # Get the given display background color. self.speed = speed # Get the given bars animation speed for the sleep() function argument. self.password = password # Get the given password hash self.password_entry = "" self.password_recursion = recursion self.password_check = Password() self.rand_color = rand_color # Get the given random color mode argument as boolean value. self.runner = True # Control animation keep-alive variable. pygame.init() self.screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN, 32) if music_filepath: self.play_backgroound_music(music_filepath) self.run()
class Bars: def __init__( self, screen_width, screen_height, square=1, size="little", color_rect=(0, 0, 255), color_fill=(255, 255, 0), background_color=(0, 0, 0), rand_color=False, speed=0.05, music_filepath="", password="", recursion=0, ): """ """ self.screen_width = screen_width # Get screen height for the fullscreen display size. self.screen_height = screen_height # Get screen width for the fullscreen display size. self.square = square # Get the mode [ rectangles == 0 | squares == 1 ] """ Compute the [rectangle|squares] in relation ship of the selected size ["little"|"middle"|"big"]. """ if size == "big": if square: factor = 8 # Factor for squares size computing. else: factor = 4 # Factor for rectangle (bars) size computing. elif size == "middle": if square: factor = 4 # Factor for squares size computing. else: factor = 2 # Factor for rectangle (bars) size computing. elif size == "little": if square: factor = 2 # Factor for squares size computing. else: factor = 1 # Factor for rectangle (bars) size computing. square_list = [] # Temporary container for squares size computing. for v in [16, 8, 4, 2]: # Finding the right size of the rectangles (bars) and spaces between them, in relationship to the screen resolution width. try: assert self.screen_width % v == 0 self.spaces = v self.rect_width = v * factor square_list.append(v) break except: pass for v in [16, 8, 4, 2]: # Finding the right size of the rectangles (bars) and spaces between them, in relationship to the screen resolution height. try: assert self.screen_height % v == 0 self.rect_heigth = v * factor square_list.append(v) break except: pass if not square_list: # The resolution not match with the algorithm we can't define the sizes. return if square: # Finding the right size of the squares and spaces between them, in relationship to the screen resolution height. self.spaces, self.rect_width, self.rect_heigth = ( min(square_list), min(square_list) * factor, min(square_list) * factor, ) self.color_rect = color_rect # Get the given background [rectangles (bars) | squares] color. self.color_fill = color_fill # Get the given foreground [rectangles (bars) | squares] color. self.background_color = background_color # Get the given display background color. self.speed = speed # Get the given bars animation speed for the sleep() function argument. self.password = password # Get the given password hash self.password_entry = "" self.password_recursion = recursion self.password_check = Password() self.rand_color = rand_color # Get the given random color mode argument as boolean value. self.runner = True # Control animation keep-alive variable. pygame.init() self.screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN, 32) if music_filepath: self.play_backgroound_music(music_filepath) self.run() def play_backgroound_music(self, filepath): pygame.mixer.init() pygame.mixer.music.load(filepath) pygame.mixer.music.play(-1) def compute_width_counter(self): """ Method to count the number of [rectangles (bars) | squares] we can display in the width. self.spaces is the offset from the border so we must divided it by 2 to center our animation. """ i = ((self.screen_width % self.rect_width + self.spaces) / 2) + ( (self.rect_width + self.spaces) ) # Offset from the border. We sacrify an [ rectangle (bar) | square ] for bugfix an value overflow # what result to draw an piece of [ rectangle (bar) | square ] if we unlucky. counter = 0 while i < self.screen_width - ( ((self.screen_width % self.rect_width + self.spaces) / 2) + ((self.rect_width + self.spaces)) ): i += self.rect_width + self.spaces counter += 1 self.width_start_offset = ((self.screen_width % self.rect_width + self.spaces) / 2) + ( (self.rect_width + self.spaces) ) # Offset from the border. return counter def compute_heigth_counter(self): """ Method to count the number of [rectangles (bars) | squares] we can display in the height. self.spaces is the offset from the border so we must divided it by 2 to center our animation. """ i = ((self.screen_height % (self.rect_heigth + self.spaces)) / 2) + ( (self.rect_heigth + self.spaces) ) # Offset from the border. We sacrify an [ rectangle (bar) | square ] for bugfix an value overflow # what result to draw an piece of [ rectangle (bar) | square ] if we unlucky. counter = 0 while i < self.screen_height - ( ((self.screen_height % (self.rect_heigth + self.spaces)) / 2) + ((self.rect_heigth + self.spaces)) ): i += self.rect_heigth + self.spaces counter += 1 self.heigth_start_offset = ((self.screen_height % (self.rect_heigth + self.spaces)) / 2) + ( (self.rect_heigth + self.spaces) ) # Offset from the border. return counter def run(self): self.width_rect_counter = self.compute_width_counter() self.height_rect_counter = self.compute_heigth_counter() while self.runner: # Mainloop for one [ rectangle (bar) | square ] animation. self.screen.fill(self.background_color) # Background color filling. i = 0 x_coords = self.width_start_offset while i < self.width_rect_counter: # We run from left to the right. ii = 0 y_coords = self.heigth_start_offset while ii < self.height_rect_counter: # We run from top to bottom. if self.rand_color: self.color_rect = (randint(0, 255), randint(0, 255), randint(0, 255)) pygame.draw.rect( self.screen, self.color_rect, ((x_coords, y_coords), (self.rect_width, self.rect_heigth)), 0 ) y_coords += self.rect_heigth + self.spaces ii += 1 i += 1 x_coords += self.rect_width + self.spaces if not self.rand_color: # In the random color mode we don't need the foreground [ rectangle (bar) | square ] what do this loop. i = 0 x_coords = self.width_start_offset while i < self.width_rect_counter: # We run from left to the right. y_coords = self.heigth_start_offset ii = 0 y_coords = self.screen_height - self.heigth_start_offset - (self.rect_heigth + self.spaces) while ii < randint(0, self.height_rect_counter): # We run from top to bottom. pygame.draw.rect( self.screen, self.color_fill, ((x_coords, y_coords), (self.rect_width, self.rect_heigth)), 0 ) y_coords -= self.rect_heigth + self.spaces ii += 1 i += 1 x_coords += self.rect_width + self.spaces for event in pygame.event.get(): if event.type == KEYDOWN: if event.key == K_RETURN: if self.password: if ( self.password_check.gen_password_hash(self.password_entry, self.password_recursion) == self.password ): self.runner = False try: pygame.mixer.music.stop() except: pass else: self.password_entry = "" else: try: pygame.mixer.music.stop() except: pass self.runner = False else: if self.password: char = get_char(event.key) if not char: self.password_entry = "" else: if not type(char) == bool: self.password_entry += char pygame.display.update() sleep(self.speed) pygame.display.quit()
class Rollers() : def __init__(self,screen_width,screen_height,size="big",colors=["red"],background_color=(0,0,0),speed=0.005,direction="Vertical",music_filepath="",password="",recursion=0) : ''' Run the rollers animation with the given settings. ''' self.screen_width=screen_width # Get screen height for the fullscreen display size. self.screen_height=screen_height # Get screen width for the fullscreen display size. self.size=size # Get the given size: ["little"|"middle"|"big"]. self.colors=colors # Get the given color(s) for the rollers to display and their count. self.background_color=background_color # Get the given display background color. self.speed=speed # Get the given rollers animation speed for the sleep() function argument. self.direction=direction # Get the given rollers direction: ["Horizontal"|"Vertical"]. self.password=password # Get the given password hash self.password_entry="" self.password_recursion=recursion self.password_check=Password() self.runner=True # Control animation keep-alive variable. ''' The rollers are driven in two times: -) from border to center (from color to white) : self.up -) from center to border (from white to color) : self.down and the color is [de|in]crement with the steps : self.incr to form a roller. ''' if self.size == 'big' : self.up=64 self.down=64 self.incr=4 elif self.size == "middle" : self.up=32 self.down=32 self.incr=8 elif self.size == "little" : self.up=16 self.down=16 self.incr=16 pygame.init() self.screen=pygame.display.set_mode((0,0),pygame.FULLSCREEN,32) if music_filepath : self.play_backgroound_music(music_filepath) if direction == "Vertical" and len(colors) == 1 : # Rollers running vertical and only one is selected. self.run_vertical() elif direction == "Vertical" and len(colors) > 1 : # Rollers running vertical and more than one is selected. self.run_multi_vertical() elif direction == "Horizontal" and len(colors) == 1 : # Rollers running horizontal and only one is selected. self.run_horizontal() elif direction == "Horizontal" and len(colors) > 1 : # Rollers running horizontal and more than one is selected. self.run_multi_horizontal() def play_backgroound_music(self,filepath) : pygame.mixer.init() pygame.mixer.music.load(filepath) pygame.mixer.music.play(-1) def run_vertical(self) : start_pos=0 # Actual position y value in the display color_idx=0 # Color index for compatiblity with multi rollers. color=self.colors[color_idx] # Color setting. while self.runner : # Mainloop for one roller animation. self.screen.fill(self.background_color) # Background color filling. if start_pos == self.screen_height-(self.up+self.down) : # The roller reach the display end and we set the y position value to begin. start_pos=0 i=0 ii=0 while i < self.up : # Iterating for roller (from border to center part) generating. # The variable i for the y value # The variable ii for the color value. if color == 'red' : pygame.draw.line(self.screen,(255,ii,ii),(0,start_pos+i),(self.screen_width,start_pos+i),1) elif color == "green" : pygame.draw.line(self.screen,(ii,255,ii),(0,start_pos+i),(self.screen_width,start_pos+i),1) elif color == "blue" : pygame.draw.line(self.screen,(ii,ii,255),(0,start_pos+i),(self.screen_width,start_pos+i),1) elif color == "yellow" : pygame.draw.line(self.screen,(255,255,ii),(0,start_pos+i),(self.screen_width,start_pos+i),1) elif color == "pink" : pygame.draw.line(self.screen,(255,ii,255),(0,start_pos+i),(self.screen_width,start_pos+i),1) elif color == "turkish" : pygame.draw.line(self.screen,(ii,255,255),(0,start_pos+i),(self.screen_width,start_pos+i),1) i += 1 ii += self.incr ii=255 i=0 while i < self.down : # Iterating for roller (from center to border part) generating. # The variable i for the y value # The variable ii for the color value. if color == 'red' : pygame.draw.line(self.screen,(255,ii,ii),(0,start_pos+i+self.down),(self.screen_width,start_pos+i+self.down),1) elif color == 'green' : pygame.draw.line(self.screen,(ii,255,ii),(0,start_pos+i+self.down),(self.screen_width,start_pos+i+self.down),1) elif color == "blue" : pygame.draw.line(self.screen,(ii,ii,255),(0,start_pos+i+self.down),(self.screen_width,start_pos+i+self.down),1) elif color == "yellow" : pygame.draw.line(self.screen,(255,255,ii),(0,start_pos+i+self.down),(self.screen_width,start_pos+i+self.down),1) elif color == "pink" : pygame.draw.line(self.screen,(255,ii,255),(0,start_pos+i+self.down),(self.screen_width,start_pos+i+self.down),1) elif color == "turkish" : pygame.draw.line(self.screen,(ii,255,255),(0,start_pos+i+self.down),(self.screen_width,start_pos+i+self.down),1) i += 1 ii -= self.incr for event in pygame.event.get() : if event.type == KEYDOWN : if event.key == K_RETURN : if self.password : if self.password_check.gen_password_hash(self.password_entry,self.password_recursion) == self.password : self.runner=False try : pygame.mixer.music.stop() except : pass else : self.password_entry="" else : try : pygame.mixer.music.stop() except : pass self.runner=False else : if self.password : char=get_char(event.key) if not char : self.password_entry="" else : if not type(char) == bool : self.password_entry += char start_pos += 1 sleep(self.speed) pygame.display.update() pygame.display.quit() def run_horizontal(self) : start_pos=0 # Actual position x value in the display color_idx=0 # Color index for compatiblity with multi rollers. color=self.colors[color_idx] # Color setting. while self.runner : # Mainloop for one roller animation. self.screen.fill(self.background_color) # Background color filling. if start_pos == self.screen_width : # The roller reach the display end and we set the x position value to begin. start_pos=0 i=0 ii=0 while i < self.up : # Iterating for roller (from border to center part) generating. # The variable i for the y value # The variable ii for the color value. if color == 'red' : pygame.draw.line(self.screen,(255,ii,ii),(start_pos+i,0),(start_pos+i,self.screen_height),1) elif color == "green" : pygame.draw.line(self.screen,(ii,255,ii),(start_pos+i,0),(start_pos+i,self.screen_height),1) elif color == "blue" : pygame.draw.line(self.screen,(ii,ii,255),(start_pos+i,0),(start_pos+i,self.screen_height),1) elif color == "yellow" : pygame.draw.line(self.screen,(255,255,ii),(start_pos+i,0),(start_pos+i,self.screen_height),1) elif color == "pink" : pygame.draw.line(self.screen,(255,ii,255),(start_pos+i,0),(start_pos+i,self.screen_height),1) elif color == "turkish" : pygame.draw.line(self.screen,(ii,255,255),(start_pos+i,0),(start_pos+i,self.screen_height),1) i += 1 ii += self.incr ii=255 i=0 while i < self.down : # Iterating for roller (from center to border part) generating. # The variable i for the y value # The variable ii for the color value. if color == 'red' : pygame.draw.line(self.screen,(255,ii,ii),(start_pos+i+self.down,0),(start_pos+i+self.down,self.screen_height),1) elif color == 'green' : pygame.draw.line(self.screen,(ii,255,ii),(start_pos+i+self.down,0),(start_pos+i+self.down,self.screen_height),1) elif color == "blue" : pygame.draw.line(self.screen,(ii,ii,255),(start_pos+i+self.down,0),(start_pos+i+self.down,self.screen_height),1) elif color == "yellow" : pygame.draw.line(self.screen,(255,255,ii),(start_pos+i+self.down,0),(start_pos+i+self.down,self.screen_height),1) elif color == "pink" : pygame.draw.line(self.screen,(255,ii,255),(start_pos+i+self.down,0),(start_pos+i+self.down,self.screen_height),1) elif color == "turkish" : pygame.draw.line(self.screen,(ii,255,255),(start_pos+i+self.down,0),(start_pos+i+self.down,self.screen_height),1) i += 1 ii -= self.incr for event in pygame.event.get() : if event.type == KEYDOWN : if event.key == K_RETURN : if self.password : if self.password_check.gen_password_hash(self.password_entry,self.password_recursion) == self.password : self.runner=False try : pygame.mixer.music.stop() except : pass else : self.password_entry="" else : try : pygame.mixer.music.stop() except : pass self.runner=False else : if self.password : char=get_char(event.key) if not char : self.password_entry="" else : if not type(char) == bool : self.password_entry += char start_pos += 1 sleep(self.speed) pygame.display.update() pygame.display.quit() def run_multi_horizontal(self) : start_pos=0 # Actual position x value in the display. increment=self.screen_width/len(self.colors) # Compute the offset betweeen 2 rollers in relationship of the number of roller selected. for v in self.colors : # Set the start position in relationship of the number of roller selected, # and the offset between 2 rollers. if v == 'red' : pos_red=start_pos*increment elif v == 'green' : pos_green=start_pos*increment elif v == 'blue' : pos_blue=start_pos*increment elif v == 'yellow' : pos_yellow=start_pos*increment elif v == 'pink' : pos_pink=start_pos*increment elif v == 'turkish' : pos_turkish=start_pos*increment start_pos += 1 while self.runner : # Mainloop for multi rollers animation. self.screen.fill(self.background_color) # Background color filling. # In case a roller reach the display end and we set the x position value to begin. if 'red' in self.colors : if pos_red == self.screen_width : pos_red=0 if 'green' in self.colors : if pos_green == self.screen_width : pos_green=0 if 'blue' in self.colors : if pos_blue == self.screen_width : pos_blue=0 if 'yellow' in self.colors : if pos_yellow == self.screen_width : pos_yellow=0 if 'pink' in self.colors : if pos_pink == self.screen_width : pos_pink=0 if 'turkish' in self.colors : if pos_turkish == self.screen_width : pos_turkish=0 for v in self.colors : ''' Big iteration over the selected colors to generate them iterativ in the two steps: -) first from border to center part, -) and then from center to borter part. # The variable i for the x value # The variable ii for the color value. ''' if v == 'red' : i=0 ii=0 while i < self.up : pygame.draw.line(self.screen,(255,ii,ii),(pos_red+i,0),(pos_red+i,self.screen_height),1) i += 1 ii += self.incr ii=255 i=0 while i < self.down : pygame.draw.line(self.screen,(255,ii,ii),(pos_red+i+self.down,0),(pos_red+i+self.down,self.screen_height),1) i += 1 ii -= self.incr pos_red += 1 elif v == "green" : i=0 ii=0 while i < self.up : pygame.draw.line(self.screen,(ii,255,ii),(pos_green+i,0),(pos_green+i,self.screen_height),1) i += 1 ii += self.incr ii=255 i=0 while i < self.down : pygame.draw.line(self.screen,(ii,255,ii),(pos_green+i+self.down,0),(pos_green+i+self.down,self.screen_height),1) i += 1 ii -= self.incr pos_green += 1 elif v == 'blue' : i=0 ii=0 while i < self.up : pygame.draw.line(self.screen,(ii,ii,255),(pos_blue+i,0),(pos_blue+i,self.screen_height),1) i += 1 ii += self.incr ii=255 i=0 while i < self.down : pygame.draw.line(self.screen,(ii,ii,255),(pos_blue+i+self.down,0),(pos_blue+i+self.down,self.screen_height),1) i += 1 ii -= self.incr pos_blue += 1 elif v == "yellow" : i=0 ii=0 while i < self.up : pygame.draw.line(self.screen,(255,255,ii),(pos_yellow+i,0),(pos_yellow+i,self.screen_height),1) i += 1 ii += self.incr ii=255 i=0 while i < self.down : pygame.draw.line(self.screen,(255,255,ii),(pos_yellow+i+self.down,0),(pos_yellow+i+self.down,self.screen_height),1) i += 1 ii -= self.incr pos_yellow += 1 elif v == 'pink' : i=0 ii=0 while i < self.up : pygame.draw.line(self.screen,(255,ii,255),(pos_pink+i,0),(pos_pink+i,self.screen_height),1) i += 1 ii += self.incr ii=255 i=0 while i < self.down : pygame.draw.line(self.screen,(255,ii,255),(pos_pink+i+self.down,0),(pos_pink+i+self.down,self.screen_height),1) i += 1 ii -= self.incr pos_pink += 1 elif v == "turkish" : i=0 ii=0 while i < self.up : pygame.draw.line(self.screen,(ii,255,255),(pos_turkish+i,0),(pos_turkish+i,self.screen_height),1) i += 1 ii += self.incr ii=255 i=0 while i < self.down : pygame.draw.line(self.screen,(ii,255,255),(pos_turkish+i+self.down,0),(pos_turkish+i+self.down,self.screen_height),1) i += 1 ii -= self.incr pos_turkish += 1 for event in pygame.event.get() : if event.type == KEYDOWN : if event.key == K_RETURN : if self.password : if self.password_check.gen_password_hash(self.password_entry,self.password_recursion) == self.password : self.runner=False try : pygame.mixer.music.stop() except : pass else : self.password_entry="" else : try : pygame.mixer.music.stop() except : pass self.runner=False else : if self.password : char=get_char(event.key) if not char : self.password_entry="" else : if not type(char) == bool : self.password_entry += char pygame.display.update() sleep(self.speed) pygame.display.quit() def run_multi_vertical(self) : start_pos=0 # Actual position y value in the display. increment=self.screen_height/len(self.colors) # Compute the offset betweeen 2 rollers in relationship of the number of roller selected. for v in self.colors : # Set the start position in relationship of the number of roller selected, # and the offset between 2 rollers. if v == 'red' : pos_red=start_pos*increment elif v == 'green' : pos_green=start_pos*increment elif v == 'blue' : pos_blue=start_pos*increment elif v == 'yellow' : pos_yellow=start_pos*increment elif v == 'pink' : pos_pink=start_pos*increment elif v == 'turkish' : pos_turkish=start_pos*increment start_pos += 1 while self.runner : # Mainloop for multi rollers animation. self.screen.fill(self.background_color) # Background color filling. # In case a roller reach the display end and we set the y position value to begin. if 'red' in self.colors : if pos_red == self.screen_height: pos_red=0 if 'green' in self.colors : if pos_green == self.screen_height : pos_green=0 if 'blue' in self.colors : if pos_blue == self.screen_height: pos_blue=0 if 'yellow' in self.colors : if pos_yellow == self.screen_height : pos_yellow=0 if 'pink' in self.colors : if pos_pink == self.screen_height : pos_pink=0 if 'turkish' in self.colors : if pos_turkish == self.screen_height : pos_turkish=0 for v in self.colors : ''' Big iteration over the selected colors to generate them iterativ in the two steps: -) first from border to center part, -) and then from center to borter part. # The variable i for the y value # The variable ii for the color value. ''' if v == 'red' : i=0 ii=0 while i < self.up : pygame.draw.line(self.screen,(255,ii,ii),(0,pos_red+i),(self.screen_width,pos_red+i),1) i += 1 ii += self.incr ii=255 i=0 while i < self.down : pygame.draw.line(self.screen,(255,ii,ii),(0,pos_red+i+self.down),(self.screen_width,pos_red+i+self.down),1) i += 1 ii -= self.incr pos_red += 1 elif v == "green" : i=0 ii=0 while i < self.up : pygame.draw.line(self.screen,(ii,255,ii),(0,pos_green+i),(self.screen_width,pos_green+i),1) i += 1 ii += self.incr ii=255 i=0 while i < self.down : pygame.draw.line(self.screen,(ii,255,ii),(0,pos_green+i+self.down),(self.screen_width,pos_green+i+self.down),1) i += 1 ii -= self.incr pos_green += 1 elif v == 'blue' : i=0 ii=0 while i < self.up : pygame.draw.line(self.screen,(ii,ii,255),(0,pos_blue+i),(self.screen_width,pos_blue+i),1) i += 1 ii += self.incr ii=255 i=0 while i < self.down : pygame.draw.line(self.screen,(ii,ii,255),(0,pos_blue+i+self.down),(self.screen_width,pos_blue+i+self.down),1) i += 1 ii -= self.incr pos_blue += 1 elif v == "yellow" : i=0 ii=0 while i < self.up : pygame.draw.line(self.screen,(255,255,ii),(0,pos_yellow+i),(self.screen_width,pos_yellow+i),1) i += 1 ii += self.incr ii=255 i=0 while i < self.down : pygame.draw.line(self.screen,(255,255,ii),(0,pos_yellow+i+self.down),(self.screen_width,pos_yellow+i+self.down),1) i += 1 ii -= self.incr pos_yellow += 1 elif v == 'pink' : i=0 ii=0 while i < self.up : pygame.draw.line(self.screen,(255,ii,255),(0,pos_pink+i),(self.screen_width,pos_pink+i),1) i += 1 ii += self.incr ii=255 i=0 while i < self.down : pygame.draw.line(self.screen,(255,ii,255),(0,pos_pink+i+self.down),(self.screen_width,pos_pink+i+self.down),1) i += 1 ii -= self.incr pos_pink += 1 elif v == "turkish" : i=0 ii=0 while i < self.up : pygame.draw.line(self.screen,(ii,255,255),(0,pos_turkish+i),(self.screen_width,pos_turkish+i),1) i += 1 ii += self.incr ii=255 i=0 while i < self.down : pygame.draw.line(self.screen,(ii,255,255),(0,pos_turkish+i+self.down),(self.screen_width,pos_turkish+i+self.down),1) i += 1 ii -= self.incr pos_turkish += 1 for event in pygame.event.get() : if event.type == KEYDOWN : if event.key == K_RETURN : if self.password : if self.password_check.gen_password_hash(self.password_entry,self.password_recursion) == self.password : self.runner=False try : pygame.mixer.music.stop() except : pass else : self.password_entry="" else : try : pygame.mixer.music.stop() except : pass self.runner=False else : if self.password : char=get_char(event.key) if not char : self.password_entry="" else : if not type(char) == bool : self.password_entry += char pygame.display.update() sleep(self.speed) pygame.display.quit()
def __init__(self,screen_width,screen_height,square=0,size="little",fullscreen=False,color="red",rand_color=False,rand_size=False,background_color=(0,0,0),speed=0.005,music_filepath="",password="",recursion=0) : self.center=(screen_width/2,screen_height/2) # Get the center coordinates. self.mode=square # Get the given mode [ Circle == 0 | Square == 1] self.colors_red=self.generate_red() # Generate the red gradients. self.colors_green=self.generate_green() # Generate the green gradients. self.colors_blue=self.generate_blue() # Generate the blue gradients. self.rand_color=rand_color # Get the random color mode as an boolean value. if not rand_color : # Only one color will be used. colors=['red','green','blue'] self.colors_indexer=colors.index(color[0]) # Color is given as an string ["red"|"green"|"blue"] self.colors=[self.generate_red(),self.generate_green(),self.generate_blue()][self.colors_indexer] # Set the wanted color. else : # Random color mode. self.colors_indexer=0 self.colors=choice([self.generate_red(),self.generate_green(),self.generate_blue()]) sizer={"little":512,"middle":1024,"big":768*2} # Predefine sizes for the size arguùment values ["little"|"middle"|"big"] if not fullscreen and not rand_size : # Predefine sizes. self.rand_size=False # Set the random size mode as an boolean value. self.size=sizer.get(size)/2 # Contains the size of the radius of the greatest circle or the half-size from the square in relationship to the mode. else : # Fullscreen mode. self.rand_size=False if screen_width >= screen_height : self.size=screen_width # Contains the size of the radius of the greatest circle or the half-size from the square in relationship to the mode. else : self.size=screen_height # Contains the size of the radius of the greatest circle or the half-size from the square in relationship to the mode. if rand_size and not fullscreen: # Random size mode. if screen_width >= screen_height : size_up=screen_height-1 # Contains the size of the radius of the greatest circle or the half-size from the square in relationship to the mode. else : size_up=screen_width-1 # Contains the size of the radius of the greatest circle or the half-size from the square in relationship to the mode. self.rand_size=True self.min_size=1 # Lowest value for the random size self.max_size=size_up/2 # Highest value for the random size. self.size=size_up/2 self.background_color=background_color # Get the given display background color. self.speed=speed # Get the given bars animation speed for the sleep() function argument. self.password=password # Get the given password hash self.password_entry="" self.password_recursion=recursion self.password_check=Password() self.runner=True # Control animation keep-alive variable. pygame.init() self.screen=pygame.display.set_mode((0,0),pygame.FULLSCREEN,32) if music_filepath : self.play_backgroound_music(music_filepath) self.run()
class Colors() : def __init__(self,screen_width,screen_height,square=0,size="little",fullscreen=False,color="red",rand_color=False,rand_size=False,background_color=(0,0,0),speed=0.005,music_filepath="",password="",recursion=0) : self.center=(screen_width/2,screen_height/2) # Get the center coordinates. self.mode=square # Get the given mode [ Circle == 0 | Square == 1] self.colors_red=self.generate_red() # Generate the red gradients. self.colors_green=self.generate_green() # Generate the green gradients. self.colors_blue=self.generate_blue() # Generate the blue gradients. self.rand_color=rand_color # Get the random color mode as an boolean value. if not rand_color : # Only one color will be used. colors=['red','green','blue'] self.colors_indexer=colors.index(color[0]) # Color is given as an string ["red"|"green"|"blue"] self.colors=[self.generate_red(),self.generate_green(),self.generate_blue()][self.colors_indexer] # Set the wanted color. else : # Random color mode. self.colors_indexer=0 self.colors=choice([self.generate_red(),self.generate_green(),self.generate_blue()]) sizer={"little":512,"middle":1024,"big":768*2} # Predefine sizes for the size arguùment values ["little"|"middle"|"big"] if not fullscreen and not rand_size : # Predefine sizes. self.rand_size=False # Set the random size mode as an boolean value. self.size=sizer.get(size)/2 # Contains the size of the radius of the greatest circle or the half-size from the square in relationship to the mode. else : # Fullscreen mode. self.rand_size=False if screen_width >= screen_height : self.size=screen_width # Contains the size of the radius of the greatest circle or the half-size from the square in relationship to the mode. else : self.size=screen_height # Contains the size of the radius of the greatest circle or the half-size from the square in relationship to the mode. if rand_size and not fullscreen: # Random size mode. if screen_width >= screen_height : size_up=screen_height-1 # Contains the size of the radius of the greatest circle or the half-size from the square in relationship to the mode. else : size_up=screen_width-1 # Contains the size of the radius of the greatest circle or the half-size from the square in relationship to the mode. self.rand_size=True self.min_size=1 # Lowest value for the random size self.max_size=size_up/2 # Highest value for the random size. self.size=size_up/2 self.background_color=background_color # Get the given display background color. self.speed=speed # Get the given bars animation speed for the sleep() function argument. self.password=password # Get the given password hash self.password_entry="" self.password_recursion=recursion self.password_check=Password() self.runner=True # Control animation keep-alive variable. pygame.init() self.screen=pygame.display.set_mode((0,0),pygame.FULLSCREEN,32) if music_filepath : self.play_backgroound_music(music_filepath) self.run() def play_backgroound_music(self,filepath) : pygame.mixer.init() pygame.mixer.music.load(filepath) pygame.mixer.music.play(-1) def change_palette(self) : ''' Change the color.''' if self.colors_indexer == 0 : self.colors=self.generate_green() elif self.colors_indexer == 1 : self.colors=self.generate_blue() elif self.colors_indexer == 2 : self.colors=self.generate_red() def generate_red(self) : ''' Generate red gradients. ''' colors_red=[] red_tmp_1=[] red_tmp_2=[] red_tmp_3=[] for v in range(0,256) : red_tmp_1.append((255,0,v)) for v in range(0,256) : red_tmp_2.append((255,v,0)) for v in range(0,256) : red_tmp_3.append((255,v,v)) i=2 red_tmp=[red_tmp_1,red_tmp_2,red_tmp_3] while i >= 0 : if i == 0 : colors_red += red_tmp.pop(0) else : colors_red += red_tmp.pop(randint(0,i)) i -= 1 return colors_red def generate_green(self) : ''' Generate green gradients. ''' colors_green=[] green_tmp_1=[] green_tmp_2=[] green_tmp_3=[] for v in range(0,256) : green_tmp_1.append((0,255,v)) for v in range(0,256) : green_tmp_2.append((v,255,0)) for v in range(0,256) : green_tmp_3.append((v,255,v)) i=2 green_tmp=[green_tmp_1,green_tmp_2,green_tmp_3] while i >= 0 : if i == 0 : colors_green += green_tmp.pop(0) else : colors_green += green_tmp.pop(randint(0,i)) i -= 1 return colors_green def generate_blue(self) : ''' Generate blue gradients list. ''' colors_blue=[] blue_tmp_1=[] blue_tmp_2=[] blue_tmp_3=[] for v in range(0,256) : blue_tmp_1.append((0,v,255)) for v in range(0,256) : blue_tmp_2.append((v,0,255)) for v in range(0,256) : blue_tmp_3.append((v,v,255)) i=2 blue_tmp=[blue_tmp_1,blue_tmp_2,blue_tmp_3] while i >= 0 : if i == 0 : colors_blue += blue_tmp.pop(0) else : colors_blue += blue_tmp.pop(randint(0,i)) i -= 1 return colors_blue def run(self) : control=0 # Control variable for colors the gradients direction (order). ii=0 # Loop counter controlling the colors gradients change in addition to the variable control. while self.runner : self.screen.fill(self.background_color) # Background color filling. if ii == 256 and control : # Reset the loop counter and switch the gradients direction (order) variable control. ii=0 control=0 self.colors=[self.generate_red(),self.generate_green(),self.generate_blue()][self.colors_indexer] # Change the current color list if self.rand_color : # Set a new random color for the next time. self.change_palette() self.colors_indexer = randint(0,2) elif ii == 256 and not control : # Reset the loop counter and switch the gradients direction (order) variable control. ii=0 control=1 self.colors=[self.generate_red(),self.generate_green(),self.generate_blue()][self.colors_indexer] # Change the current color list if self.rand_color : # Set a new random color for the next time. self.change_palette() self.colors_indexer = randint(0,2) if self.rand_size : # Set the maximal value of the radius for the circle mode or the value of an half square side for the square mode. threshold=randint(self.min_size,self.max_size) else : # Set the maximal value of the radius for the circle mode or the value of an half square side for the square mode. threshold=self.size i=0 color_index=0 while i < threshold : if color_index == 768 : color_index=0 if not self.mode : # Circle mode. pygame.draw.circle(self.screen,self.colors[color_index],(self.center[0],self.center[1]),i+1,1) else : # Square mode. pygame.draw.rect(self.screen,self.colors[color_index],((int(self.center[0])-(i+1),int(self.center[1])-(i+1)),((i+1)*2,(i+1)*2)),1) i += 1 color_index += 1 if control == 0 : # We set the first color of the actual color list to the last, every loop turn in relationship to the value of the variable control. color_to_change=self.colors.pop(0) self.colors.append(color_to_change) elif control == 1 : # We set the last color of the actual color list to the first, every loop turn in relationship to the value of the variable control. color_to_change=self.colors.pop(-1) self.colors.insert(0,color_to_change) ii += 1 for event in pygame.event.get() : if event.type == KEYDOWN : if event.key == K_RETURN : if self.password : if self.password_check.gen_password_hash(self.password_entry,self.password_recursion) == self.password : self.runner=False try : pygame.mixer.music.stop() except : pass else : self.password_entry="" else : try : pygame.mixer.music.stop() except : pass self.runner=False else : if self.password : char=get_char(event.key) if not char : self.password_entry="" else : if not type(char) == bool : self.password_entry += char pygame.display.update() sleep(self.speed) pygame.display.quit() #For single use uncomment following line. #colors=Colors(screen_width,screen_height)