2015-09-10 19:24:26 +00:00
|
|
|
Classes:
|
|
|
|
|
2015-09-10 21:37:17 +00:00
|
|
|
|
2015-09-10 19:24:26 +00:00
|
|
|
/******************/
|
|
|
|
/** COLORIZATION **/
|
|
|
|
/******************/
|
|
|
|
Principe: colorer en modifiant les pixels (n&b) dans un ton (teinte) précisée
|
|
|
|
|
|
|
|
restitue la contraste mais recentre la couleur autour de la teinte
|
|
|
|
/************ ALGO **************/
|
|
|
|
i = 50 // incertitude
|
|
|
|
t = RGBPixel(1,2,3) // teinte souhaitée
|
|
|
|
p = RGBPixel(1,2,3) // couleur actuelle
|
|
|
|
|
|
|
|
/************ CODE **************/
|
|
|
|
def colorize(pixel, tint):
|
2015-09-10 21:37:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*****************/
|
|
|
|
/** SHAPIZATION **/
|
|
|
|
/*****************/
|
|
|
|
Principe: récupérer une forme par récurrence
|
|
|
|
|
|
|
|
Ajouter les 8 bits périphériques du pixel courant s'il existe et s'il a des couleurs pas trop éloignées des précédentes
|
|
|
|
/************ ALGO **************/
|
|
|
|
|
|
|
|
/************ CODE **************/
|
2015-09-11 07:25:44 +00:00
|
|
|
def getShape(self, coords, pixelMap, pixelList ): # return PixelList
|
|
|
|
# coords = [lastx, lasty, x, y]
|
|
|
|
width = len( pixelMap[0] )
|
|
|
|
height = len( pixelMap )
|
2015-09-10 21:37:17 +00:00
|
|
|
|
2015-09-11 07:25:44 +00:00
|
|
|
lastx = coords[0]
|
|
|
|
lasty = coords[1]
|
|
|
|
x = coords[2]
|
|
|
|
y = coords[3]
|
2015-09-10 21:37:17 +00:00
|
|
|
|
2015-09-11 07:25:44 +00:00
|
|
|
newCoords = [x, y]
|
|
|
|
|
|
|
|
|
|
|
|
# si le pixel existe (pas de dépassement de la pixelMap)
|
|
|
|
if x<width and x>=0 and y<height and y>=0:
|
2015-09-10 21:37:17 +00:00
|
|
|
|
|
|
|
already = False;
|
|
|
|
for i in range(0, len(pixelList)):
|
2015-09-11 07:25:44 +00:00
|
|
|
if pixelList[i] == pixelMap[y][x]:
|
2015-09-10 21:37:17 +00:00
|
|
|
already = True;
|
|
|
|
break
|
|
|
|
|
|
|
|
# si le pixel n'est pas déjà dans le tableau
|
|
|
|
if not already:
|
|
|
|
|
2015-09-11 07:25:44 +00:00
|
|
|
pixelMap[y][x].setRGB(255,0,0); # debug, tout rouge
|
|
|
|
|
|
|
|
pixelList.append( pixelMap[y][x] ) # ajout au tableau
|
2015-09-10 21:37:17 +00:00
|
|
|
|
2015-09-11 07:25:44 +00:00
|
|
|
self.getShape(newCoords+[x-1, y+1], pixelMap, pixelList) # 1
|
|
|
|
self.getShape(newCoords+[x, y+1], pixelMap, pixelList) # 2
|
|
|
|
self.getShape(newCoords+[x+1, y+1], pixelMap, pixelList) # 3
|
2015-09-10 21:37:17 +00:00
|
|
|
|
2015-09-11 07:25:44 +00:00
|
|
|
self.getShape(newCoords+[x-1, y], pixelMap, pixelList) # 4
|
2015-09-10 21:37:17 +00:00
|
|
|
# current pixel
|
2015-09-11 07:25:44 +00:00
|
|
|
self.getShape(newCoords+[x+1, y], pixelMap, pixelList) # 6
|
2015-09-10 21:37:17 +00:00
|
|
|
|
2015-09-11 07:25:44 +00:00
|
|
|
self.getShape(newCoords+[x-1, y-1], pixelMap, pixelList) # 7
|
|
|
|
self.getShape(newCoords+[x, y-1], pixelMap, pixelList) # 8
|
|
|
|
self.getShape(newCoords+[x+1, y-1], pixelMap, pixelList) # 9
|