Clear screen

642 views
Skip to first unread message

brendan...@students.berkeley.net

unread,
Feb 2, 2014, 5:21:46 PM2/2/14
to vpytho...@googlegroups.com
Is there a way to clear the screen? I made this code:
from visual import *
scene.range = 10
def erase(evt):
    arrow.pos = vector(0,0,0)
    arrow.axis = vector(0,0,0)
scene.bind('keydown', erase)
while(0 == 0):
    ev = scene.mouse.getclick()
    click1 = sphere(pos = ev.pos, radius = .000001)
    ev = scene.mouse.getclick()
    click2 = sphere(pos = ev.pos, radius = .000001)
    arrow = arrow(pos = click1.pos, axis = click2.pos - click1.pos)

Using erase only gets rid of the last arrow. is there a way to make all the arrows be deleted when you press a key?

Bruce Sherwood

unread,
Feb 2, 2014, 6:16:41 PM2/2/14
to vpytho...@googlegroups.com
From the documentation on display windows:

objects A list of all the visible objects in the display; invisible objects and lights are not listed (scene.lights is a list of existing lights). For example, the following makes all visible boxes in the scene red:

    for obj in scene2.objects: 
        if isinstance(obj, box):
            obj.color = color.red


If the last line is obj.visible = False, all the objects disappear.

Brendan Banfield

unread,
Feb 2, 2014, 6:27:39 PM2/2/14
to vpytho...@googlegroups.com
Thanks!


--
You received this message because you are subscribed to a topic in the Google Groups "VPython-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/vpython-users/bFLGQJsIb80/unsubscribe.
To unsubscribe from this group and all its topics, send an email to vpython-user...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Brendan Banfield

unread,
Feb 2, 2014, 9:23:30 PM2/2/14
to vpytho...@googlegroups.com
Wait... what should the exact code be?  I can't get this to work.

Bruce Sherwood

unread,
Feb 2, 2014, 10:51:13 PM2/2/14
to vpytho...@googlegroups.com
Sorry, I plucked the documentation out of context. The default display is named "scene", so the for loop goes over scene.objects rather than scene2.objects, and you want to make all objects invisible, not just boxes. So here is the exact code:

for obj in scene.objects: 
    obj.visible = False

Brendan Banfield

unread,
Feb 2, 2014, 11:01:41 PM2/2/14
to vpytho...@googlegroups.com
Thanks! It's working now!


--
Reply all
Reply to author
Forward
0 new messages