55 lines
1.2 KiB
Bash
55 lines
1.2 KiB
Bash
#! /bin/sh
|
|
exec huginn -E "${0}" "${@}"
|
|
#! huginn
|
|
|
|
import Algorithms as algo;
|
|
import Mathematics as math;
|
|
import Terminal as term;
|
|
|
|
mandelbrot( x, y ) {
|
|
c = math.Complex( x, y );
|
|
z = math.Complex( 0., 0. );
|
|
s = -1;
|
|
for ( i : algo.range( 50 ) ) {
|
|
z = z * z + c;
|
|
if ( | z | > 2. ) {
|
|
s = i;
|
|
break;
|
|
}
|
|
}
|
|
return ( s );
|
|
}
|
|
|
|
main( argv_ ) {
|
|
imgSize = term_size( argv_ );
|
|
yRad = 1.2;
|
|
yScale = 2. * yRad / real( imgSize[0] );
|
|
xScale = 3.3 / real( imgSize[1] );
|
|
glyphTab = [ ".", ":", "-", "+", "+" ].resize( 12, "*" ).resize( 26, "%" ).resize( 50, "@" ).push( " " );
|
|
for ( y : algo.range( imgSize[0] ) ) {
|
|
line = "";
|
|
for ( x : algo.range( imgSize[1] ) ) {
|
|
line += glyphTab[ mandelbrot( xScale * real( x ) - 2.3, yScale * real( y ) - yRad ) ];
|
|
}
|
|
print( line + "\n" );
|
|
}
|
|
return ( 0 );
|
|
}
|
|
|
|
term_size( argv_ ) {
|
|
lines = 25;
|
|
columns = 80;
|
|
if ( size( argv_ ) == 3 ) {
|
|
lines = integer( argv_[1] );
|
|
columns = integer( argv_[2] );
|
|
} else {
|
|
lines = term.lines();
|
|
columns = term.columns();
|
|
if ( ( lines % 2 ) == 0 ) {
|
|
lines -= 1;
|
|
}
|
|
}
|
|
lines -= 1;
|
|
columns -= 1;
|
|
return ( ( lines, columns ) );
|
|
}
|