S3-standing-wave by matterandinteractions

Skip to first unread message

Frank Koslowski

Aug 27, 2022, 3:53:19 PM8/27/22
to Glowscript Users
while True:
    left.origin.x = xleft
    right.origin.x = xright
    xleft += dx
    xright -= dx
    if xleft > 0:
        xleft -= lamb
    if xright < -lamb:
        xright += lamb
    i = 0
    for x in arange(0,10*lamb+3*dx/2,dx):
        yleft = yright = 0
        if x < xleft+12*lamb:
            yleft = left.point(int(round((x-xleft)/dx))).pos.y
        if x > xright:
            yright = right.point(int(round((x-xright)/dx))).pos.y
        wave.modify(i, y=yleft+yright)
        i += 1

When run in either Jupyter Notebook, or PyCharm,
using vpython ver: 7.6.4,
both "/dx))).pos.y" calls were found to produce the following errors:

Traceback (most recent call last):
  File "H:/Py-Lessons/VPython_StandingWave.py", line 84, in <module>
    yleft = left.point(int(round((x - xleft) / dx))).pos.y 
AttributeError: 'dict' object has no attribute 'pos'

Message has been deleted

Bruce Sherwood

Aug 28, 2022, 2:20:41 PM8/28/22
to Glowscript Users
Thanks very much for reporting this error.  The code should have been this (and it has been corrected in its Web VPython form):

            yleft = left.point(int(round((x-xleft)/dx)))['pos'].y
        if x > xright:
            yright = right.point(int(round((x-xright)/dx)))['pos'].y

When that code was run in Web VPython there was no execution error, because after transpiling to JavaScript it works to say dictionary.pos instead of dictionary['pos'], whereas Python doesn't accept this.


Frank Koslowski

Sep 3, 2022, 6:20:48 PM9/3/22
to Glowscript Users
Thanks for that!
Though the program now does work in Jupyter Notebook with Python 3.9,
it is still very slow compared to  what we see in the Glowscript Demo environment.


Bruce Sherwood

Sep 3, 2022, 8:05:54 PM9/3/22
to Glowscript Users
Yes. The reason it's slow with installed Python is that a very large amount of data must be sent regularly  from the Python program to the browser. A better structure would be to make curves at least twice the width of the canvas and then manipulate the curve's origin, not the individual points. Then it should run fine with installed Python.

Reply all
Reply to author
0 new messages