开发者

Plotting Euclidean plane in Ruby

I want to plot a graph which, for each edge in the dataset, will plot a line in an n*n grid.

For example, for a grid of 4*4

****
****
****
****

the edge [[1,3], [2,1]] will draw a line be开发者_如何学Gotween (1,3) and (2,3). 

**0*
0***
****
****


It can be done with shoes http://shoesrb.com/

Shoes.app do

a = your array

  strokewidth 1.0
  spread = 10
  stroke black
  fill black
  shape do
    x = a.first
    a.each do |x|
      oval x[0]*spread-2.5, x[1]*spread-2.5, 5
    end
    fill white
    move_to x[0]*spread, x[1]*spread
    a.each do |x|
      line_to x[0]*spread, x[1]*spread
   end   
  end
end
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜