mandelbrot
This commit is contained in:
1 parent
17c287237d
commit
0a24863b34
2 files changed
+77
-1
No files matched your search
+34
-1
@@ -1,3 +1,36 @@
|
|||||||
|
|
||||||
|
mod my_match;
|
||||||
|
use my_match::*;
|
||||||
|
|
||||||
|
|
||||||
fn main() {
|
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");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user