* io.c (rb_open_file): encoding in mode string was ignored if perm is
[ruby-svn.git] / sample / rcs.rb
blob0bdf81c45d4195f19d12bfc353b58141e93d878b
1 # random dot steraogram
2 # usage: rcs.rb rcs.dat
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()   # You don't actually need this in ruby - srand() is called
12                 # on the first call of rand().
14 while gets()
15 #  print($_)
16   xr = -hdw; y = h * 1.0; maxxl = -999
17   s = ""
18   while xr < hdw
19     x = xr * (1 + y) - y * w / 2
20     i = (x / (1 + h) + sw / 2)
21     if (1 < i && i < $_.length)
22       c = $_[i, 1].to_i
23     else
24       c = 0
25     end
26     y = h - d * c
27     xl = xr - w * y / (1 + y)
28     if xl < -hdw || xl >= hdw || xl <= maxxl
29       tt = rand(ss.length)
30       c = ss[tt, 1]
31     else
32       c = s[xl + hdw, 1]
33       maxxl = xl
34     end
35     s += c
36     xr += 1
37   end
38   print(s, "\n")
39 end