如何/在哪里执行生成 SVG 的 Golang 二进制文件?

huangapple go评论106阅读模式
英文:

How/Where to execute a golang binary that generates svg

问题

我正在尝试通过阅读《Go程序设计语言》来学习Golang。我正在第三章,书中有一个示例程序,引用一下书中的描述:

绘制一个二元函数 z = f(x, y) 的线框网格三维表面。

当我执行该程序时,它生成了类似于以下的输出:

<svg xmlns='http://www.w3.org/2000/svg' style='stroke: grey; fill: white; stroke-width: 0.7' width='600' height='320'>
<polygon points='302.5980762113533,6.408069589119515 300,5.765251108350995 297.4019237886467,6.408069589119515 300,7.256408337069842'/>
<polygon points='300,7.256408337069842 297.4019237886467,6.408069589119515 294.80384757729337,7.2672587589197954 297.4019237886467,8.356773520066966'/>
<polygon points='297.4019237886467,8.356773520066966 294.80384757729337,7.2672587589197954 292.20577136594005,8.368149318273655 294.80384757729337,9.724223435392517'/>
<polygon points='294.80384757729337,9.724223435392517 292.20577136594005,8.368149318273655 289.60769515458674,9.724590598214316 292.20577136594005,11.361343197756081'/>
<!-- 更多的多边形点 -->
</svg>

在该章节的后面,有一些关于修改该程序的练习,因此我希望能够运行它并获得正确的图形输出,而不仅仅是打印出所有的点。

如果有关于如何做到这一点的任何帮助,将不胜感激。到目前为止,我只尝试在iTerm中运行该程序。

编辑

我还尝试在Chrome的Go Playground中运行它。

英文:

I'm trying to learn Golang by making my way through The Go Programming Language. I'm on Ch3 and there's an example prgramming that, to quote the book:

> plots a function of two variables z = f(x, y) as a wire mesh 3-D surface.

When I execute the program it generates something like this:

&lt;svg xmlns=&#39;http://www.w3.org/2000/svg&#39; style=&#39;stroke: grey; fill: white; stroke-width: 0.7&#39; width=&#39;600&#39; height=&#39;320&#39;&gt;&lt;polygon points=&#39;302.5980762113533,6.408069589119515 300,5.765251108350995 297.4019237886467,6.408069589119515 300,7.256408337069842&#39;/&gt;
&lt;polygon points=&#39;300,7.256408337069842 297.4019237886467,6.408069589119515 294.80384757729337,7.2672587589197954 297.4019237886467,8.356773520066966&#39;/&gt;
&lt;polygon points=&#39;297.4019237886467,8.356773520066966 294.80384757729337,7.2672587589197954 292.20577136594005,8.368149318273655 294.80384757729337,9.724223435392517&#39;/&gt;
&lt;polygon points=&#39;294.80384757729337,9.724223435392517 292.20577136594005,8.368149318273655 289.60769515458674,9.724590598214316 292.20577136594005,11.361343197756081&#39;/&gt; 

... many more polygon points

&lt;/svg&gt;

Further on in the chapter there are exercises concerning modifying this program so I'd like to run it and get a proper graphical output instead of just a printout of all the points.

Any help on how to do this would be much appreciated. So far I've only tried running the program in iTerm.

Edit

I've also tried running it in the Go playground in Chrome.

答案1

得分: 3

要查看生成的SVG文件,您需要在SVG查看器(例如浏览器)中打开它(作为文件)。将输出保存为SVG文件的最简单方法是将程序的输出重定向到文件中:

./my_program > file.svg

现在,您可以双击file.svg文件并查看您的图表。

英文:

To view the resulting SVG, you need to open it (as a file) in a SVG viewer (a browser, for example). The easiest way to save that output into a SVG file is to redirect the output of your program into a file:

./my_program &gt; file.svg

Now you can double-click file.svg and see your chart.

huangapple
  • 本文由 发表于 2017年9月7日 17:42:08
  • 转载请务必保留本文链接:https://go.coder-hub.com/46093045.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定