-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.py
More file actions
44 lines (37 loc) · 1.11 KB
/
Main.py
File metadata and controls
44 lines (37 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import pygame
import sys
import Perceptron
import Training
pygame.init()
size = width, height = 800, 800
white = 255, 255, 255
screen = pygame.display.set_mode(size)
screen.fill(white)
point_list = []
for item in range(100):
point_list.append(Training.Point(width,height, screen))
for item in point_list:
item.show()
p = Perceptron.Perceptron()
pygame.draw.line(screen, (0, 0, 0), (0,0),(width,height))
training_index = 0
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
if event.type == pygame.MOUSEBUTTONDOWN:
for item in point_list:
inputs = (item.x, item.y)
target = item.label
p.train(inputs, target)
for item in point_list:
item.show()
for item in point_list:
target = item.label
inputs = (item.x, item.y)
guess = p.guess(inputs)
if guess == target:
pygame.draw.circle(screen, (0, 255, 0), [item.x, item.y], 4)
else:
pygame.draw.circle(screen, (255, 0 , 0), [item.x, item.y], 4)
pygame.display.update()