Skip to content

Instantly share code, notes, and snippets.

@lelahx
Last active March 24, 2020 16:06
Show Gist options
  • Select an option

  • Save lelahx/b5619d819864c89af4d0433c4ed22d7a to your computer and use it in GitHub Desktop.

Select an option

Save lelahx/b5619d819864c89af4d0433c4ed22d7a to your computer and use it in GitHub Desktop.
test
from kandinsky import fill_rect, draw_string
from time import sleep
from ion import *
# Type de fichier: .pbm ou .pgm
# Largeur et longueur
fichier = "pbm 7 10"
# Chaine
chaine = "0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 1 0 0 0 1 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0"
# Ne modifiez le code que si
# vous savez ce que vous faites
fichier = fichier.split()
largeur = int(fichier [1])
hauteur = int(fichier [2])
chaine = chaine.replace("0", "255")
chaine = chaine.split()
zoom = 1
affichage_barre = True
# Detemination du type de fichier
if fichier[0] == "pbm":
nb_octet_nuance = 0.125
elif fichier[0] == "pgm":
nb_octet_nuance = 0.125
# Determination du poid et de
#l'unite adaptee a ce dernier
poid = (largeur*hauteur)*nb_octet_nuance
if poid <= 1:
poid = str(poid/1024) + " Ko "
else:
poid = str(poid) + " o "
# Dessin de l'arriere plan
fill_rect(0, 0, 320, 222, (192, 53, 53))
def image(zoom):
x = 0
y = 0
iterateur = 0
for k in range(len(chaine)):
p = int(chaine[iterateur])
iterateur += 1
fill_rect(x, y, zoom, zoom, (p, p, p))
x += zoom
if x == largeur*zoom:
x = 0
y += zoom
try:
while 1:
image(zoom)
if zoom == 0:
zoom = 1
elif (hauteur*zoom)/222 > 1:
zoom -= 1
else:
if keydown(KEY_BACK):
break
elif keydown(KEY_PLUS):
sleep(.00175)
zoom += 1
elif keydown(KEY_MINUS):
sleep(.00175)
zoom -= 1
elif keydown(KEY_OK) or keydown(KEY_TOOLBOX) or keydown(KEY_EXE):
sleep(.004)
if affichage_barre:
affichage_barre = False
elif affichage_barre == False:
affichage_barre = True
fill_rect(largeur*zoom, 0, 16, hauteur*zoom, (192, 53, 53))
fill_rect(0, hauteur*zoom - zoom, largeur*zoom + 8, 12, (192, 53, 53))
if affichage_barre:
draw_string(str("Taille:" + str(largeur) + "*" + str(hauteur) + " px " + "Zoom:" + str(zoom*100) + "% " + poid), 0, 205, (255, 255, 255), (192, 53, 53))
else:
fill_rect(0, 205, 320, 17, (192, 53, 53))
except KeyboardInterrupt:
print(31*"_" + "\n\n\n Merci d'utiliser IBM\n\n\n" + 31*"_")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment