BruceSherwood / vpython-jupyter

This repository has been moved to https://github.com/vpython/vpython-jupyter
64 stars 33 forks source link

programs run only once #32

Closed jonschull closed 6 years ago

jonschull commented 6 years ago

I'm delighted to see that you've carried vpython into the 21st century!

I find that programs run once. When I rerun a cell a second time, nothing happens.

If I restart the kernel I get another shot.

(I now see this is a documented issue at vpython.org (suggest it be documented on github too).

"Currently, to re-run a VPython program you need to click the circular arrow icon to "restart the kernel" and then click the red-highlighted button, then click in the first cell, then click the run icon."

jcoady commented 6 years ago

Hi

Just add the line

scene = canvas()

near the beginning of your vpython program and it will display the scene each time the notebook cell is executed. See documentation

http://www.glowscript.org/docs/VPythonDocs/canvas.html

John

From: "jonschull" notifications@github.com To: "BruceSherwood/vpython-jupyter" vpython-jupyter@noreply.github.com Cc: "Subscribed" subscribed@noreply.github.com Sent: Thursday, December 14, 2017 4:09:20 AM Subject: [BruceSherwood/vpython-jupyter] programs run only once (#32)

I'm delighted to see that you've carried vpython into the 21st century!

I find that programs run once. When I rerun a cell a second time, nothing happens.

If I restart the kernel I get another shot.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub , or mute the thread .

BruceSherwood commented 6 years ago

Both vpython.org and this README file now say this:

Currently, to re-run a VPython program you need to click the circular arrow icon to "restart the kernel" and then click the red-highlighted button, then click in the first cell, then click the run icon. Alternatively, if you insert "scene = canvas()" at the start of your program, you can rerun the program without restarting the kernel.

jonschull commented 6 years ago

thanks John

By the way, I've discovered that Thonny provides a self-contained python3 installation (without disrupting my py2.7 world), and happily installs and runs "vpython7 for jupyter notebooks," provides a live shell while the program runs, and renders vpython as Glowscript in a separate browser window.

This is looks like a promising vpython programming environment and I hope you check it out.

On the other hand, when I paste the resulting same code into the editor at glowscript.org it behaves a little differently.

Here's a little test program.... In Tholly, it behaves as I think it should.

!/usr/bin/env pythonw

GlowScript 2.6 VPython

from vpython import * autoscale = True autocenter = True #this doesn't seem to be working

scene.width = scene.height = 800

scene.background = color.gray(0.8)

print("Click to pick an object, make it red, create a child, and grow the parent.")

def cube_root(num): return num ** (1. / 3)

def get_radius(volume): return cube_root( (volume / pi) * (3./ 4) )

initialRadius = get_radius(1) things=[]

spheres={} spheres['0']=sphere(color=color.white, radius=get_radius(1), volume=1, children=[])

def getevent(): hit = scene.mouse.pick if hit != None: hit.color = color.yellow hit.volume += 1 # volume = children hit.radius = get_radius(hit.volume) #radius to show volume/children

    hit.children.append(sphere(pos = hit.pos + vector(0,-(hit.radius +

initialRadius),0), color = color.green, radius=initialRadius,volume=1)) print(hit.dict) print() print( s0.dict)

scene.bind("mousedown", getevent)

jschull@e-NABLE.org cell: 585-738-6696 skype:jonschull Founder, e-NABLE http://e-NABLE.org: volunteers worldwide making free, 3D printed prosthetics Innovation Fellow, JMK Innovation Fund http://www.jmkfund.org/awardee/jon-schull/

On 14 December 2017 at 08:08, john notifications@github.com wrote:

Hi

Just add the line

scene = canvas()

near the beginning of your vpython program and it will display the scene each time the notebook cell is executed. See documentation

http://www.glowscript.org/docs/VPythonDocs/canvas.html

John

From: "jonschull" notifications@github.com To: "BruceSherwood/vpython-jupyter" vpython-jupyter@noreply.github.com Cc: "Subscribed" subscribed@noreply.github.com Sent: Thursday, December 14, 2017 4:09:20 AM Subject: [BruceSherwood/vpython-jupyter] programs run only once (#32)

I'm delighted to see that you've carried vpython into the 21st century!

I find that programs run once. When I rerun a cell a second time, nothing happens.

If I restart the kernel I get another shot.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub , or mute the thread .

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/BruceSherwood/vpython-jupyter/issues/32#issuecomment-351705983, or mute the thread https://github.com/notifications/unsubscribe-auth/AADRqT62yGeDbRVLBKjPZeIqq0cOEYfAks5tAR2wgaJpZM4RB96D .

jonschull commented 6 years ago

Correction. Behavior is the same in Tholly and Glowscript (which is good)!

jschull@e-NABLE.org cell: 585-738-6696 skype:jonschull Founder, e-NABLE http://e-NABLE.org: volunteers worldwide making free, 3D printed prosthetics Innovation Fellow, JMK Innovation Fund http://www.jmkfund.org/awardee/jon-schull/

On 18 December 2017 at 14:03, Jon Schull jschull@gmail.com wrote:

thanks John

By the way, I've discovered that Thonny provides a self-contained python3 installation (without disrupting my py2.7 world), and happily installs and runs "vpython7 for jupyter notebooks," provides a live shell while the program runs, and renders vpython as Glowscript in a separate browser window.

This is looks like a promising vpython programming environment and I hope you check it out.

On the other hand, when I paste the resulting same code into the editor at glowscript.org it behaves a little differently.

Here's a little test program.... In Tholly, it behaves as I think it should.

!/usr/bin/env pythonw

GlowScript 2.6 VPython

from vpython import * autoscale = True autocenter = True #this doesn't seem to be working

scene.width = scene.height = 800

scene.background = color.gray(0.8)

print("Click to pick an object, make it red, create a child, and grow the parent.")

def cube_root(num): return num ** (1. / 3)

def get_radius(volume): return cube_root( (volume / pi) * (3./ 4) )

initialRadius = get_radius(1) things=[]

spheres={} spheres['0']=sphere(color=color.white, radius=get_radius(1), volume=1, children=[])

def getevent(): hit = scene.mouse.pick if hit != None: hit.color = color.yellow hit.volume += 1 # volume = children hit.radius = get_radius(hit.volume) #radius to show volume/children

    hit.children.append(sphere(pos = hit.pos + vector(0,-(hit.radius +

initialRadius),0), color = color.green, radius=initialRadius,volume=1)) print(hit.dict) print() print( s0.dict)

scene.bind("mousedown", getevent)

jschull@e-NABLE.org cell: 585-738-6696 skype:jonschull Founder, e-NABLE http://e-NABLE.org: volunteers worldwide making free, 3D printed prosthetics Innovation Fellow, JMK Innovation Fund http://www.jmkfund.org/awardee/jon-schull/

On 14 December 2017 at 08:08, john notifications@github.com wrote:

Hi

Just add the line

scene = canvas()

near the beginning of your vpython program and it will display the scene each time the notebook cell is executed. See documentation

http://www.glowscript.org/docs/VPythonDocs/canvas.html

John

From: "jonschull" notifications@github.com To: "BruceSherwood/vpython-jupyter" vpython-jupyter@noreply.github.com Cc: "Subscribed" subscribed@noreply.github.com Sent: Thursday, December 14, 2017 4:09:20 AM Subject: [BruceSherwood/vpython-jupyter] programs run only once (#32)

I'm delighted to see that you've carried vpython into the 21st century!

I find that programs run once. When I rerun a cell a second time, nothing happens.

If I restart the kernel I get another shot.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub , or mute the thread .

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/BruceSherwood/vpython-jupyter/issues/32#issuecomment-351705983, or mute the thread https://github.com/notifications/unsubscribe-auth/AADRqT62yGeDbRVLBKjPZeIqq0cOEYfAks5tAR2wgaJpZM4RB96D .

BruceSherwood commented 6 years ago

Good to know that it works after all, and good to hear of Thonny, which was news to me. These notes would be useful to more people if you were to post to the VPython forum, since then many users would benefit. I don't think many VPython users look at the repository.