Skip to content
Snippets Groups Projects
Commit 76a36637 authored by s183927's avatar s183927
Browse files

First commit, basic pygame GUI

parents
No related branches found
No related tags found
No related merge requests found
import pygame
import numpy as np
from random import randint
from sklearn.neighbors import NearestNeighbors
# init
pygame.init()
# resolution
width = 800
height = 600
# make the pygame window
display = pygame.display.set_mode((width, height))
# title of app
pygame.display.set_caption('Color Classification')
# set fonts
smallfont = pygame.font.SysFont('comicsansms', 25)
mediumfont = pygame.font.SysFont('comicsansms', 50)
largefont = pygame.font.SysFont('comicsansms', 80)
# matrixes of color, index 0 should be deleted
white = np.array([[0,0,0]])
black = np.array([[0,0,0]])
# write on screen
def text(msg,color,font,x,y):
screen_text = font.render(msg, True, color)
display.blit(screen_text, [x, y])
while True:
# random color
color = np.array([randint(0,255), randint(0,255), randint(0,255)])
loop = True
while loop:
# check for input to exit
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()
# color background
display.fill((123, 123, 123))
# write text
text('bazinga', (255,2,255), largefont, 75, 25)
# draw color boxes
pygame.draw.rect(display, color, [(width - 200) / 4, 300, 200, 200])
pygame.draw.rect(display, color, [(width - 200) / 1.25, 300, 200, 200])
# text
text('text', (255,255,255), largefont, (width - 200) / 4 + 20, 330)
text('text', (0,0,0), largefont, (width - 200) / 1.25 + 20, 330)
# check for mouse press in area and append point to list
for event in pygame.event.get():
if event.type == pygame.MOUSEBUTTONUP:
pos = pygame.mouse.get_pos()
if (pos[0] >= (width - 200) / 4 and (pos[0] <= (width - 200) / 4 + 200 and pos[1] >= 300 and pos[1] <= 300 + 200)):
white = np.vstack((white, color))
loop = False
if (pos[0] >= (width - 200) / 1.25 and (pos[0] <= (width - 200) / 1.25 + 200 and pos[1] >= 300 and pos[1] <= 300 + 200)):
black = np.vstack((black, color))
loop = False
# update display
pygame.display.update()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment