diff --git a/src/main.rs b/src/main.rs index e7a11a9..de6d14b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,36 @@ + +mod my_match; +use my_match::*; + + fn main() { - println!("Hello, world!"); + let size: (usize, usize) = (240, 80); + + let mut z: f2d; + let mut c: f2d; + let s = 40.0; + let sx = 1.8; + + for j in 0..size.1 { + for i in 0..size.0 { + let mut uv: (f32, f32) = (i as f32, j as f32); + uv = (uv.0 - size.0 as f32 / 2., uv.1 - size.1 as f32 / 2.); + uv = (uv.0 / (s * sx), uv.1 / s); + + c = f2d::new(uv.0, uv.1); + z = f2d::def(); + + for _ in 0..100 { + z.mul(z.clone()); + z.add(c.clone()); + } + + if z.len() < 2. { + print!("$"); + } else { + print!(" "); + } + } + print!("\n"); + } } diff --git a/src/my_match/mod.rs b/src/my_match/mod.rs new file mode 100644 index 0000000..6aaca83 --- /dev/null +++ b/src/my_match/mod.rs @@ -0,0 +1,43 @@ +pub fn mid(a: f32, b: f32) -> f32{ + return (a+b)/2.; +} + + +#[derive(Clone)] +pub struct f2d{ + x: f32, + y: f32, +} + +impl f2d{ + pub fn new(x: f32, y: f32) -> Self{ + f2d { + x: x, + y: y, + } + } + pub fn def() -> Self{ + f2d { + x: 0.0, + y: 0.0, + } + } + // вычесления + pub fn len(self) -> f32{ + /*if self.x == 0. && self.y == 0.{ + return 0.; + }*/ + (self.x * self.x + self.y * self.y).sqrt() + } + pub fn add(&mut self, b: f2d) { + self.x += b.x; + self.y += b.y; + } + pub fn mul(&mut self, b: f2d){ + let x: f32 = self.x * b.x - self.y * b.y; + let y: f32 = self.x * b.y + self.y * b.x; + + self.x = x; + self.y = y; + } +}