This commit is contained in:
lemon-cat committed 2026-05-11 14:29:27 +03:00
1 parent 5f038f9bfa
commit a4185970d9
4 files changed
+214 -158

No files matched your search

+27 -73
View File
@@ -1,118 +1,72 @@
use crossterm::{
//cursor::MoveTo,
cursor::MoveTo,
execute,
queue,
style::{Color, Print, ResetColor, SetBackgroundColor},
terminal::{Clear, ClearType},
};
use std::io::stdout;
use std::io::{Write, stdout};
mod c_math;
use c_math::*;
const X_SCAILE: f32 = 2.7;
const X_SCAILE: f64 = 2.7;
pub fn m_render(
size: (usize, usize),
scale: f32,
pos: (f32, f32),
scale: f64,
pos: (f64, f64),
) -> Result<(), Box<dyn std::error::Error>> {
/*
let mut colors = [
Color::Rgb { r: 0, g: 0, b: 0 },
Color::Rgb {
r: 150,
g: 90,
b: 150,
},
];
*/
let mut grad = Color::Rgb { r: 0, g: 0, b: 0 };
let mut out = stdout();
queue!(out, MoveTo(0, 0))?;
//out.flush()?;
let mut z: f2d;
let mut c: f2d;
let xs: f32 = size.0 as f32 / 2.;
let ys: f32 = size.1 as f32 / 2.;
let deep: f32 = 0.2 / scale;
let xs: f64 = size.0 as f64 / 2.;
let ys: f64 = size.1 as f64 / 2.;
//let deep: f32 = 1.0 / scale;
let deep = (100.0 + scale.log10().abs() * 80.0) as usize;
for i in 0..size.0 {
for j in 0..size.1 {
let x: f32 = i as f32;
let y: f32 = j as f32;
let x: f64 = i as f64;
let y: f64 = j as f64;
c = f2d::new(
(x - xs) * scale * X_SCAILE + pos.0,
(y - ys) * scale + pos.1,
(x - xs) * scale as f64 * X_SCAILE + pos.0,
(y - ys) * scale as f64 + pos.1,
);
z = f2d::def();
let mut m: f32 = 0.0;
let mut m: usize = 0;
let mut k = true;
while k {
z.mul(z.clone());
z.add(c.clone());
m += 1.0;
k = (z.len() < 2.0) && (m < deep);
//if m > deep {
// println!("Stop me!!!");
//}
m += 1;
k = (z.len() < 4.0) && (m < deep);
}
if z.len() > 2.0 {
//m /= deep;
let smooth = m + 1.0 - z.len().ln().ln() / 2.0_f32.ln();
/*
let t = (smooth / deep).clamp(0.0, 1.0);
grad = Color::Rgb {
r: (t * 230.0 + 10.0) as u8,
g: (t * 100.0 + 10.0) as u8,
b: (t * 240.0 + 10.0) as u8,
};
*/
let smooth = (m as f64 + 1.0 - z.len().ln().ln() / 2.0_f64.ln()) as f32;
grad = Color::Rgb {
r: (((smooth * 0.1).sin() + 1.0) * 230.0) as u8,
g: (((smooth * 0.1).sin() + 1.0) * 100.0) as u8,
b: (((smooth * 0.1 + 0.1).sin() + 1.0) * 220.0) as u8,
};
/*
grad = Color::Rgb {
r: (m * 230.0 + 10.0) as u8,
g: (m * 100.0 + 10.0) as u8,
b: (m * 230.0 + 10.0) as u8,
};
*/
execute!(out, SetBackgroundColor(grad), Print(" "), ResetColor)?;
queue!(out, SetBackgroundColor(grad), Print(" "), ResetColor)?;
out.flush()?;
grad = Color::Rgb { r: 0, g: 0, b: 0 };
} else {
execute!(out, SetBackgroundColor(grad), Print(" "), ResetColor,)?;
queue!(out, SetBackgroundColor(grad), Print(" "), ResetColor,)?;
out.flush()?;
}
/*
z = f2d::def();
for k in 0..deep {
z.mul(z.clone());
z.add(c.clone());
if z.len() > 2. {
let mut m = (k as f32) / (deep as f32);
//m = (m / 100.0).round() * 100.0;
m *= 255.0;
colors[1] = Color::Rgb {
r: m as u8,
g: m as u8,
b: m as u8,
};
execute!(out, SetBackgroundColor(colors[1]), Print(" "), ResetColor,)?;
//print!("#");
break;
}
}
if z.len() < 2. {
execute!(out, SetBackgroundColor(colors[0]), Print(" "), ResetColor,)?;
}
*/
}
println!();
queue!(out, Print("\r\n"))?;
}
out.flush()?;
Ok(())
}