Немного ускорил rust

This commit is contained in:
Viner Abubakirov
2025-09-15 16:30:08 +05:00
parent 74714e6140
commit 0fe2f4fdab

View File

@@ -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))