begin process at 2010 07 29 16:00:35
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

Graphique

 > JEU DE LA VIE AVEC TKINTER

JEU DE LA VIE AVEC TKINTER


 Information sur la source

Note :
6 / 10 - par 1 personne
6,00 / 10

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10
Catégorie :Graphique Classé sous :jeu, vie, sandaly, graphique, dia100daly Niveau :Initié Date de création :04/02/2009 Vu / téléchargé :2 821 / 171

Auteur : dia100daly

Ecrire un message privé
Commentaire sur cette source (1)
Ajouter un commentaire et/ou une note

 Description

Comme promis dans mon premier code source voici . le jeu de la vie en mode graphique . Pour plus de details voir le jeu de la vie il ya des explication du principe.

Source

  • from Tkinter import *
  • import time
  • def demo():
  • modif(matrice,matrice_of_len,birth,death)
  • for i in range(0,540,30):
  • for j in range(0,540,30):
  • if(matrice[j/30][i/30]== '0' ):
  • can.create_oval(i,j,i+30,j+30,fill='red')
  • else:
  • can.create_oval(i,j,i+30,j+30,fill='blue')
  • fen.after(1,demo)
  • def aux(matrice):
  • tmp =[]
  • for i in range(len(matrice)):
  • tmp1 =[]
  • for j in range(len(matrice[0])):
  • tmp1.append(oqp(matrice, i, j))
  • tmp.append(tmp1)
  • return tmp
  • def birth_or_death(matrice, matrice_of_len,b_or_d,test):
  • c ='0'
  • if(test):
  • c = '1'
  • for i in range(len(matrice)):
  • for j in range(len(matrice[0])):
  • if(matrice[i][j] !=c):
  • matrice[i][j] = b_or_d[matrice_of_len[i][j]]
  • def init_mat(fic):
  • matrice = []
  • file = open(fic,'r')
  • line = file.readlines()
  • for i in range(len(line)):
  • matrice.append(line[i].split())
  • file.close();
  • return matrice
  • def oqp(matrice,lig, col):
  • compt = 0
  • ligne =len(matrice)
  • colonne = len(matrice[0]) -1
  • if(lig < ligne -1):
  • if(col != 0):
  • if(int(matrice[lig + 1][col -1]) == 1):
  • compt = compt + 1
  • if(int(matrice[lig + 1][col]) == 1):
  • compt = compt + 1
  • if(col != colonne):
  • if(int(matrice[lig + 1][col +1]) == 1):
  • compt = compt + 1
  • if(col != colonne ):
  • if(int(matrice[lig ][col +1]) == 1):
  • compt = compt + 1
  • if(col != 0):
  • if(int(matrice[lig ][col - 1]) == 1):
  • compt = compt + 1
  • if(lig != 0):
  • if(col != 0):
  • if(int(matrice[lig-1][col-1]) == 1):
  • compt = compt + 1
  • if(col != colonne):
  • if(int(matrice[lig - 1][col+1]) == 1):
  • compt = compt + 1
  • if(int(matrice[lig - 1][col]) == 1):
  • compt = compt + 1
  • return compt
  • def modif(matrice,matrice_of_len,birth,death):
  • matrice_of_len = aux(matrice)
  • birth_or_death(matrice,matrice_of_len,birth,True)
  • birth_or_death(matrice,matrice_of_len,death,False)
  • # programme principal
  • file = "life.txt" #fichier de matrice
  • birth= '010101010101010' # regle de naissance
  • death= '110001100110001' #regle de deces
  • matrice = init_mat(file)
  • matrice_of_len = []
  • fen =Tk()
  • can = Canvas(fen,bg='black', height=550,width=550)
  • can.grid(row=0,column=0)
  • demo()
  • fen.mainloop()
from Tkinter import *

import time

def demo():
   modif(matrice,matrice_of_len,birth,death)
   for i in range(0,540,30):
      for j in range(0,540,30):
         if(matrice[j/30][i/30]== '0' ):
            can.create_oval(i,j,i+30,j+30,fill='red')
         else:
            can.create_oval(i,j,i+30,j+30,fill='blue')
   fen.after(1,demo)

def aux(matrice):
    tmp =[]
    for i in range(len(matrice)):
        tmp1 =[]
        for j in range(len(matrice[0])):
            tmp1.append(oqp(matrice, i, j))
        tmp.append(tmp1)
    return tmp

def birth_or_death(matrice, matrice_of_len,b_or_d,test):
   c ='0'
   if(test):
      c = '1'
   for i in range(len(matrice)):
      for j in range(len(matrice[0])):
         if(matrice[i][j] !=c):
            matrice[i][j] = b_or_d[matrice_of_len[i][j]]
      
def init_mat(fic):
   matrice = []
   file = open(fic,'r')
   line = file.readlines()
   for i in range(len(line)):
      matrice.append(line[i].split())
   file.close();
   return  matrice

def oqp(matrice,lig, col):
   compt = 0
   ligne =len(matrice)
   colonne = len(matrice[0]) -1
   if(lig < ligne -1):
      if(col != 0):
         if(int(matrice[lig + 1][col -1]) == 1):
            compt = compt + 1
      if(int(matrice[lig + 1][col]) == 1):
         compt = compt + 1
      if(col  != colonne):
         if(int(matrice[lig + 1][col +1]) == 1):
            compt = compt + 1
   if(col  != colonne ):
      if(int(matrice[lig ][col +1]) == 1):
         compt = compt + 1
   if(col != 0):
      if(int(matrice[lig ][col - 1]) == 1):
         compt = compt + 1
   if(lig != 0):
      if(col != 0):
         if(int(matrice[lig-1][col-1]) == 1):
            compt = compt + 1
      if(col  != colonne):
         if(int(matrice[lig - 1][col+1]) == 1):
            compt = compt + 1
      if(int(matrice[lig - 1][col]) == 1):
         compt = compt + 1
   return compt

def modif(matrice,matrice_of_len,birth,death):
   matrice_of_len = aux(matrice)
   birth_or_death(matrice,matrice_of_len,birth,True)
   birth_or_death(matrice,matrice_of_len,death,False)
   

# programme principal
file = "life.txt" #fichier de matrice 
birth= '010101010101010' # regle de naissance
death= '110001100110001' #regle de deces
matrice = init_mat(file)
matrice_of_len = []
fen =Tk()
can = Canvas(fen,bg='black', height=550,width=550)
can.grid(row=0,column=0)
demo()
fen.mainloop()

 Conclusion

Merci de laisser des commentaire
Bientot une aide aide pour le sudoku

 Fichier Zip

Les Membres Club peuvent télécharger directement un fichier contenu dans le zip sans télécharger le zip en entier !

Télécharger le zip


 Sources du même auteur

Source avec Zip JEU DE LA VIE

 Sources de la même categorie

Source avec Zip Source avec une capture PYGTK : CODES ET EXPLICATIONS POUR DÉBUTER par loloof64
TK_WATCH :HORLOGE GRAPHIQUE par afranck64
Source avec une capture DESSIN DE DÉS À ÉCHELLE VARIABLE SUR CANVAS par calogerogigante
BOITE DE CONNEXION USER/PASSWORD POUR PYTHON:TK_LOGIN par afranck64
Source avec Zip Source avec une capture CALCUL DE RÉSISTANCES par amaury74

 Sources en rapport avec celle ci

Source avec Zip Source avec une capture CASSE BRIQUE par elnabo
Source avec Zip Source avec une capture LE CALCULATOR DE RAYGOLD VERSION 3.1 par raygold
TK_WATCH :HORLOGE GRAPHIQUE par afranck64
Source avec Zip Source avec une capture JEU DU SERPENT ////\\\\ SNAKE par elnabo
Source avec Zip JEU DE LA VIE par dia100daly

Commentaires et avis

Commentaire de Julien39 le 07/03/2009 12:34:04 6/10

comme pour le premier, aucun commentaire

 Ajouter un commentaire


Discussions en rapport avec ce code source dans le forum

jeu de la vie [ par dia100daly ] je veux poster un code. Mais j'aimerai savoir si c'etait vraiment la peine car c'est la première fois. Pour plus de détail voir sur Wikipédia ( jeu de codage Windows jeu de caractères [ par creaduff ] Bonjour,Avant tout, précisons que je ne suis pas un aigle en Python ! Voici mon problème:J'ai écrit une petit programme permettant d'accéder à ma boit Python et Octave"matlab" [ par soufianovich ] Bonjour, je suis stagiaire dans une entreprise, jai fait un code octave ou"matlab" c'est la meme chose qui traite mes données. Maintenant je suis en t Python et octave [ par soufianovich ] Bonjour, je suis stagiaire dans une entreprise, jai fait un code octave ou"matlab" c'est la meme chose qui traite mes données. Maintenant je suis en t Réalisation d'un plus ou moins sur Tkinter [ par kuritsu ] Bonsoir tout le monde, et je vous souhaite la bonne année à tous par la même occasion. Je viens de me mettre à la programmation sous Python, et j'avo créer une simulation d'un jeu de cartes [ par jimux06 ] # simulation d'un tirage de cartes # dans la version 3.1.x # afficher la date du jour (jj-mm-aaaa) et l'heure (hh:mm:ss), avant chaque jeu # utiliser Librairie graphique vectoriel [ par DoudouBidou ] Bonjour, j'ai depuis quelques jour un projet en t&#234;te, celui de r&#233;aliser un logiciel de saisi de sch&#233;ma &#233;lectrique en python. Appel d'une fonction [ par Thomeux ] Bonjour,Je débute en python.J'essais de structurer mon Programme de la manière suivante         :Un fichier bibliothèque fonction,          :Un Fichi modification de jeu morpion en python [ par apprenti2008 ] salut a tous ! SVP j'ai vraiment besoin d'aide , je suis en première année MASS , le prof nous a demander de créer un jeu morpion en python , le princ Probleme de conception [ par JoeNamat ] Bonjour a vous,Je ne suis pas un tres bon programmeur et j'ai programme une interface graphique en python avec PyGTK. Cette interface graphique interr


Nos sponsors


Sondage...

Comparez les prix

CalendriCode

Juillet 2010
LMMJVSD
   1234
567891011
12131415161718
19202122232425
262728293031 

Consulter la suite du CalendriCode

 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 0,655 sec (3)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales