rishabbansal21

lens

Mar 31st, 2021 (edited)
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.88 KB | None | 0 0
  1. import pygame
  2. pygame.init()
  3.  
  4. clock = pygame.time.Clock()
  5.  
  6. screen = pygame.display.set_mode((800,600))
  7. pygame.display.set_caption("LENSES")
  8.  
  9. font_16 = pygame.font.Font('freesansbold.ttf', 16)
  10. font_23 = pygame.font.Font('freesansbold.ttf', 23)
  11.  
  12. move = 5
  13. x1 = 10
  14. x2 = 110
  15. y1 = 200
  16. y2 = 250
  17. y3 = 350
  18. y4 = 400
  19. y11 = 200
  20. y22 = 250
  21. y33 = 350
  22. y44 = 400
  23. o = False
  24. f = False
  25.  
  26. running = True
  27. while running:
  28.     screen.fill((50,50,50))
  29.  
  30.     for event in pygame.event.get():
  31.         if event.type == pygame.QUIT:
  32.             running = False
  33.  
  34.  
  35.     pygame.draw.ellipse(screen, (176,208,218), (385, 150, 30, 300))
  36.     pygame.draw.line(screen, (255,0,0), (0,300), (800,300))
  37.  
  38.     pygame.draw.line(screen, (255,0,0), (400,290), (400,310))
  39.     screen.blit(font_16.render("O", True, (255,0,0)), (395,315))
  40.  
  41.     pygame.draw.line(screen, (255,0,0), (200, 290), (200,310))
  42.     screen.blit(font_16.render("C", True, (255,0,0)), (195,315))
  43.     pygame.draw.line(screen, (255,0,0), (300, 290), (300,310))
  44.     screen.blit(font_16.render("F", True, (255,0,0)), (295,315))
  45.  
  46.     pygame.draw.line(screen, (255,0,0), (600, 290), (600,310))
  47.     screen.blit(font_16.render("C", True, (255,0,0)), (595,315))
  48.     pygame.draw.line(screen, (255,0,0), (500, 290), (500,310))
  49.     screen.blit(font_16.render("F", True, (255,0,0)), (495,315))
  50.  
  51.     pygame.draw.line(screen, (255,255,255), (5,190), (5,410), 4)
  52.  
  53.  
  54.     if not(o):
  55.         x1 += move
  56.         x2 += move
  57.  
  58.         if x2 == 400:
  59.             o = True
  60.  
  61.     if o and not(f):
  62.         move = 2
  63.         x1 += move
  64.         x2 += move
  65.         y11 += 2
  66.         y22 += 1
  67.         y33 += -1
  68.         y44 += -2
  69.  
  70.         if x2 == 500:
  71.             f = True
  72.  
  73.     if f:
  74.         move = 2
  75.         x1 += move
  76.         x2 += move
  77.  
  78.         y1 += 2
  79.         y2 += 1
  80.         y3 += -1
  81.         y4 += -2
  82.  
  83.         y11 += 2
  84.         y22 += 1
  85.         y33 += -1
  86.         y44 += -2
  87.  
  88.         if x2 > 605:
  89.             move = 5
  90.             x1 = 10
  91.             x2 = 110
  92.             y1 = 200
  93.             y2 = 250
  94.             y3 = 350
  95.             y4 = 400
  96.             y11 = 200
  97.             y22 = 250
  98.             y33 = 350
  99.             y44 = 400
  100.             o = False
  101.             f = False
  102.  
  103.  
  104.     pygame.draw.line(screen, (255,255,255), (x1,y1), (x2,y11), 2)
  105.     pygame.draw.line(screen, (255,255,255), (x1,y2), (x2,y22), 2)
  106.     pygame.draw.line(screen, (255,255,255), (x1,300), (x2,300), 2)
  107.     pygame.draw.line(screen, (255,255,255), (x1,y3), (x2,y33), 2)
  108.     pygame.draw.line(screen, (255,255,255), (x1,y4), (x2,y44), 2)
  109.  
  110.     msg1 = "When an object is placed at infinity, the real image is formed at the"
  111.     msg2 = "focus. The size of the image is point sized (highly diminished)."
  112.     screen.blit(font_23.render(msg1, True, (255,255,255)), (5,10))
  113.     screen.blit(font_23.render(msg2, True, (255,255,255)), (5,35))
  114.  
  115.     clock.tick(10)
  116.     pygame.display.update()
Add Comment
Please, Sign In to add comment