Updating shape of extrusion object

32 views
Skip to first unread message

pri...@gmail.com

unread,
Aug 8, 2022, 4:47:27 PM8/8/22
to Glowscript Users
How can I update the shape (and path) of an extrusion object with a slider?
The following simple example is far from perfect:

If possible, I would like to update the shape and path without the while loop in the same way as is possible with the length of the rod.


Poul Riis

Bruce Sherwood

unread,
Aug 8, 2022, 5:24:48 PM8/8/22
to Glowscript Users
An extrusion is a compound and has the attributes of a box. It is not possible to change the path or shape.

Bruce

pri...@gmail.com

unread,
Aug 8, 2022, 5:30:51 PM8/8/22
to Glowscript Users
Can I then delete the compound and redraw it whenever the slider modifies the path and/or shape?

Poul Riis

Bruce Sherwood

unread,
Aug 8, 2022, 6:38:47 PM8/8/22
to Glowscript Users
Of course. Just make it invisible and create a new one.

Bruce

pri...@gmail.com

unread,
Aug 9, 2022, 2:08:07 AM8/9/22
to Glowscript Users
But won't that will fill the memory with hundreds of objects?  Even if that may not be a problem I would find it better to delete old objects...

Poul Riis

mandag den 8. august 2022 kl. 23.24.48 UTC+2 skrev Bruce Sherwood:

Bruce Sherwood

unread,
Aug 9, 2022, 1:05:02 PM8/9/22
to Glowscript Users
Oddly, no, it's really not a memory problem. When I run the program below and observe the memory usage, I find that 1e4 extrusions are created and then made invisible in 10 seconds with a memory rise of 1e9 bytes of CPU memory. That's 1e9/1e4/10 = 1e4 bytes per second, or only 10 kilobytes per second. It's fortunate that this is the case, since the documentation says this:

Deleting an Object

To hide a VPython object just make it invisible: ball.visible = False. This does not delete the object from computer memory, and you can make it visible again later.

Currently it is not possible to use del ball to delete a Web VPython object.

Web VPython 3.2
scene.range = 8
sphere(radius=0.5)
p = paths.rectangle(width=10, height=10)
s = shapes.rectangle(width=2, height=3)
t = clock()
n = 0
while True:
    rate(1000)
    ex = extrusion(path=p, shape=s)
    ex.visible = False
    n += 1
    if clock()-t > 10: break
print(n)
Reply all
Reply to author
Forward
0 new messages