1998-01-16 15:13:05 +03:00
|
|
|
# random dot steraogram
|
|
|
|
# usage: rcs.rb rcs.dat
|
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
sw = 40.0 # width of original pattern
|
|
|
|
dw = 78.0 # width of generating Random Character Streogram
|
1998-01-16 15:13:05 +03:00
|
|
|
hdw = dw / 2.0
|
1999-08-13 09:45:20 +04:00
|
|
|
w = 20.0 # distance between eyes
|
|
|
|
h =1.0 # distance from screen and base plane
|
|
|
|
d = 0.2 # z value unit
|
1998-01-16 15:13:05 +03:00
|
|
|
ss="abcdefghijklmnopqrstuvwxyz0123456789#!$%^&*()-=\\[];'`,./"
|
2002-12-19 23:56:37 +03:00
|
|
|
rnd = srand() # You don't actually need this in ruby - srand() is called
|
|
|
|
# on the first call of rand().
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
while gets()
|
|
|
|
# print($_)
|
|
|
|
xr = -hdw; y = h * 1.0; maxxl = -999
|
2002-12-19 23:56:37 +03:00
|
|
|
s = ""
|
1998-01-16 15:13:05 +03:00
|
|
|
while xr < hdw
|
|
|
|
x = xr * (1 + y) - y * w / 2
|
|
|
|
i = (x / (1 + h) + sw / 2)
|
2002-12-19 23:56:37 +03:00
|
|
|
if (1 < i && i < $_.length)
|
1998-01-16 15:13:05 +03:00
|
|
|
c = $_[i, 1].to_i
|
|
|
|
else
|
|
|
|
c = 0
|
|
|
|
end
|
|
|
|
y = h - d * c
|
2002-12-19 23:56:37 +03:00
|
|
|
xl = xr - w * y / (1 + y)
|
1998-01-16 15:13:05 +03:00
|
|
|
if xl < -hdw || xl >= hdw || xl <= maxxl
|
|
|
|
tt = rand(ss.length)
|
|
|
|
c = ss[tt, 1]
|
|
|
|
else
|
|
|
|
c = s[xl + hdw, 1]
|
|
|
|
maxxl = xl
|
|
|
|
end
|
|
|
|
s += c
|
|
|
|
xr += 1
|
|
|
|
end
|
|
|
|
print(s, "\n")
|
|
|
|
end
|