Advertisement
Guest User

PyPaint 3

a guest
Jan 4th, 2020
1,106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 8.23 KB | None | 0 0
  1. import os
  2. import random
  3. try:
  4.     import pygame
  5. except:
  6.     os.system("pip install pygame")
  7.     try:
  8.         import pygame
  9.     except:
  10.         print("No")
  11. run = True
  12. fail = False
  13. slide = False
  14. pygame.init()
  15. black = (0,0,0)
  16. white = (255,255,255)
  17. gray = (127,127,127)
  18. red = (255,0,0)
  19. green = (0,255,0)
  20. blue = (0,0,255)
  21. yellow = (255,255,0)
  22. purple = (255,0,255)
  23. cyan = (0,255,255)
  24. fps = 30
  25. coords = [0,0]
  26. prev = [0,0,[0,0,0]]
  27. color = white
  28. screen = pygame.display.set_mode((500,500))
  29. pygame.display.set_caption("PyPaint 3.0")
  30. x = 0
  31. y = 0
  32. u = 9999
  33. while u != 0:
  34.     print("\n")
  35.     u -= 1
  36. clock = pygame.time.Clock()
  37. ye = False
  38. nofill = False
  39. ok = """    ____        ____        _       __     _____
  40.   / __ \__  __/ __ \____ _(_)___  / /_   |__  /
  41.  / /_/ / / / / /_/ / __ `/ / __ \/ __/    /_ <
  42. / ____/ /_/ / ____/ /_/ / / / / / /_    ___/ /
  43. /_/    \__, /_/    \__,_/_/_/ /_/\__/   /____/  
  44.      /____/                                    """
  45. yeet = "--- Controls ---\nUse arrow keys to move."
  46. yeetis = "--- Color pallete ---\n1) Black\n2) White\n3) Gray\n4) Red\n5) Green\n6) Blue\n7) Pink\n8) Cyan\n9) Yellow"
  47. every = ok + "\n" + yeet + "\n" + yeetis
  48. yeet = None
  49. yeetis = None
  50. ok = None
  51. colors = [black, white, gray, red, green, blue, yellow, purple, cyan]
  52. color2 = black
  53. print(every)
  54. m = 0
  55. while run == True:
  56.     clock.tick(fps)
  57.     yeetus = "--- Commands ---\nZ) Clear screen\nX) Fill screen with selected color\nC) Save current painting into save file (raw.txt)\nV) Load painting from save file (raw.txt)\nB) Slide mode (Current state: " + str(slide) + ")\nN) No fill mode (Current state: " + str(nofill) + ")"
  58.     if m != 10:
  59.         m += 1
  60.     else:
  61.         m = 0
  62.         print(every)
  63.         print(yeetus)
  64.     al = False
  65.     if coords[0] < 0:
  66.         coords[0] = 0
  67.     if coords[0] >= 500:
  68.         coords[0] = 490
  69.     if coords[1] < 0 :
  70.         coords[1] = 0
  71.     if coords[1] >= 500:
  72.         coords[1] = 490
  73.     if color == black:
  74.         color2 = white
  75.     else:
  76.         color2 = black
  77.     if nofill == False:
  78.         pygame.draw.rect(screen, color, (prev[0], prev[1], 10, 10))
  79.         pygame.draw.rect(screen, color, (coords[0], coords[1], 10, 10))
  80.     else:
  81.         prevcolor = screen.get_at((prev[0], prev[1]))
  82.         pygame.draw.rect(screen, prevcolor, (prev[0], prev[1], 10, 10))
  83.         nowcolor = screen.get_at((coords[0], coords[1]))
  84.         if nowcolor == white:
  85.             color2 = black
  86.         else:
  87.             color2 = white
  88.     pygame.draw.rect(screen, color2, (coords[0] + 2, coords[1] + 2, 6, 6))
  89.     pygame.display.flip()
  90.     events = pygame.event.get()
  91.     prev = []
  92.     prev.append(coords[0])
  93.     prev.append(coords[1])
  94.     for event in events:
  95.         if event.type == pygame.QUIT:
  96.             run = False
  97.         elif event.type == pygame.KEYDOWN:
  98.             if event.key == pygame.K_ESCAPE:
  99.                 run = False
  100.             elif event.key == pygame.K_UP:
  101.                 coords[1] -= 10
  102.                 al = True
  103.             elif event.key == pygame.K_DOWN:
  104.                 coords[1] += 10
  105.                 al = True
  106.             elif event.key == pygame.K_LEFT:
  107.                 coords[0] -= 10
  108.                 al = True
  109.             elif event.key == pygame.K_RIGHT:
  110.                 coords[0] += 10
  111.                 al = True
  112.             elif event.key == pygame.K_z:
  113.                 screen.fill(black)
  114.             elif event.key == pygame.K_x:
  115.                 screen.fill(color)
  116.             elif event.key == pygame.K_1:
  117.                 color = black
  118.             elif event.key == pygame.K_2:
  119.                 color = white
  120.             elif event.key == pygame.K_3:
  121.                 color = gray
  122.             elif event.key == pygame.K_4:
  123.                 color = red
  124.             elif event.key == pygame.K_5:
  125.                 color = green
  126.             elif event.key == pygame.K_6:
  127.                 color = blue
  128.             elif event.key == pygame.K_7:
  129.                 color = yellow
  130.             elif event.key == pygame.K_8:
  131.                 color = purple
  132.             elif event.key == pygame.K_9:
  133.                 color = cyan
  134.             elif event.key == pygame.K_c:
  135.                 f = open("raw.txt", "w+")
  136.                 f.write("image=[")
  137.                 l = [0,0,False,True,False]
  138.                 while l[2] != True:
  139.                     if l[3] == False:
  140.                         l[0] += 10
  141.                     else:
  142.                         l[3] = False
  143.                     if l[0] > 490:
  144.                         l[0] = 0
  145.                         l[1] += 10
  146.                         l[4] = True
  147.                     if l[1] > 490:
  148.                         l[2] = True
  149.                     if l[2] == False:
  150.                         pixel = list(screen.get_at((l[0], l[1])))
  151.                         pixel.pop(3)
  152.                         pixel = tuple(pixel)
  153.                         if pixel == black:
  154.                             pix = 1
  155.                         elif pixel == white:
  156.                             pix = 2
  157.                         elif pixel == gray:
  158.                             pix = 3
  159.                         elif pixel == red:
  160.                             pix = 4
  161.                         elif pixel == green:
  162.                             pix = 5
  163.                         elif pixel == blue:
  164.                             pix = 6
  165.                         elif pixel == yellow:
  166.                             pix = 7
  167.                         elif pixel == purple:
  168.                             pix = 8
  169.                         elif pixel == cyan:
  170.                             pix = 9
  171.                         else:
  172.                             pix = 0
  173.                         f.write(str(pix) + ",")
  174.                         pygame.draw.rect(screen, random.choice(colors), (l[0], l[1], 10, 10))
  175.                         pygame.display.flip()
  176.                 f.write("]")
  177.                 f.close()
  178.                 print(every)
  179.                 print(yeetus)
  180.                 screen.fill(black)
  181.             elif event.key == pygame.K_v:
  182.                 f = open("raw.txt", "r")
  183.                 r = f.read()
  184.                 exec(r)
  185.                 pp = [0,0]
  186.                 for i in image:
  187.                     if i == 1:
  188.                         color3 = black
  189.                     elif i == 2:
  190.                         color3 = white
  191.                     elif i == 3:
  192.                         color3 = gray
  193.                     elif i == 4:
  194.                         color3 = red
  195.                     elif i == 5:
  196.                         color3 = green
  197.                     elif i == 6:
  198.                         color3 = blue
  199.                     elif i == 7:
  200.                         color3 = yellow
  201.                     elif i == 8:
  202.                         color3 = purple
  203.                     elif i == 9:
  204.                         color3 = cyan
  205.                     pygame.draw.rect(screen, color3, (pp[0], pp[1], 10, 10))
  206.                     pp[0] += 10
  207.                     if pp[0] > 490:
  208.                         pp[1] += 10
  209.                         pp[0] = 0
  210.                     if pp[1] > 490:
  211.                         break
  212.                     pygame.display.flip()
  213.             elif event.key == pygame.K_b:
  214.                 if slide == True:
  215.                     slide = False
  216.                 else:
  217.                     slide = True
  218.             elif event.key == pygame.K_n:
  219.                 if nofill == True:
  220.                     nofill = False
  221.                 else:
  222.                     nofill = True
  223.     keys = pygame.key.get_pressed()
  224.     if al == False and slide == True:
  225.         if keys[pygame.K_UP] and keys[pygame.K_LEFT]:
  226.             coords[1] -= 10
  227.             coords[0] -= 10
  228.         elif keys[pygame.K_UP] and keys[pygame.K_RIGHT]:
  229.             coords[1] -= 10
  230.             coords[0] += 10
  231.         elif keys[pygame.K_DOWN] and keys[pygame.K_RIGHT]:
  232.             coords[1] += 10
  233.             coords[0] += 10
  234.         elif keys[pygame.K_DOWN] and keys[pygame.K_LEFT]:
  235.             coords[1] += 10
  236.             coords[0] -= 10
  237.         elif keys[pygame.K_UP]:
  238.             coords[1] -= 10
  239.         elif keys[pygame.K_DOWN]:
  240.             coords[1] += 10
  241.         elif keys[pygame.K_LEFT]:
  242.             coords[0] -= 10
  243.         elif keys[pygame.K_RIGHT]:
  244.             coords[0] += 10
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement