Advertisement
cookertron

Traffic lights

May 12th, 2020
1,200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.71 KB | None | 0 0
  1. import pygame
  2. import time
  3.  
  4. DW = DH = 400 # DisplayWidth, DisplayHeight
  5. HDW = int(DW / 2) # HalfDisplayWidth
  6. HDH = int(DH / 2) # HalfDisplayHeight
  7. pygame.init()
  8. PD = pygame.display.set_mode((DW, DH)) # PD = Primary Display
  9.  
  10. # colors
  11. RED = [255, 0, 0]
  12. AMBER = [255,191,0]
  13. GREEN = [0, 255, 0]
  14.  
  15. colors = [RED, AMBER, GREEN]
  16. colorIndex = 0
  17. timeStamp = -1
  18.  
  19. # press escape to get out!
  20. while True:
  21.     e = pygame.event.get()
  22.     if pygame.key.get_pressed()[pygame.K_ESCAPE]: break
  23.    
  24.     now = time.time()
  25.     if now - timeStamp >= 0.5:
  26.         pygame.draw.circle(PD, colors[colorIndex], (100, 100), 100)
  27.         pygame.display.update()
  28.         colorIndex += 1
  29.         if colorIndex == len(colors): colorIndex = 0
  30.         timeStamp = now
  31. pygame.quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement