Фрактал. На bash. Псевдографика!
Попросил ГПТ нарисовать мне фрактал. На bash. Попросил - получи!
#!/bin/bash
# Set the dimensions of the output
WIDTH=80
HEIGHT=40
# Set the range of the complex plane
RE_MIN=-2.0
RE_MAX=1.0
IM_MIN=-1.5
IM_MAX=1.5
# Function to calculate the Mandelbrot set
mandelbrot() {
local re im
local i j
local max_iter=100
local output
for ((j=0; j<HEIGHT; j++)); do
for ((i=0; i<WIDTH; i++)); do
re=$(echo "$RE_MIN + ($RE_MAX - $RE_MIN) * $i / $WIDTH" | bc -l)
im=$(echo "$IM_MIN + ($IM_MAX - $IM_MIN) * $j / $HEIGHT" | bc -l)
z_re=0
z_im=0
iter=0
while (( $(echo "$z_re * $z_re + $z_im * $z_im <= 4" | bc -l) && iter < max_iter )); do
temp_re=$(echo "$z_re * $z_re - $z_im * $z_im + $re" | bc -l)
z_im=$(echo "2 * $z_re * $z_im + $im" | bc -l)
z_re=$temp_re
((iter++))
done
if (( iter == max_iter )); then
output="#"
else
output="."
fi
echo -n "$output"
done
echo ""
done
}
# Run the Mandelbrot function
mandelbrot
GNU/Linux
1.2K пост15.6K подписчика
Правила сообщества
Все дистрибутивы хороши.
Будьте людьми.