import os, math, random
#---------------------------------------------------pygame
import pygame
from pygame.locals import *
#---------------------------------------i like when color are named
coal = (51,51,51)
green = (0,200,0)
red = (200,0,0)
blue = (0,0,200)
#----------------------------------------------------control sprite
class mice(pygame.sprite.Sprite):
	def __init__(self):
		pygame.sprite.Sprite.__init__(self)
		self.button = None
		self.moved = None
		self.position = None
		self.pressed = None
		self.raize = None
		
		self.image = pygame.Surface((1,1))
		self.image.set_colorkey((255,255,255))
		self.rect = self.image.get_rect()
		
	def update(self):
		self.button = pygame.mouse.get_pressed()	
		self.moved = pygame.mouse.get_rel()
		self.position = pygame.mouse.get_pos()
		if True in self.button :
			if self.pressed != True:
				self.raize = True
			else:
				self.raize = False
			self.pressed = True
		else:
			self.pressed = False
			self.raize = False
		self.rect.center = self.position

#----------------------------------------------------simple matrix
class m2(list):
	#very simple 2d matrix for map making

	def __init__(self,w,h,fill=None):	#choose ure width and heitgh
		self.w, self.h = w, h
		for x in range(w*h):
			self.append(fill)
			
	def offset(self,x,y):
		if x > self.w or y > self.h:
			return -1
		return (x + (y*self.w))

	def at(self,x,y,fill=None):
		if x > self.w or y > self.h:
			return -1
		if fill != None:
			self[self.offset(x,y)] = fill
		return self[self.offset(x,y)]
		
	def where(self,fill):
		tmp = self.index(fill)
		return (tmp % self.w, tmp / self.w)
		
	def get_line(self,y,fills=[]):
		tmp = []
		if len(fills) > 0 and len(fills) != self.w:
			return -1
		for x in range(self.w):
			if len(fills) == self.w:
				self.at(x,y,fills[x])
			tmp.append( self.at(x,y))
		return tmp
		
	def get_col(self,x,fills=[]):
		tmp = []
		if len(fills) > 0 and len(fills) != self.h:
			return -1
		for y in range(self.h):
			if len(fills) == self.h:
				self.at(x,y,fills[y])
			tmp.append(self.at(x,y))
		return tmp
#----------------------------------------------------simple vector
class v2(object):
	#very simple 2d vector class
	def __init__(self, x=0.0, y=0.0):
		if type(x) == (tuple or list):
			x,y = x[0],x[1]
		if (type(x) and type(y)) == (int or float or long or complex):
        		self.x = x
			self.y = y
		else:
			self.x,self.y = 0.0, 0.0

 	def __len__(self):
		return 2
	def __repr__(self):
		return 'v2(%s,%s)'%(self.x,self.y)
	#if
	def __eq__(self, other):
		if type(other) == v2:
			if self.x == other.x and self.y == other.y:
				return True
			else:
				return False
	def __ne__(self, other):
		if type(other) == v2:
			if self.x != other.x and self.y != other.y:
				return True
			else:
				return False
	#add
    	def __add__(self, other):
		if type(other) == v2:
			return v2(self.x+other.x,self.y+other.y)
	__radd__ = __add__
    	def __iadd__(self, other):
		if type(other) == v2:
			self.x += other.x
			self.y += other.y
	#sub
	def __sub__(self, other):
		if type(other) == v2:
			return v2(self.x-other.x,self.y-other.y)
	def __rsub__(self, other):
		if type(other) == v2:
			return v2(other.x-self.x,other.y-self.y)
    	def __isub__(self, other):
		if type(other) == v2:
			self.x -= other.x
			self.y -= other.y
	#mul
	def __mul__(self, other):
		if type(other) == v2:
			return v2(self.x*other.x,self.y*other.y)
	__rmul__ = __mul__
	def __imul__(self, other):
		if type(other) == v2:
			self.x *= other.x
			self.y *= other.y
	#div
	def __div__(self, other):
		if type(other) == v2:
			return v2(self.x/other.x,self.y/other.y)
	def __rdiv__(self, other):
		if type(other) == v2:
			return v2(other.x/self.x,other.y/self.y)
	def __idiv__(self, other):
		if type(other) == v2:
			self.x /= other.x
			self.y /= other.y
	def __floordiv__(self, other):
		if type(other) == v2:
			return v2(self.x//other.x,self.y//other.y)
	def __rfloordiv__(self, other):
		if type(other) == v2:
			return v2((other.x//self.x),(other.y//self.y))
	def __ifloordiv__(self, other):
		if type(other) == v2:
			self.x = (self.x // other.x)
			self.y = (self.y // other.y)
	def __truediv__(self, other):
		if type(other) == v2:
			return v2(float(self.x/other.x),float(self.y/other.y))
	def __rtruediv__(self, other):
		if type(other) == v2:
			return v2(float(other.x/self.x),float(other.y/self.y))
	def __itruediv__(self, other):
		if type(other) == v2:
			self.x = float(self.x / other.x)
			self.y = float(self.y / other.y)
	#mod
	def __mod__(self, other):
		if type(other) == v2:
			return v2(self.x%other.x,self.y%other.y)
	def __rmod__(self, other):
		if type(other) == v2:
			return v2(other.x%self.x,other.y%self.y)
	#pow
	def __pow__(self, other):
		if type(other) == v2:
			return v2(self.x**other.x,self.y**other.y)
	def __rpow__(self, other):
		if type(other) == v2:
			return v2(other.x**self.x,other.y**self.y)
	#uno
	def __neg__(self):
		return v2(-abs(self.x),-abs(self.y))
	def __pos__(self):
		return v2(abs(self.x),abs(self.y))
	def __abs__(self):
		return v2(abs(self.x),abs(self.y))
	def __invert__(self):
		return v2(-self.x,-self.y)
	#type
	def __complex__(self):
		return v2(complex(self.x),complex(self.y))
	def __int__(self):
		return v2(int(self.x),int(self.y))
	def __long__(self):
		return v2(long(self.x),long(self.y))
	def __float__(self):
		return v2(float(self.x),float(self.y))
	#some funk
	def get_tuple(self):
		return (self.x,self.y)
	def get_list(self):
		return [self.x,self.y]

#-------------------------------------------------------feature
def perpixelspritecollid(pos,other):
	(px,py) = pos
	px , py = px - other.rect.x, py- other.rect.y
	pos = (px,py)
	if (px or py) < 0 or px > other.rect.w or py > other.rect.h:
		return False
	if other.image.get_at(pos) == other.image.get_colorkey():
		return False
	return True

def newpixelspritecollid(pos,other):	#this one use v2 class
	p = v2(pos) - v2(other.rect.x,other.rect.y)
	if (p.x or p.y) < 0 or p.x > other.rect.w or p.y > other.rect.h:
		return False
	if other.image.get_at(p.get_tuple()) == other.image.get_colorkey():
		return False
	return True
	
def poxel2coord(poxel,mod_rad=0.0):
	(radian,radius) = poxel
	return (math.sin(radian+mod_rad)*radius, math.cos(radian+mod_rad)*radius)
	
def poxel2pixel(poxel,mod_rad=0.0):
	(radian,radius) = poxel
	return (int(math.sin(radian+mod_rad)*radius), int(math.cos(radian+mod_rad)*radius))
	
def pixel2poxel(pos):
	(x,y) = pos
	return (int(math.atan2(x,y)) , int(math.hypot(x,y)))
#------------------------------------------------------------drawing method
def ditter_mask(image,rect,color):
	for y in range(rect.h):
		for x in range(rect.w):
			if x % 2 == y % 2:
				image.set_at((x,y),color)
#========================================================================================
#========================================================================================
#========================================================================================
#========================================================================================
class spring:
	def __init__(self,obj1,obj2,push,pull,tension):
		self.obj1 = obj1
		self.obj2 = obj2
		self.push = push
		self.pull = pull
		self.tension = tension

	def do_something(self):
		pass

class mole:
	def __init__(self,x,y,mass,size):
		self.x, self.y = x,y
		self.mass, self.size = mass, size
		self.spring_list = []

		self.force = 0.0
		self.radian = 0.0

	def do_something(self):
		pass


#========================================================================================
#========================================================================================
#========================================================================================
#========================================================================================
if __name__ == "__main__":
	pygame.init()
	pygame.display.set_caption("Martin")
	pygame.mouse.set_visible(1)
	pygame.event.set_blocked(None)
	pygame.event.set_allowed(QUIT)
	clock = pygame.time.Clock()
	screen = pygame.display.set_mode((300, 300))
	offscr = screen.get_rect()
	end = False
	paused = True
	mice = mice()
#-------------------------------------------------
	while not pygame.event.peek(QUIT):
		pygame.event.clear()
		clock.tick(60)
		pygame.display.flip()
		mice.update()
	#======================================================
		screen.fill(red)
		

	
