How to embed Vpython program on html & Change values dynamically

76 views
Skip to first unread message

Pat Facunla

unread,
Sep 3, 2022, 12:58:48 PM9/3/22
to Glowscript Users
I have a project where I would like to create a website where I can dynamically change the 
values of shapes in vpython. But I don't know if that is possible. Can someone teach me
if this is possible thanks.

Bruce Sherwood

unread,
Sep 3, 2022, 1:53:18 PM9/3/22
to Glowscript Users
The word "shapes" has several different possible meanings:

1) You can dynamically change the length, width, and height of almost all objects.

2) You cannot dynamically change the shape attribute of an extrusion object.

3) You can dynamically change the shape of triangle and quad objects. Here are two examples, and the documentation:




Bruce

Pat Facunla

unread,
Sep 4, 2022, 3:13:09 PM9/4/22
to Glowscript Users
Thanks Bruce,

But I have another question.

1.) Is it possible to still change values of a VPython program after embedding it on a website. Like I would want to create a program in vpython
      where the data is always changing via real time.

Harlan Gilbert

unread,
Sep 4, 2022, 3:29:05 PM9/4/22
to glowscri...@googlegroups.com
Any property can be updated dynamically.  For example, try

scene.range = 12
ball = sphere()

for i in range(2,10):
   rate(2)             #sets frame rate
   ball.radius = i    #grows radius
   ball.color = ball.color* 0.8 + vec(0,0,.1)   #Shifts from red to purple

You can also use various sliders and buttons to update this from user input

--

---
You received this message because you are subscribed to the Google Groups "Glowscript Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to glowscript-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/glowscript-users/8a7dedb4-7065-42f7-9869-8ed14a4374dfn%40googlegroups.com.


--
Harlan Gilbert, Ph.D.
High School Chair and Math, Physics, Computer Science, and Philosophy Teacher
Green Meadow Waldorf High School
Chestnut Ridge, NY 10977

Bruce Sherwood

unread,
Sep 4, 2022, 4:56:41 PM9/4/22
to Glowscript Users
There may be a way for an embedded Web VPython program to read new data. Perhaps you could use the Web VPython function get_libary() to read the contents of a JavaScript file. The program tinyurl.com/lSurfaceCharge uses this function to read data that look like this:

var polarized_block = {} 

 polarized_block.get_W = function () {return 0.000100} 

 polarized_block.get_source_locs = function() { 
   return [ [-0.010000,0.000000,0.000000] ] 

 polarized_block.get_source_charges = function() {
     return [ 1.000000e-15 ] 

 polarized_block.get_qs = function() { return [ 
    -3.486053e-20, -2.577023e-20, -2.344574e-20, -2.228135e-20, -2.156798e-20, -2.108724e-20, -2.074490e-20, -2.049237e-20, -2.030160e-20, -2.015512e-20,      -2.004140e-20, -1.995252e-20, -1.988286e-20, -1.982834e-20, -1.978594e-20, -1.975344e-20, -1.972916e-20, -1.971192e-20, -1.970087e-20, -1.969547e-20,       -1.969547e-20, -1.970087e-20, -1.971192e-20, -1.972916e-20, -1.975344e-20, 
     etc.

In this case the data are unchanging, but presumably if you could arrange for there to be changing data in a JavaScript file, you could use this scheme.

Bruce

Bruce Sherwood

unread,
Sep 4, 2022, 4:58:25 PM9/4/22
to Glowscript Users
I'm guessing that this may be more straight-forward with VPython running with installed Python than with Web VPython.

Bruce

Pat Facunla

unread,
Sep 6, 2022, 1:04:53 PM9/6/22
to Glowscript Users
Thanks everybody for helping, It's working now 

Pat
Reply all
Reply to author
Forward
0 new messages