Немного ускорил rust
This commit is contained in:
5
main.rs
5
main.rs
@@ -1,4 +1,5 @@
|
||||
use std::env;
|
||||
use std::fmt::Write;
|
||||
use std::ops::{Add, Div, Mul, Sub};
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
@@ -198,7 +199,7 @@ fn fractal(size: u32, depth: u8, g2: Complex, g3: Complex) -> String {
|
||||
let xf: f64 = 2.0;
|
||||
let yf: f64 = 2.0;
|
||||
|
||||
let mut code = String::new();
|
||||
let mut code = String::with_capacity((size * size * 3) as usize);
|
||||
|
||||
for y in 0..=size - 1 {
|
||||
let zy = y as f64 * (yf - yi) / (size as f64 - 1.0) + yi;
|
||||
@@ -207,7 +208,7 @@ fn fractal(size: u32, depth: u8, g2: Complex, g3: Complex) -> String {
|
||||
let mut z = Complex::new(zx, zy);
|
||||
for i in 0..=depth - 1 {
|
||||
if z.abs() > 2.0 {
|
||||
code.push_str(&i.to_string());
|
||||
write!(&mut code, "{}", i).unwrap();
|
||||
break;
|
||||
}
|
||||
z = (z.powi(4) + 0.5 * g2 * z.powi(2) + 2.0 * g3 * z + 1.0 / 16.0 * g2.powi(2))
|
||||
|
||||
Reference in New Issue
Block a user