IPB

Bienvenue invité ( Connexion | Inscription )

 
Reply to this topicStart new topicStart Poll

En ligne · [ Standard ] · Linéaire+

> juste qqs sources en passant :

momo
post 21/08/2002 1:19
Message #1


lvl1 male rogue St=1 Dex=5 Int=17 Wi=5 Ch=0
****

Groupe : Modérateurs
Messages : 1,730
Inscrit le : 16/05/2002 23:00
Lieu : .gif
Membre no. 12



CODE
from Tkinter import *
import Image,ImageDraw,ImageTk,sys

def Dwords(files):
temp1=ord(files.read(1))*256**0
temp2=ord(files.read(1))*256**1
temp3=ord(files.read(1))*256**2
temp4=ord(files.read(1))*256**3
return temp1+temp2+temp3+temp4

def Words(files):
temp3=ord(files.read(1))*256**0
temp4=ord(files.read(1))*256**1
return temp3+temp4


def Read_Header_Bmp(bmpfile):
text=bmpfile.read(2)
print
print bmpfile
print "========BMP-Header Information========"
if text=="BM":
print "first Dword 'BM' : ok"
else:
print text
bfSize=Dwords(bmpfile)
print "File size in Bytes:", bfSize
reserv1=Words(bmpfile)
print "Must be zero:",
if reserv1==0:
print "ok"
else:
print "error"
reserv2=Words(bmpfile)
print "Must be zero:",
if reserv2==0:
print "ok"
else:
print "error"

offbits=Dwords(bmpfile)
print "Image data offset:",offbits


info=Words(bmpfile)
print "Info header=",info,"bytes"
# not Dwords but Longs ... :/
temp1=ord(bmpfile.read(1))*256**2
temp2=ord(bmpfile.read(1))*256**3
temp3=ord(bmpfile.read(1))*256**0
temp4=ord(bmpfile.read(1))*256**1
width=temp1+temp2+temp3+temp4
print "Width=",width
temp1=ord(bmpfile.read(1))*256**2
temp2=ord(bmpfile.read(1))*256**3
temp3=ord(bmpfile.read(1))*256**0
temp4=ord(bmpfile.read(1))*256**1
height=temp1+temp2+temp3+temp4
print "Height=",height
temp1=ord(bmpfile.read(1))*256**2
temp2=ord(bmpfile.read(1))*256**3
temp3=ord(bmpfile.read(1))*256**0
temp4=ord(bmpfile.read(1))*256**1
planes=temp1+temp2+temp3+temp4
print "Must be '1':",
if planes==1:
print "ok"
else:
print "error"
bitcount=Words(bmpfile)
print "Bits per pixel:",bitcount
compression=Dwords(bmpfile)
print "Compression type:",compression
sizeimage=Dwords(bmpfile)
print "Image size in Bytes:",sizeimage
xpxelpermeter=Dwords(bmpfile)
print "Pixels per meter (X):",xpxelpermeter
ypxelpermeter=Dwords(bmpfile)
print "Pixels per meter (Y):",ypxelpermeter
colorused=Dwords(bmpfile)
if colorused==0:
print "All colors used"
else:
print colorused,"colors used"
colorimportant=Dwords(bmpfile)
print colorimportant,"important color(s)"
print "============End of header ============"
return [width,height,bitcount,offbits,sizeimage]

def Bmp_read_24(offbits,bmpfile,size):
data=[]
if bmpfile.tell()<>offbits:
print bmpfile.tell()
bmpfile.seek(offbits)
for count in range(size/3):
test=bmpfile.read(3)
blue=ord(test[0])
green=ord(test[1])
red=ord(test[2])
colors=[red,green,blue]
data.append(colors)
return data


#file=open("Test.dat","rb")
file=open("Sparclin.bmp","rb")
bmpinfo=Read_Header_Bmp(file)
if bmpinfo[2]==24:
print "launch 24 bits decoding routine"
bmpdata=Bmp_read_24(bmpinfo[3],file,bmpinfo[4])
else:
print "%d bit(s) not supported yet"%(bmpinfo[2])
sys.exit()

file.close()
print"file closed"
root=Tk()
root.title("momo's dumb bmp reader")
if (bmpinfo[4]/(3*bmpinfo[1]))<>bmpinfo[0]:
print "size error",
bmpinfo[0]=bmpinfo[4]/(3*bmpinfo[1])
print "Width=%d"%(bmpinfo[0])
bitmap=Image.new("RGB",[bmpinfo[0],bmpinfo[1]])
print "mode:",bitmap.mode,"taille:",bitmap.size
bit=ImageDraw.Draw(bitmap)
count,count1=0,bmpinfo[1]
if (len(bmpdata)*3)<>bmpinfo[4]:
print "data size error %d/%d" % (len(bmpdata)*3,bmpinfo[4])
else:
print "data size ok"

for counter in range(len(bmpdata)):
color=(bmpdata[counter][0],bmpdata[counter][1],bmpdata[counter][2])
bit.point([count,count1],fill=color)
count+=1
if count>=bmpinfo[0]:
count=0
count1-=1


out=ImageTk.PhotoImage(bitmap)
lab=Label(image=out)
lab.pack()
print "Done"
root.mainloop()

bon terminé avec ce truc bmp : prise de tête à la longue ...
CODE
# attempt to create a chip8 interpreter
def cpu8(instr,regs,I,PC):
opcode=instr/4096
instr=instr-4096*opcode
if opcode==0:
PC=opcode0(instr,PC)
elif opcode==1:
print "%X: jump %X"%(PC,instr)
PC=instr
elif opcode==2:
stack.append(PC)
print "%X: jsr %X"%(PC,instr)
PC=instr
elif opcode==3:
register=int(instr/256)
value=instr-256*register
print "%X: skeq V%X,%X"%(PC,register,value)
if regs[register]==value:
PC+=4
else:
PC+=2
elif opcode==4:
register=int(instr/256)
value=instr-256*register
print "%X: skne v%X,%X"%(PC,register,value)
if regs[register]==value:
PC+=2
else:
PC+=4
elif opcode==5:
register1=int(instr/256)
register2=int((instr-256*register1)/16)
print "%X: skeq V%X,V%X"%(PC,register1,register2)
if regs[register1]==regs[register2]:
PC+=4
else:
PC+=2
elif opcode==6:
register=int(instr/256)
value=instr-256*register
regs[register]=value
print "%X: mov V%X,%X"%(PC,register,value)
PC+=2
elif opcode==7:
register=int(instr/256)
value=instr-256*register
regs[register]+=value
print "%X: add V%X,%X"%(PC,register,value)
PC+=2
elif opcode==8:
register1=int(instr/256)
register2=int((instr-256*register1)/16)
value=instr-256*register1-16*register2
opcode8(register1,register2,value,PC)
PC+=2
elif opcode==9:
print "skne"
elif opcode==0xA:
print "mvi "
elif opcode==0xB:
print "jmi"
elif opcode==0xC:
print "rand v"
elif opcode==0xD:
print "sprite r"
elif opcode==0xE:
print "opcode E : translating"
elif opcode==0xF:
print "opcode F : translating"
return PC
def opcode0(value,PC):
if value==0xE0:
print "%X: cls"%(PC)
PC+=2
elif value==0xEE:
PC=stack.pop()
print "%X: rts"%(PC)
else:
print "NoOp"
PC=0
return PC

def opcode8(register1,register2,value,PC):
if value==1:
regs[register1]=regs[register2]
print "%X: mov V%X,V%X"%(PC,register1,register2)
elif value==2:
regs[register1]=regs[register1]|regs[register2]
print "%X: or V%X,V%X"%(PC,register1,register2)
elif value==3:
regs[register1]=regs[register1]&regs[register2]
print "%X: and V%X,V%X"%(PC,register1,register2)
elif value==4:
regs[register1]=regs[register1]^regs[register2]
print "%X xor V%X,V%X"%(PC,register1,register2)
elif value==5:
regs[register1]+=regs[register2]
if regs[register1]>0xFF:
regs[0xF]=1
regs[register1]=regs[register1]%0xFF
print "%X add V%X,V%X"%(PC,register1,register2)
elif value==7:
regs[register1]-=regs[register2]
if regs[register1]<0:
regs[register1]+=0xFF
regs[0xF]=1
print "%X sub V%X,V%X"%(PC,register1,register2)
elif value==6:
regs[0xF]=regs[register1]&1
regs[register1]=regs[register1]>>1
print "%X: shr V%X"%(PC,register1)
elif value==0xE:
regs[0xF]=regs[register1]&128
regs[register1]=regs[register1]<<1
print "%X: shl V%X"%(PC,register1)


regs=[0]*16
stack=[]
PC=0x200
I=0
print ""
# list containing a instruction list ... no real memory map
intr=[0]*0x200
intr.append(0x610F)
intr.append(0)
intr.append(0x7001)
intr.append(0)
intr.append(0x00E0)
intr.append(0)
intr.append(0x5010)
intr.append(0)
intr.append(0x1202)
intr.append(0)
intr.append(0x810E)
intr.append(0)
intr.append(0x8006)
intr.append(0)
intr.append(0)
while PC<>0:
PC=cpu8(intr[PC],regs,I,PC)

print "registers:", regs
print "stack:",stack
print "0x%X"%PC

loin d'être terminé .. mais faut bien commencer par qq part .. smile.gif


--------------------
Natural evolution insists that we are apes; artificial evolution insists that we are machines with an attitude.
Kevin Kelly - Out of control
User is offlineProfile CardPM
Go to the top of the page
+Quote Post
PoP
post 21/08/2002 8:04
Message #2


ragondin interstellaire
*****

Groupe : Membres
Messages : 3,059
Inscrit le : 16/05/2002 23:00
Lieu : DTC, au fond à gauche
Membre no. 8



c'est...comment dire....vert?


--------------------
PoP
"Consommez malin, consommez du ragondin!"
user posted image
User is offlineProfile CardPM
Go to the top of the page
+Quote Post
momo
post 21/08/2002 12:55
Message #3


lvl1 male rogue St=1 Dex=5 Int=17 Wi=5 Ch=0
****

Groupe : Modérateurs
Messages : 1,730
Inscrit le : 16/05/2002 23:00
Lieu : .gif
Membre no. 12



pas ma faute si la coloration syntaxique n'existe pas sous ce forum ... smile.gif


--------------------
Natural evolution insists that we are apes; artificial evolution insists that we are machines with an attitude.
Kevin Kelly - Out of control
User is offlineProfile CardPM
Go to the top of the page
+Quote Post
Gfx
post 21/08/2002 13:31
Message #4


Goule
****

Groupe : Membres
Messages : 980
Inscrit le : 01/08/2002 23:00
Lieu : Lyon
Membre no. 106



Pour la coloration, je peux arranger ça :-)))
Sinon pour ton interpréteur, je te propose une méthode plus sympa :
CODE

def opcode1(self, params):
pass
def opcode2(self, params):
pass

opcodesMap = { 1 : opcode1, 2 : opcode2 }

# ...
### on connaît l'opcode ici
opcodesMap[opcode](params)



--------------------
User is offlineProfile CardPM
Go to the top of the page
+Quote Post
momo
post 21/08/2002 15:34
Message #5


lvl1 male rogue St=1 Dex=5 Int=17 Wi=5 Ch=0
****

Groupe : Modérateurs
Messages : 1,730
Inscrit le : 16/05/2002 23:00
Lieu : .gif
Membre no. 12



...
on verra ... smile.gif
m'enfin pour du chip8 ... biggrin.gif


--------------------
Natural evolution insists that we are apes; artificial evolution insists that we are machines with an attitude.
Kevin Kelly - Out of control
User is offlineProfile CardPM
Go to the top of the page
+Quote Post
PoP
post 21/08/2002 15:42
Message #6


ragondin interstellaire
*****

Groupe : Membres
Messages : 3,059
Inscrit le : 16/05/2002 23:00
Lieu : DTC, au fond à gauche
Membre no. 8



blink.gif ça veut dire qu'il y en a qui on véritablement LU ça? blink.gif


--------------------
PoP
"Consommez malin, consommez du ragondin!"
user posted image
User is offlineProfile CardPM
Go to the top of the page
+Quote Post
Gfx
post 21/08/2002 18:51
Message #7


Goule
****

Groupe : Membres
Messages : 980
Inscrit le : 01/08/2002 23:00
Lieu : Lyon
Membre no. 106



Voilà une calculatrice RPN qui utilise le principe que j'ai décrit plus haut :
(bon ok ça a niqué l'indentation, mais au moins c'est en couleurs !!)
P.S : j'ai le même source, mais avec des classes

#! /usr/bin/env python


--------------------
User is offlineProfile CardPM
Go to the top of the page
+Quote Post
momo
post 21/08/2002 20:14
Message #8


lvl1 male rogue St=1 Dex=5 Int=17 Wi=5 Ch=0
****

Groupe : Modérateurs
Messages : 1,730
Inscrit le : 16/05/2002 23:00
Lieu : .gif
Membre no. 12



Certes, c'est très clair .. mais ce n'est absolument pas ma maniere de coder ...
j'en ai chié des "barrieres" du java alors, si un prog me permet de coder +/- efficacement comme un porc , je n'hesites pas ! smile.gif
m'enfin l'interpréteur chip8 est juste une étape de compréhension des emus, histoire ( si ça marche ) de s'attaquer à un interpréteur Z-machine ensuite ...
( passeque Qnx est bien gentil mais y a pas énorme en jeux interessant smile.gif
et en plus le package python de ce dernier est sans support d'une qqconque interface graphique ... )


--------------------
Natural evolution insists that we are apes; artificial evolution insists that we are machines with an attitude.
Kevin Kelly - Out of control
User is offlineProfile CardPM
Go to the top of the page
+Quote Post
Gfx
post 22/08/2002 0:23
Message #9


Goule
****

Groupe : Membres
Messages : 980
Inscrit le : 01/08/2002 23:00
Lieu : Lyon
Membre no. 106



Si tu veux coder comme un porc : Perl (mais c du code porc classe et bien smile.gif)) ou VB (là on code vraiment comme un porc smile.gif)). Python c'est élégant (et Perl peut aussi l'être smile.gif)


--------------------
User is offlineProfile CardPM
Go to the top of the page
+Quote Post
PoP
post 22/08/2002 8:34
Message #10


ragondin interstellaire
*****

Groupe : Membres
Messages : 3,059
Inscrit le : 16/05/2002 23:00
Lieu : DTC, au fond à gauche
Membre no. 8



ah ouais, VB pour coder comme un porc, c'est le panard absolu! Code imbitable, règles de programmation incompréhensibles...
Mais si tu veux vraiment coder comme un porc, ben y'a toujours ça:
PORK!


--------------------
PoP
"Consommez malin, consommez du ragondin!"
user posted image
User is offlineProfile CardPM
Go to the top of the page
+Quote Post
momo
post 22/08/2002 8:49
Message #11


lvl1 male rogue St=1 Dex=5 Int=17 Wi=5 Ch=0
****

Groupe : Modérateurs
Messages : 1,730
Inscrit le : 16/05/2002 23:00
Lieu : .gif
Membre no. 12



VB est qunad même un peu trop porcin à mon gout smile.gif
m'enfin j'ai déjà tenté de programmer un formatteur en qb ... et serieusement ... je prefererais me jeter par la fenêtre plutôt que de m'attaquer au debuggage de ce dernier .. biggrin.gif


--------------------
Natural evolution insists that we are apes; artificial evolution insists that we are machines with an attitude.
Kevin Kelly - Out of control
User is offlineProfile CardPM
Go to the top of the page
+Quote Post
Gfx
post 22/08/2002 14:42
Message #12


Goule
****

Groupe : Membres
Messages : 980
Inscrit le : 01/08/2002 23:00
Lieu : Lyon
Membre no. 106



Le code source en couleurs ci-dessus a été pondu par un soft que j'ai écrit en VB. Un moteur de coloration de sources, qui pond du RTF, du PFD, de l'HTML ou de l'HTML/CSS. Il peut colorer virtuellement n'importe quel langage, il suffit de décrire la syntaxe du langage dans un fichier XML. Et je peux vous dire qu'en VB, c'est bien gore à écrire un tel outil smile.gif)

http://jext.free.fr/syxigh-setup.exe avec les sources


--------------------
User is offlineProfile CardPM
Go to the top of the page
+Quote Post
momo
post 22/08/2002 22:17
Message #13


lvl1 male rogue St=1 Dex=5 Int=17 Wi=5 Ch=0
****

Groupe : Modérateurs
Messages : 1,730
Inscrit le : 16/05/2002 23:00
Lieu : .gif
Membre no. 12



m'enfin .. le basic n'est pas un mauvais langage, il est seulement trop simple ... smile.gif
bon, du coup, pour mon chip8, il faut que je me fasse un "bios" : une fonte en 4*5 bits ... ( A-F, 1-9 )
bon: notepad et un prog ...
au fait il existe un moyen universel d'obtenir une entrée clavier plutôt que de jongler entre curses et msvcrt selon l'architecture ?


--------------------
Natural evolution insists that we are apes; artificial evolution insists that we are machines with an attitude.
Kevin Kelly - Out of control
User is offlineProfile CardPM
Go to the top of the page
+Quote Post
Gfx
post 23/08/2002 1:24
Message #14


Goule
****

Groupe : Membres
Messages : 980
Inscrit le : 01/08/2002 23:00
Lieu : Lyon
Membre no. 106



Ben curses a sûrement été porté sous Windows. Sinon en Python dans le module sys tu as peut être de quoi lire le flux clavier.


--------------------
User is offlineProfile CardPM
Go to the top of the page
+Quote Post
momo
post 23/08/2002 10:18
Message #15


lvl1 male rogue St=1 Dex=5 Int=17 Wi=5 Ch=0
****

Groupe : Modérateurs
Messages : 1,730
Inscrit le : 16/05/2002 23:00
Lieu : .gif
Membre no. 12



bon va falloir que je trouves curses pour windows alors ...
m'enfin, je crois que je vais d'abors resourdre le pb des timers et des graphs ... ( et là curses serait bien pratique pour faire tout en console et m'eviter d'utiliser la Pil ou Tk qui n'existent pas sous mon qnx .. biggrin.gif )


--------------------
Natural evolution insists that we are apes; artificial evolution insists that we are machines with an attitude.
Kevin Kelly - Out of control
User is offlineProfile CardPM
Go to the top of the page
+Quote Post
momo
post 23/08/2002 14:05
Message #16


lvl1 male rogue St=1 Dex=5 Int=17 Wi=5 Ch=0
****

Groupe : Modérateurs
Messages : 1,730
Inscrit le : 16/05/2002 23:00
Lieu : .gif
Membre no. 12



curses n'existe pas pour windows : c'est bien ma veine .. :/
CODE

print (lambda Ru,Ro,Iu,Io,IM,Sx,Sy:reduce(lambda x,y:x+y,map(lambda y,Iu=Iu,Io=Io,Ru=Ru,Ro=Ro,Sy=Sy,L=lambdayc,Iu=Iu,Io=Io,Ru=Ru,Ro=Ro,i=IM,Sx=Sx,Sy
=Sy:reduce(lambda x,y:x+y,map(lambdax,xc=Ru,yc=yc,Ru=Ru,Ro=Ro,i=i,Sx=Sx,F=lambdaxc,yc,x,y,k,f=lambda xc,yc,x,y,k,f:(k<=0)or (x*x+y*y>=4.0) or 1+f(xc,yc,x*x-y*y+xc,2.0*x*y+yc,k-1,f):f(xc,yc,x,y,k,f):chr(64+F(Ru+x*(Ro-Ru)/Sx,yc,0,0,i)),range(Sx))):L(Iu+y*(Io-Iu)/Sy),range(Sy))))(-2.1, 0.7, -1.2, 1.2, 30, 80, 24)

trouvé dans une FAQ python smile.gif


--------------------
Natural evolution insists that we are apes; artificial evolution insists that we are machines with an attitude.
Kevin Kelly - Out of control
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

Reply to this topicTopic OptionsStart new topic
1 utilisateur(s) sur ce sujet (1 invité(s) et 0 utilisateur(s) anonyme(s))
0 membre(s) :
 

Version bas débit Nous sommes le : : 08/07/2025 12:08