开发者

Plotting Euclidean plane in Ruby

开发者 https://www.devze.com 2023-02-10 08:32 出处:网络
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

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

精彩评论

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

关注公众号