home work 2.1
This commit is contained in:
1 parent
8b63d4fd7a
commit
5f038f9bfa
3 files changed
+62
-8
No files matched your search
Whitespace-only changes.
@@ -1,5 +1,5 @@
|
|||||||
use crossterm::{
|
use crossterm::{
|
||||||
cursor::MoveTo,
|
//cursor::MoveTo,
|
||||||
execute,
|
execute,
|
||||||
style::{Color, Print, ResetColor, SetBackgroundColor},
|
style::{Color, Print, ResetColor, SetBackgroundColor},
|
||||||
};
|
};
|
||||||
@@ -8,12 +8,13 @@ use std::io::stdout;
|
|||||||
mod c_math;
|
mod c_math;
|
||||||
use c_math::*;
|
use c_math::*;
|
||||||
|
|
||||||
const X_SCAILE: f32 = 2.0;
|
const X_SCAILE: f32 = 2.7;
|
||||||
pub fn m_render(
|
pub fn m_render(
|
||||||
size: (usize, usize),
|
size: (usize, usize),
|
||||||
scale: f32,
|
scale: f32,
|
||||||
pos: (f32, f32),
|
pos: (f32, f32),
|
||||||
) -> Result<(), Box<dyn std::error::Error>> {
|
) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
/*
|
||||||
let mut colors = [
|
let mut colors = [
|
||||||
Color::Rgb { r: 0, g: 0, b: 0 },
|
Color::Rgb { r: 0, g: 0, b: 0 },
|
||||||
Color::Rgb {
|
Color::Rgb {
|
||||||
@@ -22,13 +23,16 @@ pub fn m_render(
|
|||||||
b: 150,
|
b: 150,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
*/
|
||||||
|
|
||||||
|
let mut grad = Color::Rgb { r: 0, g: 0, b: 0 };
|
||||||
let mut out = stdout();
|
let mut out = stdout();
|
||||||
|
|
||||||
let mut z: f2d;
|
let mut z: f2d;
|
||||||
let mut c: f2d;
|
let mut c: f2d;
|
||||||
let xs: f32 = size.0 as f32 / 2.;
|
let xs: f32 = size.0 as f32 / 2.;
|
||||||
let ys: f32 = size.1 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 i in 0..size.0 {
|
||||||
for j in 0..size.1 {
|
for j in 0..size.1 {
|
||||||
@@ -40,6 +44,51 @@ pub fn m_render(
|
|||||||
(y - ys) * scale + pos.1,
|
(y - ys) * scale + pos.1,
|
||||||
);
|
);
|
||||||
z = f2d::def();
|
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 {
|
for k in 0..deep {
|
||||||
z.mul(z.clone());
|
z.mul(z.clone());
|
||||||
z.add(c.clone());
|
z.add(c.clone());
|
||||||
@@ -61,6 +110,7 @@ pub fn m_render(
|
|||||||
if z.len() < 2. {
|
if z.len() < 2. {
|
||||||
execute!(out, SetBackgroundColor(colors[0]), Print(" "), ResetColor,)?;
|
execute!(out, SetBackgroundColor(colors[0]), Print(" "), ResetColor,)?;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
println!();
|
println!();
|
||||||
}
|
}
|
||||||
|
|||||||
+9
-5
@@ -53,8 +53,8 @@ fn in_pars() -> Result<InputEvent, String> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let size: (usize, usize) = (100, 200);
|
let size: (usize, usize) = (200, 450);
|
||||||
let mut pos: (f32, f32) = (0.0, 0.1);
|
let mut pos: (f32, f32) = (0.0, 0.0);
|
||||||
let mut scale: f32 = 0.01;
|
let mut scale: f32 = 0.01;
|
||||||
let mut render = true;
|
let mut render = true;
|
||||||
//m_render(size, 0.007, (-0.4, 0.));
|
//m_render(size, 0.007, (-0.4, 0.));
|
||||||
@@ -73,11 +73,15 @@ fn main() {
|
|||||||
} else {
|
} else {
|
||||||
match input.unwrap() {
|
match input.unwrap() {
|
||||||
InputEvent::Pos(a, b) => {
|
InputEvent::Pos(a, b) => {
|
||||||
pos.0 += a;
|
pos.0 += a * scale * 10.0;
|
||||||
pos.1 += b;
|
pos.1 += b * scale * 10.0;
|
||||||
}
|
}
|
||||||
InputEvent::Scale(s) => {
|
InputEvent::Scale(s) => {
|
||||||
scale /= s;
|
if s == 0.0 {
|
||||||
|
println!("Scale is 0 !!!");
|
||||||
|
} else {
|
||||||
|
scale /= s;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user