Last active
April 21, 2018 22:26
-
-
Save AgustinParmisano/8921b3a4e708b61f1be0809548427628 to your computer and use it in GitHub Desktop.
pygame + lambda example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
#Desarrolle un programa en Python3 utilizando Pygame y expresiones lambda | |
#que genere figuras de distintos colores según la posicion del puntero y el tiempo. | |
#Las figuras no deben exeder los 100 píxeles de diámetro. | |
#Debe dar la sesación que el cursor pinta en la pantalla. | |
import pygame | |
import datetime | |
pygame.init() | |
screen = pygame.display.set_mode((800,600)) | |
pygame.display.set_caption('Hello Pygame!') | |
clock = pygame.time.Clock() | |
crashed = False | |
value_filter = lambda value : value if (value < 255 and value > 0) else value_adjuster(value) | |
def value_adjuster(value): | |
while value > 255: | |
value = value / 2 | |
while value < 0: | |
value = value + 254 | |
return value | |
def color_cursor(x,y): | |
seconds = int(datetime.datetime.now().strftime('%M:%S.%f').split(":")[-1][0:2]) | |
seconds_filter = lambda value : seconds * value | |
size = 25 | |
size_x = x + size | |
size_y = y + size | |
red = value_filter(x) | |
green = value_filter(y) | |
blue = value_filter(seconds_filter(x - y)) | |
width = 50 | |
print("X: {} Y: {} color_filter(X-Y): {}".format(x,y,seconds_filter(x - y))) | |
print(red) | |
print(green) | |
print(blue) | |
#pygame.draw.line(screen, (green,red,large_value_filter(seconds_filter(t))), t, (x-10,y-10)) | |
pygame.draw.polygon(screen, (red,green,blue), [(x,y),(size_x,size_y)], width) | |
while not crashed: | |
for event in pygame.event.get(): | |
if event.type == pygame.QUIT: | |
crashed = True | |
#print(event) | |
cursor_xy = pygame.mouse.get_pos() | |
color_cursor(cursor_xy[0],cursor_xy[1]) | |
pygame.display.update() | |
clock.tick(60) | |
pygame.quit() | |
quit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment