sample/rcs.rb


DEFINITIONS

This source file includes following functions.


   1  # random dot steraogram
   2  # usage: rcs.rb rcs.dat
   3  
   4  sw = 40.0       # width of original pattern
   5  dw = 78.0       # width of generating Random Character Streogram
   6  hdw = dw / 2.0
   7  w = 20.0        # distance between eyes
   8  h =1.0          # distance from screen and base plane
   9  d = 0.2         # z value unit
  10  ss="abcdefghijklmnopqrstuvwxyz0123456789#!$%^&*()-=\\[];'`,./"
  11  rnd = srand()
  12  
  13  while gets()
  14  #  print($_)
  15    xr = -hdw; y = h * 1.0; maxxl = -999
  16    s = "";
  17    while xr < hdw
  18      x = xr * (1 + y) - y * w / 2
  19      i = (x / (1 + h) + sw / 2)
  20      if (1 < i && i < $_.length);
  21        c = $_[i, 1].to_i
  22      else
  23        c = 0
  24      end
  25      y = h - d * c
  26      xl = xr - w * y / (1 + y);
  27      if xl < -hdw || xl >= hdw || xl <= maxxl
  28        tt = rand(ss.length)
  29        c = ss[tt, 1]
  30      else
  31        c = s[xl + hdw, 1]
  32        maxxl = xl
  33      end
  34      s += c
  35      xr += 1
  36    end
  37    print(s, "\n")
  38  end
  39        
  40    
  41      
  42    
  43  
  44  
  45  
  46  
  47    
  48    
  49