From 9986cbbb281683000340070893de5c349aaf9985 Mon Sep 17 00:00:00 2001 From: lemon-cat Date: Sat, 2 May 2026 18:46:17 +0300 Subject: [PATCH] lesson 1 --- src/main.rs | 31 +++++++++++++++++++++++++++++-- src/my_math/mod.rs | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 src/my_math/mod.rs diff --git a/src/main.rs b/src/main.rs index e7a11a9..a7769b4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,30 @@ -fn main() { - println!("Hello, world!"); +mod my_math; +use my_math::*; + +fn main(){ + let size: (usize, usize) = (50, 100); + let mut z: f2d; + let mut c: f2d; + //let mut l: f32; + + for j in 0..size.0{ + for i in 0..size.1{ + c = f2d::new(((i as f32) - (size.1 as f32)/2.)*0.02, ((j as f32) - (size.0 as f32)/2.)*0.04); + z = f2d::def(); + for k in 0..10 { + z.mul(z.clone()); + z.add(c.clone()); + } + + if z.len() < 2. { print!(" "); } + else { print!("#"); } + + /* + l = f2d::len(z); + if (l - 20.) < 0.{ print!(" "); } + else { print!("#"); } + */ + } + print!("\n"); + } } diff --git a/src/my_math/mod.rs b/src/my_math/mod.rs new file mode 100644 index 0000000..3042a8e --- /dev/null +++ b/src/my_math/mod.rs @@ -0,0 +1,41 @@ +pub fn mid(a: f32, b: f32) -> f32{ + (a + b) / 2.0 +} + +#[derive(Clone)] +pub struct f2d{ + x: f32, + y: f32, +} + +impl f2d{ + pub fn new(a: f32, b: f32) -> Self{ + f2d{ + x: a, + y: b, + } + } + pub fn def() -> Self{ + f2d{ + x: 0.0, + y: 0.0, + } + } + // + pub fn len(self) -> f32{ + (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; + } +}