-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdisplay.py
More file actions
92 lines (82 loc) · 2.88 KB
/
display.py
File metadata and controls
92 lines (82 loc) · 2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
################################# Imports #################################
import matplotlib.pyplot as plt
import numpy as np
import sys
import os
################################# Affichage Koch ##########################
def afficher_von_koch(filename):
data = np.loadtxt(filename, skiprows=1, delimiter=",")
plt.figure("Fractale de Von Koch")
plt.plot(data[:,0], data[:,1])
plt.xticks([])
plt.yticks([])
plt.gca().set_aspect('equal')
plt.title("Fractale de Von Koch")
plt.show()
################################# Affichage Newton ########################
def afficher_newton(filename):
data = np.loadtxt(filename, skiprows=1, delimiter=",")
RGB = data[:, 2:5] / 255.0 # Normalisation des couleurs RGB
plt.figure("Fractale de Newton")
plt.scatter(data[:,1], data[:,0], c=RGB)
plt.xticks([])
plt.yticks([])
plt.gca().set_aspect('equal')
plt.title("Fractale de Newton")
plt.show()
################################# Affichage Dragon ###########################
def afficher_dragon(filename):
data = np.loadtxt(filename, skiprows=1, delimiter=",")
plt.figure("Fractale du dragon de Heighway")
plt.plot(data[:,0], data[:,1])
plt.xticks([])
plt.yticks([])
plt.gca().set_aspect('equal')
plt.title("Fractale du dragon de Heighway")
plt.show()
################################# Affichage Barnsley ############################
def afficher_barnsley(filename):
data = np.loadtxt(filename, skiprows=1, delimiter=",")
plt.figure("Fractale de Barnsley")
plt.scatter(data[:,0], data[:,1], s=0.1, color = "green")
plt.xticks([])
plt.yticks([])
plt.gca().set_aspect('equal')
plt.title("Fractale de Barnsley")
plt.show()
################################ Affichage Levy ##############################
def afficher_levy(filename):
data = np.loadtxt(filename, skiprows=1, delimiter=",")
print(data)
plt.figure("Fractale de Lévy")
plt.plot(data[:,0], data[:,1])
plt.xticks([])
plt.yticks([])
plt.gca().set_aspect('equal')
plt.title("Fractale de Lévy")
plt.show()
################################# Main dispatcher #########################
def main():
if len(sys.argv) != 3:
print("Usage : python3 display.py <fractale> <fichier>")
sys.exit(1)
fractale = sys.argv[1].lower()
filename = sys.argv[2]
if not os.path.exists(filename):
print(f"Erreur : fichier {filename} introuvable.")
sys.exit(1)
if fractale == "koch":
afficher_von_koch(filename)
elif fractale == "newton":
afficher_newton(filename)
elif fractale == "dragon":
afficher_dragon(filename)
elif fractale == "barnsley":
afficher_barnsley(filename)
elif fractale == "levy":
afficher_levy(filename)
else:
print(f"Erreur : fractale inconnue '{fractale}'")
sys.exit(1)
if __name__ == "__main__":
main()