Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Classification of Text-Background Color Combination
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
s183927
Classification of Text-Background Color Combination
Commits
76a36637
Commit
76a36637
authored
Dec 14, 2018
by
s183927
Browse files
Options
Downloads
Patches
Plain Diff
First commit, basic pygame GUI
parents
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
GamerAI.py
+72
-0
72 additions, 0 deletions
GamerAI.py
with
72 additions
and
0 deletions
GamerAI.py
0 → 100644
+
72
−
0
View file @
76a36637
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
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment