Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import random
- try:
- import pygame
- except:
- os.system("pip install pygame")
- try:
- import pygame
- except:
- print("No")
- run = True
- fail = False
- slide = False
- pygame.init()
- black = (0,0,0)
- white = (255,255,255)
- gray = (127,127,127)
- red = (255,0,0)
- green = (0,255,0)
- blue = (0,0,255)
- yellow = (255,255,0)
- purple = (255,0,255)
- cyan = (0,255,255)
- fps = 30
- coords = [0,0]
- prev = [0,0,[0,0,0]]
- color = white
- screen = pygame.display.set_mode((500,500))
- pygame.display.set_caption("PyPaint 3.0")
- x = 0
- y = 0
- u = 9999
- while u != 0:
- print("\n")
- u -= 1
- clock = pygame.time.Clock()
- ye = False
- nofill = False
- ok = """ ____ ____ _ __ _____
- / __ \__ __/ __ \____ _(_)___ / /_ |__ /
- / /_/ / / / / /_/ / __ `/ / __ \/ __/ /_ <
- / ____/ /_/ / ____/ /_/ / / / / / /_ ___/ /
- /_/ \__, /_/ \__,_/_/_/ /_/\__/ /____/
- /____/ """
- yeet = "--- Controls ---\nUse arrow keys to move."
- yeetis = "--- Color pallete ---\n1) Black\n2) White\n3) Gray\n4) Red\n5) Green\n6) Blue\n7) Pink\n8) Cyan\n9) Yellow"
- every = ok + "\n" + yeet + "\n" + yeetis
- yeet = None
- yeetis = None
- ok = None
- colors = [black, white, gray, red, green, blue, yellow, purple, cyan]
- color2 = black
- print(every)
- m = 0
- while run == True:
- clock.tick(fps)
- 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) + ")"
- if m != 10:
- m += 1
- else:
- m = 0
- print(every)
- print(yeetus)
- al = False
- if coords[0] < 0:
- coords[0] = 0
- if coords[0] >= 500:
- coords[0] = 490
- if coords[1] < 0 :
- coords[1] = 0
- if coords[1] >= 500:
- coords[1] = 490
- if color == black:
- color2 = white
- else:
- color2 = black
- if nofill == False:
- pygame.draw.rect(screen, color, (prev[0], prev[1], 10, 10))
- pygame.draw.rect(screen, color, (coords[0], coords[1], 10, 10))
- else:
- prevcolor = screen.get_at((prev[0], prev[1]))
- pygame.draw.rect(screen, prevcolor, (prev[0], prev[1], 10, 10))
- nowcolor = screen.get_at((coords[0], coords[1]))
- if nowcolor == white:
- color2 = black
- else:
- color2 = white
- pygame.draw.rect(screen, color2, (coords[0] + 2, coords[1] + 2, 6, 6))
- pygame.display.flip()
- events = pygame.event.get()
- prev = []
- prev.append(coords[0])
- prev.append(coords[1])
- for event in events:
- if event.type == pygame.QUIT:
- run = False
- elif event.type == pygame.KEYDOWN:
- if event.key == pygame.K_ESCAPE:
- run = False
- elif event.key == pygame.K_UP:
- coords[1] -= 10
- al = True
- elif event.key == pygame.K_DOWN:
- coords[1] += 10
- al = True
- elif event.key == pygame.K_LEFT:
- coords[0] -= 10
- al = True
- elif event.key == pygame.K_RIGHT:
- coords[0] += 10
- al = True
- elif event.key == pygame.K_z:
- screen.fill(black)
- elif event.key == pygame.K_x:
- screen.fill(color)
- elif event.key == pygame.K_1:
- color = black
- elif event.key == pygame.K_2:
- color = white
- elif event.key == pygame.K_3:
- color = gray
- elif event.key == pygame.K_4:
- color = red
- elif event.key == pygame.K_5:
- color = green
- elif event.key == pygame.K_6:
- color = blue
- elif event.key == pygame.K_7:
- color = yellow
- elif event.key == pygame.K_8:
- color = purple
- elif event.key == pygame.K_9:
- color = cyan
- elif event.key == pygame.K_c:
- f = open("raw.txt", "w+")
- f.write("image=[")
- l = [0,0,False,True,False]
- while l[2] != True:
- if l[3] == False:
- l[0] += 10
- else:
- l[3] = False
- if l[0] > 490:
- l[0] = 0
- l[1] += 10
- l[4] = True
- if l[1] > 490:
- l[2] = True
- if l[2] == False:
- pixel = list(screen.get_at((l[0], l[1])))
- pixel.pop(3)
- pixel = tuple(pixel)
- if pixel == black:
- pix = 1
- elif pixel == white:
- pix = 2
- elif pixel == gray:
- pix = 3
- elif pixel == red:
- pix = 4
- elif pixel == green:
- pix = 5
- elif pixel == blue:
- pix = 6
- elif pixel == yellow:
- pix = 7
- elif pixel == purple:
- pix = 8
- elif pixel == cyan:
- pix = 9
- else:
- pix = 0
- f.write(str(pix) + ",")
- pygame.draw.rect(screen, random.choice(colors), (l[0], l[1], 10, 10))
- pygame.display.flip()
- f.write("]")
- f.close()
- print(every)
- print(yeetus)
- screen.fill(black)
- elif event.key == pygame.K_v:
- f = open("raw.txt", "r")
- r = f.read()
- exec(r)
- pp = [0,0]
- for i in image:
- if i == 1:
- color3 = black
- elif i == 2:
- color3 = white
- elif i == 3:
- color3 = gray
- elif i == 4:
- color3 = red
- elif i == 5:
- color3 = green
- elif i == 6:
- color3 = blue
- elif i == 7:
- color3 = yellow
- elif i == 8:
- color3 = purple
- elif i == 9:
- color3 = cyan
- pygame.draw.rect(screen, color3, (pp[0], pp[1], 10, 10))
- pp[0] += 10
- if pp[0] > 490:
- pp[1] += 10
- pp[0] = 0
- if pp[1] > 490:
- break
- pygame.display.flip()
- elif event.key == pygame.K_b:
- if slide == True:
- slide = False
- else:
- slide = True
- elif event.key == pygame.K_n:
- if nofill == True:
- nofill = False
- else:
- nofill = True
- keys = pygame.key.get_pressed()
- if al == False and slide == True:
- if keys[pygame.K_UP] and keys[pygame.K_LEFT]:
- coords[1] -= 10
- coords[0] -= 10
- elif keys[pygame.K_UP] and keys[pygame.K_RIGHT]:
- coords[1] -= 10
- coords[0] += 10
- elif keys[pygame.K_DOWN] and keys[pygame.K_RIGHT]:
- coords[1] += 10
- coords[0] += 10
- elif keys[pygame.K_DOWN] and keys[pygame.K_LEFT]:
- coords[1] += 10
- coords[0] -= 10
- elif keys[pygame.K_UP]:
- coords[1] -= 10
- elif keys[pygame.K_DOWN]:
- coords[1] += 10
- elif keys[pygame.K_LEFT]:
- coords[0] -= 10
- elif keys[pygame.K_RIGHT]:
- coords[0] += 10
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement