~ubuntu-branches/ubuntu/hardy/ruby1.8/hardy-updates

« back to all changes in this revision

Viewing changes to sample/rcs.rb

  • Committer: Bazaar Package Importer
  • Author(s): akira yamada
  • Date: 2007-03-13 22:11:58 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20070313221158-h3oql37brlaf2go2
Tags: 1.8.6-1
* new upstream version, 1.8.6.
* libruby1.8 conflicts with libopenssl-ruby1.8 (< 1.8.6) (closes: #410018)
* changed packaging style to cdbs from dbs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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()   # You don't actually need this in ruby - srand() is called
 
12
                # on the first call of rand().
 
13
 
 
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