home work 2.1

This commit is contained in:
lemon-cat committed 2026-05-07 18:38:01 +03:00
1 parent 8b63d4fd7a
commit 5f038f9bfa
3 files changed
+62 -8

No files matched your search

+53 -3
View File
@@ -1,5 +1,5 @@
use crossterm::{
cursor::MoveTo,
//cursor::MoveTo,
execute,
style::{Color, Print, ResetColor, SetBackgroundColor},
};
@@ -8,12 +8,13 @@ use std::io::stdout;
mod c_math;
use c_math::*;
const X_SCAILE: f32 = 2.0;
const X_SCAILE: f32 = 2.7;
pub fn m_render(
size: (usize, usize),
scale: f32,
pos: (f32, f32),
) -> Result<(), Box<dyn std::error::Error>> {
/*
let mut colors = [
Color::Rgb { r: 0, g: 0, b: 0 },
Color::Rgb {
@@ -22,13 +23,16 @@ pub fn m_render(
b: 150,
},
];
*/
let mut grad = Color::Rgb { r: 0, g: 0, b: 0 };
let mut out = stdout();
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: usize = (0.5 / scale) as usize;
let deep: f32 = 0.2 / scale;
for i in 0..size.0 {
for j in 0..size.1 {
@@ -40,6 +44,51 @@ pub fn m_render(
(y - ys) * scale + pos.1,
);
z = f2d::def();
let mut m: f32 = 0.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!!!");
//}
}
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,
};
*/
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)?;
grad = Color::Rgb { r: 0, g: 0, b: 0 };
} else {
execute!(out, SetBackgroundColor(grad), Print(" "), ResetColor,)?;
}
/*
z = f2d::def();
for k in 0..deep {
z.mul(z.clone());
z.add(c.clone());
@@ -61,6 +110,7 @@ pub fn m_render(
if z.len() < 2. {
execute!(out, SetBackgroundColor(colors[0]), Print(" "), ResetColor,)?;
}
*/
}
println!();
}