Update genForet.py

This commit is contained in:
LordOf20th 2019-02-08 17:12:51 +01:00
parent e280d11c8d
commit 8c80248242

View file

@ -8,6 +8,7 @@ import numpy as np
import random import random
import tkinter as tk import tkinter as tk
#Fonctions agissant sur la matrice
def genForet(n,p=0.25): def genForet(n,p=0.25):
foret=np.full(shape=(n,n), fill_value=0) foret=np.full(shape=(n,n), fill_value=0)
for i in range(0,foret.shape[0]): for i in range(0,foret.shape[0]):
@ -16,6 +17,17 @@ def genForet(n,p=0.25):
foret[i,j]=1 foret[i,j]=1
return foret return foret
def enflammer( n, p=0.25,x=-1,y=-1): #Fonction mettant le feu aléatoirement à une case
foret = genForet(n,p)
if x==-1:
x=random.randint(0, foret.shape[0])
if y==-1:
y=random.randint(0, foret.shape[1])
foret[x,y]=-1
return foret
#def propagation(n, *p, *x, *y):
def affichage(foret): def affichage(foret):
fenetre = tk.Tk() #Crée la fenêtre que l'on va modifier fenetre = tk.Tk() #Crée la fenêtre que l'on va modifier
@ -29,6 +41,8 @@ def affichage(foret):
for j in range(0,foret.shape[1]): for j in range(0,foret.shape[1]):
if foret[i,j]== 1: if foret[i,j]== 1:
canvas.create_rectangle((i+1)*10,(j+1)*10,(i+2)*10,(j+2)*10,fill='green',width=0) canvas.create_rectangle((i+1)*10,(j+1)*10,(i+2)*10,(j+2)*10,fill='green',width=0)
elif foret[i,j]==-1:
canvas.create_rectangle((i+1)*10,(j+1)*10,(i+2)*10,(j+2)*10,fill='red',width=0)
canvas.pack() canvas.pack()
bouton = tk.Button(fenetre, text="Quitter", command=fenetre.quit) bouton = tk.Button(fenetre, text="Quitter", command=fenetre.quit)
bouton.pack() bouton.pack()