import sys from pylab
import *
# On ouvre le fichier image
img = imread('C:\JVimages\perroquet.png')
# fonction qui convertit un nombre
entre 0 et 255 en hexadécimal
def
hexa(n): n1 = n//16
if n1 > 9:
t1 = chr(65 + (n1-10))
else:
t1 = str(n1)
n2 = n%16 if
n2 > 9: t2 = chr(65
+ (n2-10)) else:
t2 = str(n2)
return t1 +
t2
# fonction appelée sur
évènement clavier def
press(event):
if event.key ==
"x":
ax.affich = 3
fig, ax = plt.subplots()
fig.canvas.mpl_connect('key_press_event',
press)
# Variable de position
dans l'animation 1 / 2 / 3 (fin) ax.affich = 1
img2 = ones(img.shape)
# ray est le rayon des points
ray = 5
while ax.affich <
3: clf()
if ax.affich == 1:
xticks([]) yticks([])
imshow(img)
ax.affich = 2
else: imshow(img2)
xticks([]) yticks([])
for i
in range(ray, img.shape[0],2
* ray):
for j
in range(ray, img.shape[1],
2 * ray):
R = hexa(int(255*img[i,j,0]))
V = hexa(int(255*img[i,j,1]))
B = hexa(int(255*img[i,j,2]))
C = "#" + R + V + B
circle1 = Circle((j, i), radius = ray, fc = C)
fig, gca().add_patch(circle1)
ax.affich = 1 title("Appuyer
sur x pour fermer") pause(1)
close() show()
|