import sys, pygame
from euclid import *

from Sketch import Sketch

pygame.init()

screen = pygame.display.set_mode((320, 240))

class MySketch(Sketch):
	def DrawLine(self, points):
		if len(points) == 1:
			points += [points[0]]
		r = pygame.draw.aalines(screen, (150, 150, 150), False, points, 1)
		#pygame.draw.rect(screen, [250, 200, 200], r, 1)
	
	def DrawSelectLine(self, points):
		if len(points) == 1:
			points += [points[0]]
		[pygame.draw.aalines(screen, [0, 0, 0], False, [(a + x, b + y) for a, b in points], 1) for x, y in [(0, 1), (0, -1), (-1, 0), (1, 0)]]
	
	def DrawCircles(self, circles):
		[pygame.draw.circle(screen, [255, 0, 0], c, 5, 1) for c in circles]
	
	def StartSelect(self, pos):
		print "selected"

s = MySketch()

def AddTuples(a, b):
	return [(a[i][0] + b[0], a[i][1] + b[1]) for i in range(len(a))]

while True:
	for event in pygame.event.get():
		if event.type == pygame.QUIT:
			sys.exit()
		
		if event.type == pygame.MOUSEBUTTONDOWN:
			s.PenDown(event.pos)
		if event.type == pygame.MOUSEMOTION:
			s.PenTo(event.pos)
		if event.type == pygame.MOUSEBUTTONUP:
			s.PenUp(event.pos)
	
	s.Update()
	screen.fill([255, 255, 255])
	s.Draw()
	pygame.display.flip()


