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