简体   繁体   中英

How to capture an output image generated by the box function of python visual module?

I am using the box() function provided by the visual module of Python. I want to capture the output image rendered by the display() function as a .png file. I am using scene.capture('test4312'). But getting an error "AttributeError: 'display' object has no attribute 'capture'". Though the output is being displayed, it is not getting stored.

Here is the code for reference.

from visual import * from visual.filedialog import get_file

scene = display(width=300, height=100,center=vector(10,7,3),background=(1,1,1)) #scene = canvas(title='3DP 4,3,-12', width=600, height=200, center=vector(5,0,0), background=(1,1,1))

fd = get_file() lines_list = fd.readlines() for i in arange(0,256,1): a,b,c = (int(val) for val in lines_list[i].split()) str1="("+str(a)+","+str(b)+","+str(c)+")"

box(pos=vector(a,b,c),size=(1,1,1),color=(i*0.01,0,0),opacity=0.6,line=true,linecolor=color.red)

box(pos=vector(a,b,c),size=(1,1,1),color=(0.015*i,0,0),opacity=0.6,line=true,linecolor=color.red)
label(pos=vector(a,b,c), text=str1,height=9,box=false,color=color.white,opacity=0)


#print(answer)

scene.capture('test4312')


Please let me know if there is any solution to this problem. I need to store the output as .png.

Regards, Somrita.

The obsolete visual module (not supported since Jan. 2016) did not have a scene.capture() function. There are two current VPython environments that you can use that do include scene.capture(): At vpython.org are instructions on installing the vpython module. At webvpython.org (or equivalently, glowscript.org) you can write VPython programs without installing any software at all; your program, which is saved in the cloud, is transpiled in the browser to JavaScript and executed in the browser. Web VPython is very convenient, but it does have the limitation that you can't import Python libraries other than a slightly incomplete random module. Web VPython programs run several times faster than pure Python programs, thanks to being converted to JavaScript. Do read https://www.glowscript.org/docs/VPythonDocs/experienced.html on the differences between visual and vpython. The main difference is that you need to write "vector(1,2,3)" or "vec(1,2,3)", not "(1,2,3)". Also, what was a "display" is now a "canvas". Note that others can run your Web VPython program without installing any software; just give a URL, such as https://www.glowscript.org/#/user/GlowScriptDemos/folder/Examples/program/ElectricMotor

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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