Benutzer-Werkzeuge

Webseiten-Werkzeuge


Seitenleiste

ws1920:sechster_gruppentermin_09.01.2020

Was wir heute gemacht haben:

- Programm funktioniert!!! (zusammenführen von animation und gameoflife-code)

- Code aufgeräumt (Variablennamen geändert usw.; Aufteilung in Bibliothek und Ausführungsdatei)

- Colourmap geändert zu schwarz-weiß

- Achsen entfernt

- Wiki sortiert

- alle haben sich mit dem Code vertraut gemacht

Ziele für die nächste Woche:

- Interagierbar machen

- Anfangskonfigurationen ändern

- Stefans Tipps

- Git angucken?

- zeitschritte wieder integrieren (gerade ist es durch funcanimation so lang bis mensch das Fenster schließt)

Ausführungsdatei:

import GameOfLife as gol
import numpy as np
from matplotlib import pyplot as plt
from matplotlib import animation
import random



def animate (e):
    im.set_array(gol.Schritt())
    return im,

zeilen = int(input('Gib die Anzahl der Zeilen/Spalten ein: '))
spalten = zeilen

gol.Initialisiere(zeilen, spalten)

fig = plt.figure(figsize=(1920,1080), dpi=1, frameon=False)



#fig position ändern




plt.axis('off')

#figure(num=None, figsize=(8, 6), dpi=80, facecolor='w', edgecolor='k')
#plt.figure(figsize=(1,1)) 
im = plt.imshow(gol.zustand, animated=True, cmap=plt.get_cmap('gray'))
anim = animation.FuncAnimation(fig, animate, frames=200, interval=100)
#blit ist boese
#
# fuer mint gruen cmap=YlGn

plt.show()

Bibliothek(aufgeraeumt):

import random
import numpy as np
import matplotlib.pyplot as plt

# Größe der Matrix
# Die Matrix wird zufällig mit Nullen und Einsen gefüllt


def Tripleeinheitsmatrix(zeilen,spalten):
    tem = np.zeros ((zeilen,spalten))
    for i in range(0, zeilen):
        for j in range(0, spalten):
            if i==j:
                tem[(i,j)] = 1
            else:
                tem[(i,j)] = 0
                
    for i in range(0, zeilen):
        for j in range(0, spalten):
            if i==(j+1):
                tem[(i,j)] = 1
    for i in range(0, zeilen):
        for j in range(0, spalten):
            if j==(i+1):
                tem[(i,j)] = 1
                
    tem[0,tem.shape[1]-1] = 1
    tem[tem.shape[1]-1,0] = 1
           
    return tem
                

def BerechneAnzahlNachbarn(zustand):
    z = np.dot(tem, zustand)       
    k = np.dot(z, tem)
    anzahlNachbarn = k - zustand
        
    return anzahlNachbarn


def BerechneNeuenZustand(zustand, anzahlNachbarn):
    #Ursprungszelle Tod + genau 3 lebende Nachbarn = lebend
    #Ursprungszelle Lebend + genau 1 lebenden Nachbarn = tot
    #Ursprungszelle Lebend + 2 o. 3 Nachbarn = lebend
    #Ursprungszelle lebend + 4 oder mehr Nachbarn = tot
    
    for i in range(0, zeilen):
        for j in range(0, spalten):
            if zustand[(i,j)] == 1 and (anzahlNachbarn[(i,j)] in range(2) or anzahlNachbarn[(i,j)] in range(4,9)) :
                zustand[(i,j)]=0
            elif zustand[(i,j)] == 0 and anzahlNachbarn[(i,j)]==3:
                zustand[(i,j)]=1
                    
    return zustand

def Schritt():
    global zustand
    anzahlNachbarn = BerechneAnzahlNachbarn(zustand)
    return BerechneNeuenZustand(zustand, anzahlNachbarn)
                
def Wiederhole(t):
    for i in range(t):
        Schritt()

#t= int(input('Gib die Zeitschritte ein: '))
def Initialisiere(z, s):
    global zustand, tem, zeilen, spalten

    zeilen = z
    spalten = s
    
    zustand = np.round(np.random.random((zeilen,spalten))).astype(int)
    tem = Tripleeinheitsmatrix(zeilen,spalten)
#Wiederholungen(t)   
ws1920/sechster_gruppentermin_09.01.2020.txt · Zuletzt geändert: 2020/01/23 17:16 von hannariegel