简体   繁体   English

使用脚本从 Vpython 中提取 Canvas 或 Jpeg 图像渲染 Output

[英]Extract Canvas or Jpeg Image out of Vpython Rendered Output using script

Hope you are all doing well.希望你们一切都好。

I am trying to draw a 3D-text which I want to embed into an HTML document.我正在尝试绘制要嵌入到 HTML 文档中的 3D 文本。 So for this I found vpython which can draw 3D text and render result in browser window using CANVAS.因此,为此我找到了 vpython,它可以绘制 3D 文本并使用 CANVAS 在浏览器 window 中呈现结果。

Is there any easy way to get that rendered canvas or raster image (jpeg/png) exported right from the the vpython script?.有什么简单的方法可以直接从 vpython 脚本导出渲染的 canvas 或光栅图像 (jpeg/png)?

[Here is jupyter notebook result] [1]: https://i.stack.imgur.com/Z2YUH.png [这里是 jupyter notebook 结果] [1]: https://i.stack.imgur.com/Z2YUH.png

Same code executed from python file launches the browser having rendered HTML page.从 python 文件执行的相同代码会启动呈现 HTML 页面的浏览器。

Once I get rendered canvas or even raster image I will be able to use it.一旦我得到渲染 canvas 甚至光栅图像,我就可以使用它。

If I understand correctly, the following approach should work: Go to webvpython.org and log in with a Google account.如果我理解正确,以下方法应该有效:Go 到 webvpython.org 并使用 Google 帐户登录。 Create a new file, which will have a header "GlowScript 3.2 VPython".创建一个新文件,其中包含 header“GlowScript 3.2 VPython”。 Add your 3D text statement such as text(text='Hello').添加您的 3D 文本语句,例如 text(text='Hello')。 Click "Run this program" to check that it looks the way you want, then click "Edit this program" followed by clicking "Share or export this program".单击“运行此程序”以检查它是否符合您的要求,然后单击“编辑此程序”,然后单击“共享或导出此程序”。 Copy the JavaScript code that has been transpiled from your (very short) VPython program and store it in an.html file.复制从您的(非常短的)VPython 程序转译的 JavaScript 代码,并将其存储在 .html 文件中。 Double-click that.html file, which will invoke a browser and display the 3D text.双击 .html 文件,这将调用浏览器并显示 3D 文本。 You can install the JavaScript code in your own html and/or use iframe to embed it.您可以在自己的 html 中安装 JavaScript 代码和/或使用 iframe 嵌入它。 Alternatively, if you simply want to create an image, use scene.capture(some file name) to store a.png file into your Download folder.或者,如果您只想创建图像,请使用 scene.capture(some file name) 将 .png 文件存储到您的下载文件夹中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM