Skip to content

Instantly share code, notes, and snippets.

@wibbia
Last active August 29, 2015 14:11
Show Gist options
  • Save wibbia/2103717e77200a31eaa2 to your computer and use it in GitHub Desktop.
Save wibbia/2103717e77200a31eaa2 to your computer and use it in GitHub Desktop.
import pygame, sys, time
from pygame.locals import *
pygame.init()
white = 255,255,255
red = 255,0,0
black = 0,0,0
blue = 0,0,255
Orange = 255,185,0
magenta = 255,0,255
dark_magenta = 139,0,139
yellow = 255,255,0
dark_yellow = 139,139,0
pale_yellow = 80,50,0
green = 0,255,0
dark_green = 0,139,0
grey = 150,150,150
dark_red = 139,0,0
dark_blue = 0,0,139
dark_grey = 70,70,70
purple = 204,0,204
dark_purple = 153,0,153
size = width, height = 1000, 600
s = pygame.display.set_mode(size)
pygame.display.set_caption("Drawer")
s.fill(pale_yellow)
dhj = 0
i = 0
a = False
f = False
g = False
dr = False
dg = False
w = False
lc = False
saving = False
d = 0
b = pygame.draw.rect(s, red, (100,500,100,50))
c = pygame.draw.rect(s, black, (600,500,100,50))
e = pygame.draw.rect(s, blue, (200,500,100,50))
h = pygame.draw.rect(s, yellow, (300,500,100,50))
j = pygame.draw.rect(s, green, (400,500,100,50))
redstamp = pygame.draw.rect(s, red, (500,500,50,25))##
bluestamp = pygame.draw.rect(s, blue, (550,500,50,25))##
yellowstamp = pygame.draw.rect(s, yellow, (500,525,50,25))##
greenstamp = pygame.draw.rect(s, green, (550,525,50,25))##
helper = pygame.draw.rect(s, magenta, (700,500,100,50))
eraser = pygame.draw.rect(s, grey, (800,500,100,50))
canvas = pygame.draw.rect(s, grey, (10,10,980,456))
CoverCanvas = pygame.draw.rect(s, grey, (10,10,980,480))
lowerCanvas = pygame.draw.rect(s, pale_yellow, (0,560,1000,40))
saver = pygame.draw.rect(s, purple,(15,500,75,50))
scroll = pygame.draw.rect(s, red, (10,575,100,20))
sub = s.subsurface(canvas)
counter = 0
name_of_file = []
counting = 0
names = []
rb = "a"
bb = "b"
yb = "c"
gb = "d"
eb = "e"
lb = "f"
updates = []
words = "You can click on the Tools below to select your tool. The tool will go darker when you have selected it. To start the tool, click on the canvas (The grey section). To end the tool, click on the canvas again. Clear, will remove all of your work from the screen. Click stamp to display an image and click on the canvas to create as many stamps as you want. Press stamp again to get off of the tool. You can only draw on the canvas. By clicking and dragging on the percentage bar at the bottom of the screen, you will increase and decrease the size of the brush that you use. By clicking the save button, the canvas with all your work will be saved as a png in the folder of the application. You can name the file anything you want just by typing with the keyboard. Do not press enter though as this is not recognised. To save your image, name it, and then press the save button again. Once you have saved the image you won't be able to draw anymore of it so only save it when it is done. The Eraser tool, will remove any work when the eraser tool is dragged over it. Click the helper button again, otherwise you will draw over this text. Selecting two or more brushes at a time will cause problems. This means that if this does occur, you can drag down to the brush boxes and manually click them off. This does mean that the brush will continue drawing down to the bottom of the canvas. Finally, Enjoy Drawing!"
split = words.split()
height = 15
scale = [10]
distance = 100
dis = 1
di = [1]
updater = [10]
multi = []
length = 15
time1 = time.time()
time2 = time.time()
def Standard():
pygame.draw.rect(s, red, (updater[-1],575, 100,20))
myfont = pygame.font.SysFont("Calibri", 20)
label = myfont.render(str(round(di[-1]))+"%", 1, green)
s.blit(label, (updater[-1]+30, 576))
Standard()
position = 300
keysdown = [""]
key = keysdown[-1]
ratio = 100
reda = False
bluea = False
yellowa = False
greena = False
while True:
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
counting = 1
keysdown.append(event.key)
elif event.type == pygame.KEYUP:
keysdown.remove(event.key)
elif event.type == pygame.MOUSEBUTTONDOWN:
pos = x,y = pygame.mouse.get_pos()
if b.collidepoint(pos) and d == 0:
a = True
pygame.draw.rect(s, dark_red, (100,500,100,50))
updates.append(rb)
elif b.collidepoint(pos) and d == 1:
a = False
d = 0
pygame.draw.rect(s, red, (100,500,100,50))
continue
elif e.collidepoint(pos) and d == 0:
f = True
pygame.draw.rect(s, dark_blue, (200,500,100,50))
updates.append(bb)
elif e.collidepoint(pos) and d == 1:
f = False
d = 0
pygame.draw.rect(s, blue, (200,500,100,50))
continue
elif canvas.collidepoint(pos) and d == 2:
a = False
f = False
dr = False
dg = False
lc = False
if updates[-1] == "a":
pygame.draw.rect(s, red, (100,500,100,50))
a = False
pygame.draw.rect(s, pale_yellow, (0,560,1000,40))
Standard()
elif updates[-1] == "b":
pygame.draw.rect(s, blue, (200,500,100,50))
f = False
pygame.draw.rect(s, pale_yellow, (0,560,1000,40))
Standard()
elif updates[-1] == "c":
pygame.draw.rect(s, yellow, (300,500,100,50))
dr = False
pygame.draw.rect(s, pale_yellow, (0,560,1000,40))
Standard()
elif updates[-1] == "d":
pygame.draw.rect(s, green, (400,500,100,50))
dg = False
pygame.draw.rect(s, pale_yellow, (0,560,1000,40))
Standard()
elif updates[-1] == "e":
pygame.draw.rect(s, grey, (800,500,100,50))
w = False
pygame.draw.rect(s, pale_yellow, (0,560,1000,40))
Standard()
if d == 2:
d = 0
continue
elif lowerCanvas.collidepoint(pos) and d == 0:
lc = True
updates.append(lb)
elif lowerCanvas.collidepoint(pos) and d == 1:
lc = False
if x > 900:
x = 900
pygame.draw.rect(s, red, (x,575, 100,20))
myfont = pygame.font.SysFont("Calibri", 20)
label = myfont.render(str(Rounder)+"%", 1, green)
s.blit(label, (x + 30, 576))
d = 0
continue
elif c.collidepoint(pos):
s.fill(pale_yellow)
d = 0
pygame.draw.rect(s, red, (100,500,100,50))
pygame.draw.rect(s, black, (600,500,100,50))
pygame.draw.rect(s, blue, (200,500,100,50))
pygame.draw.rect(s, yellow, (300,500,100,50))
pygame.draw.rect(s, green, (400,500,100,50))
pygame.draw.rect(s, grey, (10,10,980,456))
pygame.draw.rect(s, grey, (10,10,980,480))
pygame.draw.rect(s, magenta, (700,500,100,50))
pygame.draw.rect(s, grey, (800,500,100,50))
pygame.draw.rect(s, purple, (15,500,75,50))
pygame.draw.rect(s, red, (updater[-1],575, 100,20))
pygame.draw.rect(s, red, (500,500,50,25))##
pygame.draw.rect(s, blue, (550,500,50,25))##
pygame.draw.rect(s, yellow, (500,525,50,25))##
pygame.draw.rect(s, green, (550,525,50,25))##
Standard()
continue
elif eraser.collidepoint(pos) and d == 0:
w = True
pygame.draw.rect(s,dark_grey,(800,500,100,50))
updates.append(eb)
elif eraser.collidepoint(pos) and d == 1:
w = False
d = 0
pygame.draw.rect(s,grey,(800,500,100,50))
continue
elif saver.collidepoint(pos) and d == 0:
saving = True
elif saver.collidepoint(pos) and d == 1:
saving = False
name = ''.join(str(namer) for namer in name_of_file)
for i in range(0, len(name_of_file)):
name_of_file.remove(name_of_file[0])
names.append(name)
pygame.draw.rect(s, dark_purple, (15,500,75,50))
pygame.image.save(sub, names[-1]+str(".png"))
counter += 1
d = 0
s.fill(pale_yellow)
d = 0
pygame.draw.rect(s, red, (100,500,100,50))
pygame.draw.rect(s, black, (600,500,100,50))
pygame.draw.rect(s, blue, (200,500,100,50))
pygame.draw.rect(s, yellow, (300,500,100,50))
pygame.draw.rect(s, green, (400,500,100,50))
pygame.draw.rect(s, grey, (10,10,980,456))
pygame.draw.rect(s, grey, (10,10,980,480))
pygame.draw.rect(s, magenta, (700,500,100,50))
pygame.draw.rect(s, grey, (800,500,100,50))
pygame.draw.rect(s, purple, (15,500,75,50))
pygame.draw.rect(s, red, (updater[-1],575, 100,20))
pygame.draw.rect(s, red, (500,500,50,25))##
pygame.draw.rect(s, blue, (550,500,50,25))##
pygame.draw.rect(s, yellow, (500,525,50,25))##
pygame.draw.rect(s, green, (550,525,50,25))##
Standard()
counting = 0
ratio = 100
keysdown = [""]
key = keysdown[-1]
continue
elif redstamp.collidepoint(pos) and d == 0:
reda = True
pygame.draw.rect(s, dark_red, (500,500,50,25))
elif redstamp.collidepoint(pos) and d == 1:
reda = False
d = 0
pygame.draw.rect(s, red,(500,500,50,25))
continue
elif bluestamp.collidepoint(pos) and d == 0:
bluea = True
pygame.draw.rect(s, dark_blue, (550,500,50,25))
elif bluestamp.collidepoint(pos) and d == 1:
bluea = False
d = 0
pygame.draw.rect(s, blue, (550,500,50,25))
continue
elif yellowstamp.collidepoint(pos) and d == 0:
yellowa = True
pygame.draw.rect(s, dark_yellow, (500,525,50,25))
elif yellowstamp.collidepoint(pos) and d == 1:
yellowa = False
d = 0
pygame.draw.rect(s, yellow, (500,525,50,25))
continue
elif greenstamp.collidepoint(pos) and d == 0:
greena = True
pygame.draw.rect(s, dark_green, (550,525,50,25))
elif greenstamp.collidepoint(pos) and d == 1:
greena = False
d = 0
pygame.draw.rect(s, green, (550,525,50,25))
continue
elif h.collidepoint(pos) and d == 0:
dr = True
pygame.draw.rect(s,dark_yellow,(300,500,100,50))
updates.append(yb)
elif h.collidepoint(pos) and d == 1:
dr = False
d = 0
pygame.draw.rect(s,yellow,(300,500,100,50))
continue
elif j.collidepoint(pos) and d == 0:
dg = True
pygame.draw.rect(s,dark_green,(400,500,100,50))
updates.append(gb)
elif j.collidepoint(pos) and d == 1:
dg = False
d = 0
pygame.draw.rect(s,green,(400,500,100,50))
continue
elif helper.collidepoint(pos) and d == 0:
pygame.draw.rect(s, dark_magenta, (700,500,100,50))
pygame.draw.rect(s, grey, (10,10,980,456))
pygame.draw.rect(s, grey, (10,10,980,480))
for word in split:
if length > 900:
height += 20
length = 15
myfont = pygame.font.SysFont("Calibri", 20)
label = myfont.render(word, 1, Orange)
s.blit(label, (length,height))
length += len(word) * 10 + 10
elif helper.collidepoint(pos) and d == 1:
pygame.draw.rect(s, magenta, (700,500,100,50))
pygame.draw.rect(s, grey, (10,10,980,456))
pygame.draw.rect(s, grey, (10,10,980,480))
height = 15
length = 15
elif reda == True and canvas.collidepoint(pos):
pos = x,y = pygame.mouse.get_pos()
pygame.draw.rect(s, red, (x,y,75,75))
continue
elif bluea == True and canvas.collidepoint(pos):
pos = x,y = pygame.mouse.get_pos()
pygame.draw.rect(s,blue, (x,y,75,75))
continue
elif yellowa == True and canvas.collidepoint(pos):
pos = x,y = pygame.mouse.get_pos()
pygame.draw.rect(s,yellow, (x,y,75,75))
continue
elif greena == True and canvas.collidepoint(pos):
pos = x,y = pygame.mouse.get_pos()
pygame.draw.rect(s,green, (x,y,75,75))
continue
d += 1
if d > 2:
d = 0
elif event.type == pygame.QUIT:
sys.exit()
if f == True and canvas.collidepoint(pos):
pos = x,y = pygame.mouse.get_pos()
pygame.draw.rect(s, blue, (x,y, scale[-1],scale[-1]))
if a == True and canvas.collidepoint(pos):
pos = x,y = pygame.mouse.get_pos()
pygame.draw.rect(s, red, (x,y, scale[-1],scale[-1]))
if dr == True and canvas.collidepoint(pos):
pos = x,y = pygame.mouse.get_pos()
pygame.draw.rect(s, yellow, (x,y, scale[-1],scale[-1]))
if dg == True and canvas.collidepoint(pos):
pos = x,y = pygame.mouse.get_pos()
pygame.draw.rect(s, green, (x,y, scale[-1],scale[-1]))
if w == True and canvas.collidepoint(pos):
pos = x,y = pygame.mouse.get_pos()
pygame.draw.rect(s, grey, (x,y, scale[-1],scale[-1]))
if saving == True:
if counting == 1:
key = keysdown[-1]
key = chr(key)
ratio += 15
name_of_file.append(key)
elif counting == 0:
pygame.draw.rect(s, black, (0, 555, 1000, 40))
myfont = pygame.font.SysFont("Calibri", 32)
label = myfont.render(str(key), 1, white)
label1 = myfont.render("Name: ", 1, white)
s.blit(label1, (10, 560))
s.blit(label, (ratio,560))
counting = 2
if lc == True and lowerCanvas.collidepoint(pos):
if dhj == 0:
di.append(10)
dhj += 1
Rounder = round(di[-1], 0)
pos = x,y = pygame.mouse.get_pos()
pygame.draw.rect(s, pale_yellow, (0,560,1000,40))
pygame.draw.rect(s, red, (x,575, 100,20))
myfont = pygame.font.SysFont("Calibri", 20)
label = myfont.render(str(Rounder)+"%", 1, green)
s.blit(label, (x + 30, 576))
updater.append(x)
if x > 900:
continue
elif x < 0:
continue
di.append((x *1.11)* dis/10)
pygame.display.flip()
scale.append(x/10)
ttime = time2 - time1
if round(ttime) > 2:
pygame.draw.rect(s, purple, (15,500,75,50))
time2 = time.time()
### Below is text for buttons ###
colours = ["Save","Red Brush", "Blue Brush", "Yellow Brush", "Green Brush", "Stamp", "Clear", "Helper", "Eraser"]
i = 50
for colour in colours:
myfont = pygame.font.SysFont("Calibri", 18)
label = myfont.render(colour, 1, Orange)
s.blit(label, (i - len(colour) * 4,515))
i += 100
pygame.display.flip()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment