1 # The Computer Language Benchmarks Game
\r
2 # http://shootout.alioth.debian.org/
\r
4 # contributed by Karl von Laudermann
\r
5 # modified by Jeremy Echols
\r
7 size = 600 # ARGV[0].to_i
\r
9 puts "P4\n#{size} #{size}"
\r
11 ITER = 49 # Iterations - 1 for easy for..in looping
\r
12 LIMIT_SQUARED = 4.0 # Presquared limit
\r
17 count_size = size - 1 # Precomputed size for easy for..in looping
\r
19 # For..in loops are faster than .upto, .downto, .times, etc.
\r
20 for y in 0..count_size
\r
21 for x in 0..count_size
\r
24 cr = (2.0*x/size)-1.5
\r
25 ci = (2.0*y/size)-1.0
\r
28 # To make use of the for..in code, we use a dummy variable,
\r
29 # like one would in C
\r
30 for dummy in 0..ITER
\r
31 tr = zr*zr - zi*zi + cr
\r
35 if (zr*zr+zi*zi) > LIMIT_SQUARED
\r
41 byte_acc = (byte_acc << 1) | (escape ? 0b0 : 0b1)
\r
44 # Code is very similar for these cases, but using separate blocks
\r
45 # ensures we skip the shifting when it's unnecessary, which is most cases.
\r
50 elsif (x == count_size)
\r
51 byte_acc <<= (8 - bit_num)
\r