/usr/share/doc/ruby-gsl/examples/gallery/koch.rb is in ruby-gsl 2.1.0.3+dfsg1-1build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | #!/usr/bin/env ruby
# Koch curve
require("gsl")
include Math
ONE_UNIT = 3
def koch(x, y, theta, size, order, file)
if order == 0
x += cos(theta)*size
y += sin(theta)*size
file.printf("%e %e\n", x, y)
else
x, y = koch(x, y, theta, size/3, order-1, file)
theta += Math::PI/3
x, y = koch(x, y, theta, size/3, order-1, file)
theta -= 2.0*Math::PI/3
x, y = koch(x, y, theta, size/3, order-1, file)
theta += Math::PI/3
x, y = koch(x, y, theta, size/3, order-1, file)
end
return [x, y]
end
SIZE = 243
ORDER = 4
x = 0.0
y = 0.0
theta = 0.0
IO.popen("graph -T X -C -N x -N y", "w") do |io|
io.printf("%e %e\n", x, y)
x, y = koch(x, y, theta, SIZE, ORDER, io)
theta -= 2.0*Math::PI/3
x, y = koch(x, y, theta, SIZE, ORDER, io)
theta -= 2.0*Math::PI/3
x, y = koch(x, y, theta, SIZE, ORDER, io)
theta -= 2.0*Math::PI/3
end
|