S3-standing-wave by matterandinteractions

36 views
Skip to first unread message

Frank Koslowski

unread,
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
    rate(100)

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

unread,
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.

Bruce

Frank Koslowski

unread,
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.

Frank

Bruce Sherwood

unread,
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.

Bruce
Reply all
Reply to author
Forward
0 new messages