Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- import random
- import time
- import pygame
- from pygame.locals import *
- pygame.init()
- SCREEN_WIDTH = 500
- SCREEN_HEIGHT = 350
- done = False
- def clima(tempmin, tempmax, temp, tempprom):
- while done==False:
- for i in range(0,24):
- # Imprime la hora, temperatura y el estado del ventilador
- print "*============================*"
- print "la hora es: ", int(i)
- texttemp = str(temp)
- if i <= 11: # Si la hora es menor o igual 11, entonces genera un numero aleatorio entre la temperatura minima y la temp promedio
- dorand = str(random.randint(tempmin, tempprom)) # El random
- elif i <= 18: # Si la hora es menor o igual 18, entonces genera un numero aleatorio entre la temperatura promedio y la temp maxima
- dorand = str(random.randint(tempprom, tempmax))
- else: # Son las horas que faltan, generan un numero aleatorio entre la temperatura minima y la temp promedio
- dorand = str(random.randint(tempmin, tempprom))
- print "la temperatura es: ", dorand
- if dorand >= texttemp: # Si la temperatura es mayor o igual a la temperatura para encender el ventilador
- print "ventilador encendido" # Se encendió el ventilador
- screen.blit(letra.render("Ventilador Encendido", True, (0, 100, 0)), (50, 260))
- else: # Cuando la temperatura es menor a la que requiere el ventilador
- print "ventilador apagado" # El ventilador esta apagado
- screen.blit(letra.render("Ventilador Apagado", True, (255, 0, 0)), (50, 260))
- # Interfaz Grafica
- pygame.display.update()
- screen.blit(letra2.render("Ventilador", True, (34, 139, 34)), (130, 50))
- screen.blit(letra.render("Temperatura minima: %s C" % texttempmin, True, (0, 0, 0)), (50, 100)) # Temperatura Minima
- screen.blit(letra.render("Temperatura maxima: %s C" % texttempmax, True, (0, 0, 0)), (50, 140)) # Temperatura Maxima
- screen.blit(letra.render("Hora: %s:00" % i, True, (0, 0, 0)), (50, 180)) # Hora
- screen.blit(letra.render("Temperatura: %s C" % dorand, True, (0, 0, 0)), (50, 220)) # Temperatura registrada
- pygame.display.update()
- screen.blit(fondo, (0, 0))
- time.sleep(1)
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- exit()
- if __name__ == "__main__":
- # Captura las temperaturas del medio ambiente
- try:
- tempmin = int(val)
- except:
- tempmin = int(raw_input('Ingresa la temperatura minima: '))
- try:
- tempmax = int(val)
- except:
- tempmax = int(raw_input('Ingresa la temperatura maxima: '))
- try:
- temp = int(val)
- except:
- temp = int(raw_input('A que temperatura quieres encender el ventilador: '))
- screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
- pygame.display.set_caption("Ventilador")
- fondo = pygame.image.load("lol.png")
- screen.blit(fondo, (0, 0))
- letra = pygame.font.Font(None, 40)
- letra2 = pygame.font.Font(None, 60)
- screen.blit(fondo, (0, 0))
- pygame.display.flip()
- time.sleep(2)
- # Condiciones iniciales para que el programa funcione
- if tempmin >= 60: # Si la Temperatura es mayor a 60 NO CREO QUE PUEDA EXISTIR VIDA
- print "No hay condiciones para vivir"
- exit()
- elif tempmax >= 60:# Si la Temperatura es mayor a 60 NO CREO QUE PUEDA EXISTIR VIDA
- print "No hay condiciones para vivir"
- exit()
- elif tempmin > temp: # Que no este bien asignada la temperatura
- print "Nunca se encendera el clima"
- exit()
- elif temp > tempmax: # Que no este bien asignada la temperatura
- print "Nunca se encendera el clima"
- exit()
- elif tempmin >= tempmax: # Que la temperatura minima sea mayor a la temperatura maxima
- print "La temperatura minima no puede ser mayor a la maxima"
- exit()
- else: # En caso de que no ocurran problemas
- texttempmin = str(tempmin)
- texttempmax = str(tempmax)
- tempprom1 = int((tempmax - tempmin) / 2) # Diferencia entre temp minima y maxima
- tempprom = tempmin + tempprom1 # Suma de la temperatura minima con la diferencia de temperaturas
- print "La temp promedio es: ", tempprom # Imprime el promedio de temperaturas
- pygame.display.update()
- clima(tempmin, tempmax, temp, tempprom)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement