test
This commit is contained in:
1 parent
cacda9ea37
commit
db52f5ebe0
8 files changed
+223
-11
No files matched your search
@@ -0,0 +1,68 @@
|
||||
import pandas as pd
|
||||
import matplotlib.pyplot as plt
|
||||
import imageio.v2 as imageio # v2 évite les messages d'avertissement
|
||||
import os
|
||||
import tempfile
|
||||
import shutil
|
||||
|
||||
def create_gif_from_csv(csv_path, output_gif, duration=0.5):
|
||||
# 1. Lecture du CSV
|
||||
try:
|
||||
df = pd.read_csv(csv_path, sep=';', header=None)
|
||||
except Exception as e:
|
||||
print(f"Erreur lors de la lecture du fichier : {e}")
|
||||
return
|
||||
|
||||
n_max = len(df)
|
||||
frames = []
|
||||
|
||||
# Création d'un dossier temporaire sécurisé
|
||||
# Il sera supprimé automatiquement à la fin du traitement
|
||||
temp_dir = tempfile.mkdtemp()
|
||||
print(f"Dossier temporaire créé : {temp_dir}")
|
||||
|
||||
try:
|
||||
# 2. Création de chaque graphe
|
||||
for i, row in df.iterrows():
|
||||
n = i + 1
|
||||
# Affichage de la progression
|
||||
print(f"ligne {n} / {n_max}")
|
||||
|
||||
plt.figure(figsize=(8, 5))
|
||||
plt.plot(row.values, marker='', linestyle='-', color='b')
|
||||
plt.yticks([])
|
||||
plt.xticks([])
|
||||
plt.title(f"Graphe - Ligne {n}")
|
||||
plt.grid(True)
|
||||
|
||||
# Échelle constante basée sur l'ensemble du dataset
|
||||
plt.ylim(df.min().min() - 1, df.max().max() + 1)
|
||||
|
||||
# Chemin complet de l'image dans le dossier temporaire
|
||||
filename = os.path.join(temp_dir, f"frame_{i}.png")
|
||||
plt.savefig(filename)
|
||||
plt.close()
|
||||
|
||||
# Lecture pour le GIF
|
||||
frames.append(imageio.imread(filename))
|
||||
|
||||
# 3. Compilation en GIF
|
||||
if frames:
|
||||
print("\nCompilation du GIF en cours...")
|
||||
imageio.mimsave(output_gif, frames, duration=duration, loop=0)
|
||||
print(f"Succès ! Ton animation est prête : {output_gif}")
|
||||
else:
|
||||
print("Aucune image n'a été générée.")
|
||||
|
||||
finally:
|
||||
# 4. Nettoyage complet du dossier temporaire
|
||||
# On utilise shutil.rmtree pour supprimer le dossier et son contenu
|
||||
shutil.rmtree(temp_dir)
|
||||
print(f"Nettoyage effectué : dossier {temp_dir} supprimé.")
|
||||
|
||||
# --- Configuration ---
|
||||
fichier_csv = 'temp.csv'
|
||||
nom_du_gif = 'mon_animation.gif'
|
||||
|
||||
# Lancer la fonction
|
||||
create_gif_from_csv(fichier_csv, nom_du_gif, duration=0.5)
|
||||
+53
-11
@@ -1,5 +1,5 @@
|
||||
use core::fmt;
|
||||
use std::{env, io::{stdout, Write}, ops::{Index, IndexMut}, thread::sleep, time::Duration};
|
||||
use std::{env, fs::File, io::{Write, stdout}, ops::{Index, IndexMut}, thread::sleep, time::Duration};
|
||||
use libc::{exit};
|
||||
use owo_colors::{OwoColorize};
|
||||
use terminal_size::{terminal_size, Width, Height};
|
||||
@@ -81,28 +81,32 @@ fn tempsp1 (mat:&mut Matrice<u64>) -> () {
|
||||
let tmp = mat.clone();
|
||||
for x in 0..tmp.largeur {
|
||||
for y in 0..tmp.hauteur {
|
||||
|
||||
let mut tempmoy = 0;
|
||||
|
||||
for i in 0..9 {
|
||||
let (xtmp,ytmp) = coovois(i, x as isize, y as isize);
|
||||
if ytmp < 0 {
|
||||
tempmoy += mat.nb_state as usize;
|
||||
tempmoy += mat[(x,y)] as usize;
|
||||
} else if ytmp as usize >= tmp.hauteur {
|
||||
()
|
||||
}else if xtmp < 0 || xtmp as usize >= tmp.largeur {
|
||||
tempmoy += mat[(x,y)] as usize;
|
||||
} else if xtmp < 0 {
|
||||
tempmoy += mat[(x,y)] as usize
|
||||
} else if xtmp as usize >= tmp.largeur {
|
||||
tempmoy += mat[(x,y)] as usize;
|
||||
} else {
|
||||
let type_cell = tmp[(xtmp as usize,ytmp as usize)] as usize;
|
||||
tempmoy += type_cell;
|
||||
}
|
||||
}
|
||||
if mat[(x,y)] < mat.nb_state {
|
||||
mat[(x,y)] = (0.88888888 * tempmoy as f64 / 8.).round() as u64;
|
||||
if mat[(x,y)] <= mat.nb_state {
|
||||
mat[(x,y)] = (1. * tempmoy as f64 / 9.).round() as u64;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main () {
|
||||
fn main () -> Result<(), Box<dyn std::error::Error>> {
|
||||
|
||||
// cache le curseur
|
||||
print!("\x1b[?47h\x1b[?1049h\x1b[?25l");
|
||||
@@ -120,7 +124,7 @@ fn main () {
|
||||
let args: Vec<String> = env::args().collect();
|
||||
let nb_state: u64 = args[1].parse::<u64>().unwrap();
|
||||
|
||||
let mut a = Matrice::new(w, h, (nb_state / 2) as u64, nb_state);
|
||||
let mut a = Matrice::new(w, h, (0) as u64, nb_state);
|
||||
|
||||
if args.len() >= 3 {
|
||||
a.gen_ran();
|
||||
@@ -140,17 +144,55 @@ fn main () {
|
||||
//a[(2 + 96,1)] = 1;
|
||||
//a[(0 + 96,2)] = 1;
|
||||
//a[(1 + 96,2)] = 1;
|
||||
//a[(2 + 96,2)] = 1;
|
||||
//a[(2 + 96,2)] = 1
|
||||
let filetmp = File::create("temp.csv");
|
||||
let mut file;
|
||||
match filetmp {
|
||||
Ok(tmp) => file = tmp,
|
||||
Err(_) => unsafe {exit(1)},
|
||||
}
|
||||
|
||||
let objtmp = File::create("obj.csv");
|
||||
let mut objf;
|
||||
match objtmp {
|
||||
Ok(tmp) => objf = tmp,
|
||||
Err(_) => unsafe {exit(1)},
|
||||
}
|
||||
|
||||
let mut i: isize = 0;
|
||||
|
||||
a[(w/2, h)] = nb_state / 10;
|
||||
a[(w/2 - 1, h)] = nb_state / 10;
|
||||
a[(w/2, h - 1)] = nb_state / 10;
|
||||
a[(w/2 + 1, h)] = nb_state / 10;
|
||||
a[(w/2, h + 1)] = nb_state / 10;
|
||||
a[(w/2 + 1, h - 1)] = nb_state / 10;
|
||||
a[(w/2 + 1, h + 1)] = nb_state / 10;
|
||||
a[(w/2 - 1, h + 1)] = nb_state / 10;
|
||||
a[(w/2 - 1, h - 1)] = nb_state / 10;
|
||||
|
||||
loop {
|
||||
let now = std::time::Instant::now();
|
||||
print!("{a}");
|
||||
if i % 100000000 == 0 {
|
||||
print!("{a}");
|
||||
for y in 0..a.hauteur {
|
||||
let cases = a[(a.largeur/2, y)];
|
||||
let save = cases.to_string() + ";";
|
||||
file.write_all(save.as_bytes())?;
|
||||
}
|
||||
file.write_all(b"\n")?;
|
||||
|
||||
let cases = a[(a.largeur/2, a.hauteur/2)];
|
||||
objf.write_all(cases.to_string().as_bytes())?;
|
||||
objf.write_all(b"\n")?;
|
||||
i = 0;
|
||||
}
|
||||
tempsp1(&mut a);
|
||||
|
||||
let dif = now.elapsed();
|
||||
if dif <= TEMPS {
|
||||
sleep(TEMPS - dif);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user