Another thing you can try if you want to run a webvpython program inside a jupyter notebook is to use the "%%html" magic command with the -- isolated option in a jupyter notebook cell
as the first line in a notebook cell. Then you can run one of the example webvpython programs in this notebook cell by doing the following.
1. Choose a webvpython example programs from among those listed here.
4. Copy and Paste the code in the box in the webpage for this link into the notebook cell containing the first line %%html --isolated . The jupyter notebook should contain the copied code from webvpython. Run the code in the cell and you should see the vpython program running in the output of the cell in the jupyter notebook.
<div id="glowscript" class="glowscript">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link type="text/css" href="
https://www.glowscript.org/css/redmond/2.1/jquery-ui.custom.css" rel="stylesheet" />
<link type="text/css" href="
https://www.glowscript.org/css/ide.css" rel="stylesheet" />
<script type="text/javascript" src="
https://www.glowscript.org/lib/jquery/2.1/jquery.min.js"></script>
<script type="text/javascript" src="
https://www.glowscript.org/lib/jquery/2.1/jquery-ui.custom.min.js"></script>
<script type="text/javascript" src="
https://www.glowscript.org/package/glow.3.2.min.js"></script>
<script type="text/javascript" src="
https://www.glowscript.org/package/RSrun.3.2.min.js"></script>
<script type="text/javascript"><!--//--><![CDATA[//><!--
// START JAVASCRIPT
;(function() {;
var ρσ_modules = {};
ρσ_modules.pythonize = {};
(function(){
function strings() {
var string_funcs, exclude, name;
string_funcs = set("capitalize strip lstrip rstrip islower isupper isspace lower upper swapcase center count endswith startswith find rfind index rindex format join ljust rjust partition rpartition replace split rsplit splitlines zfill".split(" "));
if (!arguments.length) {
exclude = (function(){
var s = ρσ_set();
s.jsset.add("split");
s.jsset.add("replace");
return s;
})();
} else if (arguments[0]) {
exclude = Array.prototype.slice.call(arguments);
} else {
exclude = null;
}
if (exclude) {
string_funcs = string_funcs.difference(set(exclude));
}
var ρσ_Iter0 = string_funcs;
ρσ_Iter0 = ((typeof ρσ_Iter0[Symbol.iterator] === "function") ? (ρσ_Iter0 instanceof Map ? ρσ_Iter0.keys() : ρσ_Iter0) : Object.keys(ρσ_Iter0));
for (var ρσ_Index0 of ρσ_Iter0) {
name = ρσ_Index0;
(ρσ_expr_temp = String.prototype)[(typeof name === "number" && name < 0) ? ρσ_expr_temp.length + name : name] = (ρσ_expr_temp = ρσ_str.prototype)[(typeof name === "number" && name < 0) ? ρσ_expr_temp.length + name : name];
}
};
if (!strings.__module__) Object.defineProperties(strings, {
__module__ : {value: "pythonize"}
});
ρσ_modules.pythonize.strings = strings;
})();
async function __main__() {
"use strict";
var display = canvas;
var scene = canvas();
var version, print, arange, __name__, type, ρσ_ls, G, giant, dwarf, dt, r, F;
version = ρσ_list_decorate([ "3.2", "glowscript" ]);
Array.prototype['+'] = function(r) {return this.concat(r)}
Array.prototype['*'] = function(r) {return __array_times_number(this, r)}
window.__GSlang = "vpython";
print = GSprint;
arange = range;
__name__ = "__main__";
type = pytype;
var strings = ρσ_modules.pythonize.strings;
strings();
"6";
scene.caption = "To rotate \"camera\", drag with right button or Ctrl-drag.\nTo zoom, drag with middle button or Alt/Option depressed, or use scroll wheel.\n On a two-button mouse, middle is left + right.\nTo pan left/right and up/down, Shift-drag.\nTouch screen: pinch/extend to zoom, swipe or two-finger rotate.";
"7";
scene.forward = vector(0, 1["-u"]()["*"](.3), 1["-u"]()["*"](1));
"9";
G = 6.7e-11;
"11";
giant = ρσ_interpolate_kwargs.call(this, sphere, [ρσ_desugar_kwargs({pos: vector(1["-u"]()["*"](1e11), 0, 0), radius: 2e10, color: color.red, make_trail: true, trail_type: "points", interval: 10, retain: 50})]);
"13";
giant.mass = 2e30;
"14";
giant.p = vector(0, 0, 1["-u"]()["*"](1e4))["*"](giant.mass);
"16";
dwarf = ρσ_interpolate_kwargs.call(this, sphere, [ρσ_desugar_kwargs({pos: vector(15e10, 0, 0), radius: 1e10, color: color.yellow, make_trail: true, interval: 10, retain: 50})]);
"18";
dwarf.mass = 1e30;
"19";
dwarf.p = 1["-u"]()["*"](giant.p);
"21";
dt = 1e5;
"22";
while (true) {
"23";
(await rate(200));
"24";
r = dwarf.pos["-"](1["*"](giant.pos));
"25";
F = G["*"](giant.mass)["*"](dwarf.mass)["*"](r.hat)["/"](Math.pow(mag(r), 2));
"26";
giant.p = giant.p["+"](F["*"](dt));
"27";
dwarf.p = dwarf.p["-"](1["*"](F)["*"](dt));
"28";
giant.pos = giant.pos["+"](giant.p["/"](giant.mass)["*"](dt));
"29";
dwarf.pos = dwarf.pos["+"](dwarf.p["/"](dwarf.mass)["*"](dt));
}
};
if (!__main__.__module__) Object.defineProperties(__main__, {
__module__ : {value: null}
});
;$(function(){ window.__context = { glowscript_container: $("#glowscript").removeAttr("id") }; __main__() })})()
// END JAVASCRIPT
//--><!]]></script>
</div>