Advertisement
IshaanGarud

Simple User Interaction with PYGAME

Sep 29th, 2020
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. """Although I am only 12 YEARS OlD(tomorrow i will be 13(30th SEP))
  2. I Made It On My Own
  3. Please Enjoy!!
  4.  
  5. INSTAGRAM:- @ishaan_garud3097
  6. :-) :-) :-D :-D"""
  7.  
  8.  
  9. import sys
  10. import pygame
  11. import random
  12. from pygame.locals import *
  13.  
  14. pygame.init()
  15. # Resolution is ignored on Android
  16. surface = pygame.display.set_mode((640, 480))
  17. clock = pygame.time.Clock()
  18. surfrect = surface.get_rect()
  19. rect = pygame.Rect((0, 0), (128, 128))
  20. rect.center = (surfrect.w / 2, surfrect.h / 2)
  21. #--------------RGB---------------
  22. r = (255,0,0)
  23. g = (0,255,0)
  24. b = (0,0,255)
  25. #--------------CYMO---------------
  26. c = (0,255,255)
  27. y = (255,255,0)
  28. m = (255,0,255)
  29. o = (255,150,75)
  30. #--------------Light--------------
  31. pnk = (255,150,150)
  32. l_g = (125,255,125)
  33. l_b = (100,200,255)
  34.  
  35. colors = [r,g,b,c,y,m,o,pnk,l_g,l_b]
  36. touched = False
  37. while True:
  38. for ev in pygame.event.get():
  39. if ev.type == QUIT:
  40. pygame.quit()
  41. elif ev.type == pygame.MOUSEBUTTONDOWN:
  42. r_colors = random.choice(colors)
  43. if rect.collidepoint(ev.pos):
  44. touched = True
  45. # This is the starting point
  46. pygame.mouse.get_rel()
  47. elif ev.type == pygame.MOUSEBUTTONUP:
  48. touched = False
  49. clock.tick(60)
  50. surface.fill((0,0,0))
  51. if touched:
  52. rect.move_ip(pygame.mouse.get_rel())
  53. rect.clamp_ip(surfrect)
  54. surface.fill(r_colors)
  55. surface.fill((255, 255, 255), rect)
  56. pygame.display.flip()
  57.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement