Advertisement
richigarza

ventilador.py

Nov 5th, 2012
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.38 KB | None | 0 0
  1. #!/usr/bin/python
  2. import random
  3. import time
  4. import pygame
  5. from pygame.locals import *
  6.  
  7. pygame.init()
  8.  
  9. SCREEN_WIDTH = 500
  10. SCREEN_HEIGHT = 350
  11. done = False
  12.  
  13. def clima(tempmin, tempmax, temp, tempprom):
  14.     while done==False:     
  15.         for i in range(0,24):
  16.                 # Imprime la hora, temperatura y el estado del ventilador
  17.         print "*============================*"
  18.         print "la hora es: ", int(i)
  19.              
  20.  
  21.         texttemp = str(temp)
  22.                 if i <= 11: # Si la hora es menor o igual 11, entonces genera un numero aleatorio entre la temperatura minima y la temp promedio
  23.                     dorand = str(random.randint(tempmin, tempprom)) # El random
  24.                 elif i <= 18: # Si la hora es menor o igual 18, entonces genera un numero aleatorio entre la temperatura promedio y la temp maxima
  25.                     dorand = str(random.randint(tempprom, tempmax))
  26.                 else: # Son las horas que faltan, generan un numero aleatorio entre la temperatura minima y la temp promedio
  27.                     dorand = str(random.randint(tempmin, tempprom))
  28.  
  29.                 print "la temperatura es: ", dorand
  30.  
  31.                 if dorand >= texttemp: # Si la temperatura es mayor o igual a la temperatura para encender el ventilador
  32.                         print "ventilador encendido" # Se encendió el ventilador
  33.             screen.blit(letra.render("Ventilador Encendido", True, (0, 100, 0)), (50, 260))
  34.         else: # Cuando la temperatura es menor a la que requiere el ventilador
  35.                 print "ventilador apagado" # El ventilador esta apagado
  36.             screen.blit(letra.render("Ventilador Apagado", True, (255, 0, 0)), (50, 260))
  37.         # Interfaz Grafica
  38.             pygame.display.update()
  39.                 screen.blit(letra2.render("Ventilador", True, (34, 139, 34)), (130, 50))
  40.             screen.blit(letra.render("Temperatura minima: %s C" % texttempmin, True, (0, 0, 0)), (50, 100)) # Temperatura Minima
  41.             screen.blit(letra.render("Temperatura maxima: %s C" % texttempmax, True, (0, 0, 0)), (50, 140)) # Temperatura Maxima
  42.             screen.blit(letra.render("Hora:  %s:00" % i, True, (0, 0, 0)), (50, 180)) # Hora
  43.             screen.blit(letra.render("Temperatura: %s C" % dorand, True, (0, 0, 0)), (50, 220)) # Temperatura registrada
  44.             pygame.display.update()
  45.             screen.blit(fondo, (0, 0))
  46.             time.sleep(1)
  47.  
  48.         for event in pygame.event.get():
  49.             if event.type == pygame.QUIT:
  50.                 exit()
  51.  
  52.  
  53.  
  54. if __name__ == "__main__":
  55.  
  56. # Captura las temperaturas del medio ambiente
  57.     try:
  58.       tempmin = int(val)
  59.     except:
  60.       tempmin = int(raw_input('Ingresa la temperatura minima: '))
  61.     try:
  62.       tempmax = int(val)
  63.     except:
  64.       tempmax = int(raw_input('Ingresa la temperatura maxima: '))
  65.     try:
  66.       temp = int(val)
  67.     except:
  68.       temp = int(raw_input('A que temperatura quieres encender el ventilador: '))
  69.  
  70.     screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
  71.     pygame.display.set_caption("Ventilador")
  72.     fondo = pygame.image.load("lol.png")
  73.     screen.blit(fondo, (0, 0))
  74.     letra = pygame.font.Font(None, 40)
  75.     letra2 = pygame.font.Font(None, 60)
  76.     screen.blit(fondo, (0, 0))
  77.     pygame.display.flip()
  78.     time.sleep(2)
  79.  
  80. # Condiciones iniciales para que el programa funcione
  81.     if tempmin >= 60: # Si la Temperatura es mayor a 60 NO CREO QUE PUEDA EXISTIR VIDA
  82.     print "No hay condiciones para vivir"
  83.     exit()
  84.     elif tempmax >= 60:# Si la Temperatura es mayor a 60 NO CREO QUE PUEDA EXISTIR VIDA
  85.     print "No hay condiciones para vivir"
  86.     exit()
  87.     elif tempmin > temp: # Que no este bien asignada la temperatura
  88.         print "Nunca se encendera el clima"
  89.         exit()
  90.     elif temp > tempmax: # Que no este bien asignada la temperatura
  91.         print "Nunca se encendera el clima"
  92.         exit()
  93.     elif tempmin >= tempmax: # Que la temperatura minima sea mayor a la temperatura maxima
  94.     print "La temperatura minima no puede ser mayor a la maxima"
  95.         exit()
  96.     else: # En caso de que no ocurran problemas
  97.     texttempmin = str(tempmin)
  98.     texttempmax = str(tempmax)
  99.         tempprom1 = int((tempmax - tempmin) / 2) # Diferencia entre temp minima y maxima
  100.     tempprom = tempmin + tempprom1  # Suma de la temperatura minima con la diferencia de temperaturas
  101.         print "La temp promedio es: ", tempprom # Imprime el promedio de temperaturas
  102.     pygame.display.update()
  103.     clima(tempmin, tempmax, temp, tempprom)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement