Le nouveau Super Mario Bros pour la gamme des fx9860g https://www.planet-casio.com/Fr/forums/topic15994-1-[addin]-SuperCasioBros-v0.1.html
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

124 lines
2.8 KiB

import os
import tempfile
import subprocess
from PIL import Image
# Palette de couleurs
pierre = (0, 0, 0)
brique = (255, 0, 0)
empty = (255, 255, 255)
piece = (203, 255, 0)
boite_piece = (255, 153, 0)
boite_champi = (204, 0, 255)
brique_piece = (101, 127, 0)
beton = (84, 84, 84)
tuyauMilieu = (0, 255, 102)
tuyau_bout = (50, 255, 0)
drapeau = (0, 255, 216)
goomba = (127, 76, 0)
koopa_vert = (25, 127, 0)
koopa_rouge = (127, 0, 0)
mario_start = (108, 81, 47)
nuage = (127, 127, 127)
arbre_tronc = (74,35,18)
arbre_feuilles = (0,86,0)
plante = (102,0,127)
def color_compare(color1, color2):
if color1[0] == color2[0] and color1[1] == color2[1] and color1[2] == color2[2]:
return 1
else:
return 0
def write_char(val):
a = val%256
return a.to_bytes(1,'little')
#if a>128:
# a -= 256
# return chr(a)
# return '%c' % int(val%256)
# Load image
filename = input("File name ?\n> ")
img = Image.open(filename)
print("Converting..." + filename + ", size =", img.size)
#rough binary
# code = str().encode('latin1')
code = write_char(int(img.size[0]))
code += write_char(int(img.size[1]))
pixels = img.load()
for x in range(0,img.size[0]):
for i in range(0, img.size[1]):
y=img.size[1]-i-1
if color_compare(pixels[x,y],empty):
code += write_char(0)
elif color_compare(pixels[x,y], pierre):
code += write_char(1)
elif color_compare(pixels[x,y], piece):
code += write_char(2)
elif color_compare(pixels[x,y], brique):
code += write_char(3)
elif color_compare(pixels[x,y],brique_piece):
code += write_char(4)
elif color_compare(pixels[x,y],boite_piece):
code += write_char(5)
elif color_compare(pixels[x,y],boite_champi):
code += write_char(6)
elif color_compare(pixels[x,y],beton):
code += write_char(7)
elif color_compare(pixels[x,y],tuyau_bout):
code += write_char(8)
elif color_compare(pixels[x,y], tuyauMilieu):
code += write_char(9)
elif color_compare(pixels[x,y], drapeau):
code += write_char(10)
elif color_compare(pixels[x,y], goomba):
code += write_char(11)
elif color_compare(pixels[x,y], koopa_vert):
code += write_char(12)
elif color_compare(pixels[x,y], koopa_rouge):
code += write_char(13)
elif color_compare(pixels[x,y], mario_start):
code += write_char(14)
elif color_compare(pixels[x,y], nuage):
code += write_char(15)
elif color_compare(pixels[x,y], arbre_tronc):
code += write_char(16)
elif color_compare(pixels[x,y], arbre_feuilles):
code += write_char(17)
elif color_compare(pixels[x,y], plante):
code += write_char(18)
else:
code += write_char(0)
print("Warning: unknown type at", x, y, "with pixel color: ", pixels[x,y])
f = open("../assets-fx/bin/lvl_"+filename, 'wb')
f.write(code)
f.close()
print("Converted succesfully ! (", os.path.getsize("../assets-fx/bin/lvl_"+filename), "bytes )")