Advertisement
kekellner

Ejemplo con diccionarios

Mar 22nd, 2021
1,103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.98 KB | None | 0 0
  1. LED0 = [200, 200, 0]
  2. # [coordX, coordY,
  3. # boton0 = [100, 100, 50]
  4.  
  5. boton0 = {
  6.     "coorX": 150,
  7.     "coorY": 150,
  8.     "col": color(0, 255, 0),
  9.     "tama": 50,
  10.     "colPresionado": color(255, 0, 0)
  11. }
  12.  
  13. boton1 = {
  14.     "coorX": 250,
  15.     "coorY": 150,
  16.     "col": color(0, 0, 255),
  17.     "tama": 50,
  18.     "colPresionado": color(0, 255, 0)
  19. }
  20.  
  21. boton2 = {
  22.     "coorX": 350,
  23.     "coorY": 150,
  24.     "col": color(2500, 0, 255),
  25.     "tama": 50,
  26.     "colPresionado": color(255, 255, 0)
  27. }
  28.  
  29. def setup():
  30.     size(500, 500)
  31.  
  32. def draw():
  33.     background(0)
  34.     # esencialmente lo que estoy diciendo es que datos = boton0
  35.     pintarBotonDict(boton0)
  36.     pintarBotonDict(boton1)  # datos = boton1
  37.     pintarBotonDict(boton2)  # datos = boton2
  38.    
  39.     # entregarHelado(chocomenta, conoWaffle, 5) #terraza
  40.     # entregarHelado(galleta, conoPeq, 1)
  41.     # entregarHelado(pistacho, conoWaffle, 2)
  42.  
  43.     # pintarLED(LED0)
  44.     # pintarBoton(boton0)
  45.     # pintarBoton(boton1)
  46.     # pintarBoton(boton2)
  47.     # pintarBoton(boton3)
  48.  
  49. # def entregarHelado(sabor, tipoDeCono, cantidadDeBolas):
  50. #     tomarCono(tipoDeCono)
  51. #     tomarHelado(sabor)
  52. #     servirBolas(cantidadDeBolas)
  53.  
  54. def pintarBotonDict(datos):
  55.     fill(datos["col"])
  56.     square(datos["coorX"], datos["coorY"], datos["tama"])
  57.  
  58.     if mouseX >= datos["coorX"] and mouseX <= datos["coorX"] + datos["tama"]:
  59.         if mouseY >= datos["coorY"] and mouseY <= datos["coorY"] + datos["tama"]:
  60.             if mousePressed:
  61.                 fill(datos["colPresionado"])
  62.                 square(datos["coorX"], datos["coorY"], datos["tama"] - 20)
  63.  
  64. # def pintarLED(a):
  65. #     fill(128)
  66. #     circle(a[0], a[1], 50)
  67.  
  68. # def pintarBoton(datos):
  69. #     fill(180, 0, 0)
  70. #     square(datos[0], datos[1], datos[2])
  71.  
  72. #     if mousePressed:
  73. #         if mouseX > datos[0] and mouseX < datos[0] + datos[2] and mouseY > datos[1] and mouseY < datos[1] + datos[2]:
  74. #             fill(0, 180, 180)
  75. #             square(datos[0], datos[1], datos[2] * 0.8)
  76.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement