lesson 1
This commit is contained in:
1 parent
17c287237d
commit
9986cbbb28
2 files changed
+70
-2
No files matched your search
+29
-2
@@ -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");
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user