In [50]:
require "json"
Out[50]:
In [38]:
class Point
def initialize(x, y)
@x = x
@y = y
end
def x
@x
end
def y
@y
end
def to_s
"(#@x,#@y)"
end
end
Out[38]:
In [46]:
path = [Point.new(0,1), Point.new(5,4), Point.new(2,8)]
Out[46]:
In [49]:
def calculate_points(path)
puts path.length
# path.each do |p|
# puts p.to_s
# end
for i in 1..(path.length-1)
puts "#{i} : #{path[i-1].x - path[i].x}"
end
end
calculate_points(path)
Out[49]:
In [52]:
x = Point.new(0,0).to_json
Out[52]:
In [59]:
a = path.map{|pt| {x: pt.x, y: pt.y, label: pt.to_s}}
puts a.to_json
In [ ]: