English 中文(简体)
鲁比拉角点和试采
原标题:Plot points and rectangles in Ruby
  • 时间:2012-04-25 16:55:26
  •  标签:
  • ruby
  • svg
  • plot

我正在寻找一种容易的方法,以图画大约10点和试采,以便能够看到我算法的错误之处。 我看上去了梯度,但看来这特别糟糕的是块块状。

最佳回答

SVG(MDN Tutorial)是一种非常简单的文本格式,可不使用SVG图书馆而轻易使用,并在任何现代网络浏览器上浏览。 例如:

SVG Points via String Interpolation

points = (0..5).map{ [rand(100)-50,rand(100)-50] }

puts <<ENDSVG
<svg xmlns="http://www.w3.org/2000/svg" viewBox="-100 -100 200 200">
#{points.map{ |x,y| "<circle cx= #{x}  cy= #{y}  r= 3  />" }.join("
")}
</svg>
ENDSVG

Output: http://jsfiddle.net/xwnVY/


如果你想比扼制干涉更有条理:

SVG Points Using Nokogiri XML Builder

require  nokogiri  # gem install nokogiri
b = Nokogiri::XML::Builder.new do |doc|
  doc.svg xmlns:"http://www.w3.org/2000/svg", viewBox:"-100 -100 200 200" do
    points.each do |x,y|
      doc.circle r:3, cx:x, cy:y
    end
  end
end
puts b.to_xml

将产出作为“foo.svg”加以删除,并在现代网络浏览器上开放。


Drawing Rects

引人注意:

<rect transform="rotate(45)" x="0" y="0" width="100" height="200" />
<polygon points="0,0 100,0 100,100 0,100" />
<path d="M0,0 L100,0 100,100 0,100 Z" />

如果你想要把不偏重变化的武断点连接起来,多角可能是最容易生产的。 请注意,虽然I ve以<代码>x,y x,y格式显示上述坐标,但若便于您的代码生成,SVG还将接受<代码>x、y、x、y或x y x y x


A Bit of Formatting

如果你想要提纲而不是填表,你可以在特别志愿人员小组中添加这一特别安全部分:

<style>
  rect, polygon, path { fill:none; stroke:black; stroke-width:1px }
</style>

Using Haml for the XML

Finally, Haml is another option that you might consider for making your XML without an SVG-specific library:

@points = (0..7).map{ [rand(100)-50,rand(100)-50] }

require  haml 
puts Haml::Engine.new(<<ENDHAML).render(self)
%svg(xmlns="http://www.w3.org/2000/svg" viewBox="-100 -100 200 200")
  :css
    circle { fill:orange }
    rect, polygon, path {
      fill:none; stroke:black;
      vector-effect:non-scaling-stroke
    }
  - @points.each_slice(4) do |rect|
    %polygon{ points:rect.join(" ") }
  - @points.each do |x,y|
    %circle{r:3, cx:x, cy:y}
ENDHAML

Output: http://jsfiddle.net/xwnVY/4/

问题回答

也许你可以尝试特别学校。 便于创建(解释XML)、开放式、跨平台,你可以开张,使用因子替罪scape。





相关问题
Ruby parser in Java

The project I m doing is written in Java and parsers source code files. (Java src up to now). Now I d like to enable parsing Ruby code as well. Therefore I am looking for a parser in Java that parses ...

rails collection_select vs. select

collection_select and select Rails helpers: Which one should I use? I can t see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

multiple ruby extension modules under one directory

Can sources for discrete ruby extension modules live in the same directory, controlled by the same extconf.rb script? Background: I ve a project with two extension modules, foo.so and bar.so which ...

Text Editor for Ruby-on-Rails

guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an ...

热门标签