Created
October 31, 2010 08:38
-
-
Save Cairnarvon/656307 to your computer and use it in GitHub Desktop.
Trying to decide if Tcl is worth learning.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/tclsh | |
set rows 40 | |
set cols 80 | |
if {$argc == 2} { | |
set rows [lindex $argv 0] | |
set cols [lindex $argv 1] | |
} elseif {$argc != 0} { | |
puts "Invalid arguments! Need two (rows, cols) or none." | |
exit | |
} | |
proc mandel {real imag} { | |
set z_r 0.0 | |
set z_i 0.0 | |
for {set i 0} {$i < 20} {incr i} { | |
set z_r_t [expr $z_r * $z_r - $z_i * $z_i + $real] | |
set z_i_t [expr 2 * $z_r * $z_i + $imag] | |
set z_r $z_r_t | |
set z_i $z_i_t | |
if {$z_r * $z_r + $z_i * $z_i > 4} { | |
return [expr {$i < 5 ? " " : $i < 10 ? "░" : $i < 15 ? "▒" : "▓"}] | |
} | |
} | |
return "█" | |
} | |
for {set i 0} {$i < $rows} {incr i} { | |
for {set j 0} {$j < $cols} {incr j} { | |
puts -nonewline [mandel [expr 4.0 * $j / $cols - 2]\ | |
[expr -4.0 * $i / $rows + 2]] | |
} | |
puts "" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment