Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/color.py
blob: b685e7895518d6fefa1e2fc3d38dde82737e6183 (plain)
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#!/usr/bin/env python

import os, pygame,math
import pygame.font, pygame.event, pygame.draw, string
from matriz import *
from pygame.locals import *
from math import sin, cos, pi, sqrt

class pyGrafic:
	def __init__(self, matriz):
		self.matriz=matriz
		self.filas=matriz.Filas
		self.columnas=matriz.Columnas		
	
	def init(self):
		#pygame.init()		
		self.screen = pygame.display.set_mode((600, 600),1)
		pygame.display.set_caption('Pintando Fracciones')
		self.cargaImgs()
		self.dibujar()	
		self.gridRect = pygame.Rect(0,0,50,45)
		self.palet()
		self.color=self.back
		self.colorName='white'
		
	def cargaImgs(self):
		self.purple= pygame.image.load("./purple.png").convert()
		self.purple.set_colorkey((0x80, 0x00, 0x80), RLEACCEL)
		
		self.brown= pygame.image.load("./brown.png").convert()
		self.brown.set_colorkey((0x80, 0x00, 0x80), RLEACCEL)
		
		self.pink= pygame.image.load("./pink.png").convert()
		self.pink.set_colorkey((0x80, 0x00, 0x80), RLEACCEL)
		
		self.orange= pygame.image.load("./orange.png").convert()
		self.orange.set_colorkey((0x80, 0x00, 0x80), RLEACCEL)
		
		self.gray= pygame.image.load("./gray.png").convert()
		self.gray.set_colorkey((0x80, 0x00, 0x80), RLEACCEL)
		
		self.yellow= pygame.image.load("./yellow.png").convert()
		self.yellow.set_colorkey((0x80, 0x00, 0x80), RLEACCEL)
		
		self.blue = pygame.image.load("./blue.png").convert()
		self.blue.set_colorkey((0x80, 0x00, 0x80), RLEACCEL)
	
		self.green = pygame.image.load("./green.png").convert()
		self.green.set_colorkey((0x80, 0x00, 0x80), RLEACCEL)

		self.red = pygame.image.load("./red.png").convert()
		self.red.set_colorkey((0x80, 0x00, 0x80), RLEACCEL)

		self.back = pygame.image.load("./back.png").convert()
		self.back.set_colorkey((0x80, 0x00, 0x80), RLEACCEL)

	def dibujar(self):
		self.mapimg = pygame.Surface((600,600),1)
		self.mapimg= self.mapimg.convert()
		self.mapimg.fill((0,0,0))
		
		for y in range(self.columnas):
			for x in range(self.filas):
				pixelX,pixelY=x*38,y*41
				self.mapimg.blit(self.back,(pixelX,pixelY))

	def setcolor(self, x, y):
		if(x > 561):
			if(y>=0 and y<41):
				self.color=self.red
				self.colorName='red'
			if(y>=41 and y<82):
				self.color=self.green
				self.colorName='green'
			if(y>=82 and y<123):
				self.color=self.blue
				self.colorName='blue'
			if(y>=123 and y<164):
				self.color=self.brown
				self.colorName='brown'
			if(y>=164 and y<205):
				self.color=self.purple
				self.colorName='purple'
			if(y>=205 and y<246):
				self.color=self.yellow
				self.colorName='yellow'
			if(y>=246 and y<287):
				self.color=self.pink
				self.colorName='pink'
			if(y>=287 and y<328):
				self.color=self.orange
				self.colorName='orange'
			if(y>=328 and y<349):
				self.color=self.gray
				self.colorName='gray'

		c=-1
		f=-1
		for fila in range(self.filas+1):
			if (x<=(fila*38)):
				f=fila-1				
				print "columna:" + str(f)
				break
		
		for columna in range(self.columnas+1):
			if (y<=(columna*41)):
				c=columna-1
				print "fila:" + str(c)
				break
		
		if c<self.filas and f<self.columnas and c>-1 and f>-1:
			self.matriz.Tabla[c][f].PintarCelda(self.colorName)
			print "Color:" + self.matriz.Tabla[c][f].ObtenerColor()

		c=c*41
		f=f*38
		if (c>-1 and f>-1):
			self.mapimg.blit(self.color,(f,c))
			pygame.display.flip()

	def palet (self):
		self.mapimg.blit(self.red,(562,0))
		self.mapimg.blit(self.green,(562,41))
		self.mapimg.blit(self.blue,(562,82))
		self.mapimg.blit(self.brown,(562,123))
		self.mapimg.blit(self.purple,(562,164))
		self.mapimg.blit(self.yellow,(562,205))
		self.mapimg.blit(self.pink,(562,246))
		self.mapimg.blit(self.orange,(562,287))
		self.mapimg.blit(self.gray,(562,328))

	def loop(self):    
		pygame.init()
		self.init()
		while 1:
			for event in pygame.event.get():
				if event.type == QUIT:
					return
				elif event.type == KEYDOWN:
					if event.key == K_ESCAPE:
						return
				elif event.type is MOUSEBUTTONDOWN:
					if event.button == 1:
						self.setcolor(event.pos[0],event.pos[1])

			self.screen.blit(self.mapimg, (0, 0))
			pygame.display.flip()

def main():

	pygame.init()
	matriz=CrearMatriz(60)
	#se inicia el controlador de pygame
	
	objeto=pyGrafic(matriz)
	objeto.loop()

#se llama a la funcion main cuando se ejecute el scrip
if __name__ == '__main__': main()