Hier werden die Unterschiede zwischen zwei Versionen gezeigt.
Beide Seiten der vorigen Revision Vorhergehende Überarbeitung Nächste Überarbeitung | Vorhergehende Überarbeitung | ||
ws1920:sechster_termin_9.1 [2020/01/09 16:57] richard.wonneberger |
ws1920:sechster_termin_9.1 [2020/01/09 17:54] (aktuell) richard.wonneberger |
||
---|---|---|---|
Zeile 1: | Zeile 1: | ||
- | code am anfang:(funktioniert) | ||
+ | Sechster Termin(erster termin des neuen Jahres)(9.1.20) | ||
+ | __**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: | ||
<code> | <code> | ||
Zeile 10: | Zeile 42: | ||
from matplotlib import animation | from matplotlib import animation | ||
import random | import random | ||
+ | |||
+ | |||
def animate (e): | def animate (e): | ||
Zeile 15: | Zeile 49: | ||
return im, | return im, | ||
- | N=50 | + | zeilen = int(input('Gib die Anzahl der Zeilen/Spalten ein: ')) |
- | e=np.random.random((N,N)) | + | spalten = zeilen |
- | print(e) | + | |
- | fig = plt.figure() | + | |
- | im=plt.imshow(e, animated=True) | + | |
- | anim = animation.FuncAnimation(fig, animate, frames=200, interval=100, blit=True) | + | |
- | #blit ist ueberschreiben statt alles neu zu machen | + | |
- | # | + | |
- | plt.show() | + | |
- | </code> | + | gol.Initialisiere(zeilen, spalten) |
- | <code> | + | fig = plt.figure(figsize=(1920,1080), dpi=1, frameon=False) |
- | 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 Matrix_füllen(M,zeilen,spalten): | ||
- | for i in range(0, zeilen): | ||
- | for j in range(0, spalten): | ||
- | if random.random() < 0.5: | ||
- | M[(i,j)]= 1 | ||
- | else: | ||
- | M[(i,j)]= 0 | ||
- | return M | ||
- | | ||
- | def Tripleeinheitsmatrix(D,zeilen,spalten): | + | #fig position ändern |
- | for i in range(0, zeilen): | + | |
- | for j in range(0, spalten): | + | |
- | if i==j: | + | |
- | D[(i,j)] = 1 | + | |
- | else: | + | |
- | D[(i,j)] = 0 | + | |
- | + | ||
- | for i in range(0, zeilen): | + | |
- | for j in range(0, spalten): | + | |
- | if i==(j+1): | + | |
- | D[(i,j)] = 1 | + | |
- | for i in range(0, zeilen): | + | |
- | for j in range(0, spalten): | + | |
- | if j==(i+1): | + | |
- | D[(i,j)] = 1 | + | |
- | + | ||
- | D[0,D.shape[1]-1] = 1 | + | |
- | D[D.shape[1]-1,0] = 1 | + | |
- | + | ||
- | return D | + | |
- | | + | |
- | def Generationen(Matrix_füllen,Tripleeinheitsmatrix): | ||
- | def Matrizenmultiplikation(D,M): | ||
- | z = np.dot(D,M) | ||
- | k = np.dot(z,D) | ||
- | wandelmatrix = k- M | ||
- | | ||
- | return wandelmatrix | ||
- | | ||
- | wandelmatrix= Matrizenmultiplikation(D,M) | ||
- | Matrizenmultiplikation(D,M) | ||
- | #print (wandelmatrix) | ||
- | | ||
- | | ||
- | #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 | ||
- | | ||
- | | ||
- | def GameofLife(M,wandelmatrix): | ||
- | for i in range(0, zeilen): | ||
- | for j in range(0, spalten): | ||
- | if M[(i,j)] == 1 and (wandelmatrix[(i,j)]==2 or wandelmatrix[(i,j)]==3) : | ||
- | M[(i,j)]=1 | ||
- | elif M[(i,j)] == 1 and (wandelmatrix[(i,j)]==1 or wandelmatrix[(i,j)] in range(4,9)) : | ||
- | M[(i,j)]=0 | ||
- | elif M[(i,j)] == 0 and wandelmatrix[(i,j)]==3: | ||
- | M[(i,j)]=1 | ||
- | else: | ||
- | M[(i,j)]=0 | ||
- | | ||
- | return M | ||
- | | ||
- | return GameofLife(M,wandelmatrix) | ||
- | #print(M) | ||
- | #plt.imshow(M) | ||
- | #plt.show() | ||
- | | ||
- | def Wiederholungen(t): | ||
- | for i in range(t): | ||
- | Generationen(Matrix_füllen,Tripleeinheitsmatrix) | ||
- | def Schritt(): | ||
- | return Generationen(Matrix_füllen,Tripleeinheitsmatrix) | ||
- | t= int(input('Gib die Zeitschritte ein: ')) | + | plt.axis('off') |
- | zeilen = int(input('Gib die Anzahl der Zeilen/Spalten ein: ')) | + | |
- | spalten = zeilen | + | |
- | M = np.zeros ((zeilen,spalten)) | + | #figure(num=None, figsize=(8, 6), dpi=80, facecolor='w', edgecolor='k') |
- | D = np.zeros ((zeilen,spalten)) | + | #plt.figure(figsize=(1,1)) |
- | wandelmatrix = np.zeros ((zeilen,spalten)) | + | im = plt.imshow(gol.zustand, animated=True, cmap=plt.get_cmap('gray')) |
- | + | anim = animation.FuncAnimation(fig, animate, frames=200, interval=100) | |
- | Matrix_füllen(M,zeilen,spalten) | + | #blit ist boese |
- | Tripleeinheitsmatrix(D,zeilen,spalten) | + | # |
- | Generationen(Matrix_füllen,Tripleeinheitsmatrix) | + | # fuer mint gruen cmap=YlGn |
- | #Wiederholungen(t) | + | |
+ | plt.show() | ||
</code> | </code> | ||
+ | Bibliothek(aufgeraeumt): | ||
<code> | <code> | ||
Zeile 209: | Zeile 155: | ||
</code> | </code> | ||
- | <code> | ||
- | |||
- | 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() | ||
- | im = plt.imshow(gol.zustand, animated=True, cmap=plt.get_cmap('PiYG_r')) | ||
- | anim = animation.FuncAnimation(fig, animate, frames=200, interval=100) | ||
- | #blit ist boese | ||
- | # | ||
- | # fuer mint gruen cmap=YlGn_r | ||
- | |||
- | plt.show() | ||
- | </code> | ||