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 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()
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_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 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)