lesson 2
This commit is contained in:
1 parent
9986cbbb28
commit
8b63d4fd7a
6 files changed
+185
-64
No files matched your search
@@ -0,0 +1,68 @@
|
||||
use crossterm::{
|
||||
cursor::MoveTo,
|
||||
execute,
|
||||
style::{Color, Print, ResetColor, SetBackgroundColor},
|
||||
};
|
||||
use std::io::stdout;
|
||||
|
||||
mod c_math;
|
||||
use c_math::*;
|
||||
|
||||
const X_SCAILE: f32 = 2.0;
|
||||
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 {
|
||||
r: 150,
|
||||
g: 90,
|
||||
b: 150,
|
||||
},
|
||||
];
|
||||
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;
|
||||
|
||||
for i in 0..size.0 {
|
||||
for j in 0..size.1 {
|
||||
let x: f32 = i as f32;
|
||||
let y: f32 = j as f32;
|
||||
|
||||
c = f2d::new(
|
||||
(x - xs) * scale * X_SCAILE + pos.0,
|
||||
(y - ys) * scale + pos.1,
|
||||
);
|
||||
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!();
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
Reference in new issue
Block a user