Skip to content

Commit 05fb448

Browse files
committed
Fixed some nasty bugs associated with assigning a compound to the correct canvas
1 parent 64c0e7a commit 05fb448

File tree

4 files changed

+48
-13
lines changed

4 files changed

+48
-13
lines changed

docs/VPythonDocs/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@
9292
<p class="Normal">VPython makes it unusually easy to write programs that generate navigable real-time 3D animations. It is based on the Python programming language which is widely used in introductory programming courses thanks to its clean design, and it is also widely used in science and business.</p>
9393
<p class="Normal">VPython was originated by David Scherer in 2000. In 2011 David Scherer and Bruce Sherwood initiated the development of GlowScript, a similar programming environment but which runs in a browser. In 2014 it became possible to use RapydScript, a programming language very similar to Python, to support VPython programs in the GlowScript environment. This
9494
documentation describes VPython and includes notes on what is not currently available in the GlowScript version. </p>
95-
<p class="Normal">The version of VPython that runs with a standard installed Python is referred to as &quot;classic&quot; VPython. John Coady has implemented VPython to run in <strong><a href="http://ipython.org/" target="_blank">iPython</a></strong> notebooks, with his <strong><a href="https://pypi.python.org/pypi/IVisual/0.1.87" target="_blank">ivisual</a></strong> module.</p>
95+
<p class="Normal">The version of VPython that runs with a standard installed Python is referred to as &quot;classic&quot; VPython. John Coady has implemented VPython to run in <strong><a href="http://ipython.org/" target="_blank">iPython</a></strong> notebooks, with his <strong><a href="https://pypi.python.org/pypi/IVisual/0.1.87" target="_blank">ivisual</a></strong> module. Aaron Titus has posted a useful summary of the various ways to <strong><a href="http://physicslogos.blogspot.com/2015/04/vpython-anaconda-and-ivisual.html" target="_blank">install and use VPython</a></strong>. </p>
9696
<p class="Normal">For a quick introduction, see the following YouTube videos. These were created for classic VPython but are just as useful for learning the browser version. </p>
9797
<blockquote>
9898
<p class="Normal"><a href="http://vpython.org/video01.html" target="_blank"><strong>3D Objects</strong></a></p>

lib/glow/api_misc.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,6 @@
353353
degrees: function degrees(rad) { return (rad * 180 / Math.PI) },
354354

355355
sleep: sleep,
356-
//rate: rate,
357356
update: update,
358357
print: print,
359358
print_options: print_options,

lib/glow/primitives.js

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,7 @@
624624
this.canvas = args.canvas
625625
delete args.canvas
626626
} else if (args.display !== undefined) {
627-
obj.canvas = obj.display = args.display
627+
this.canvas = args.display
628628
delete args.display
629629
} else {
630630
this.canvas = canvas.selected
@@ -669,7 +669,10 @@
669669
this.__opacity = value
670670
this.canvas.__vertex_changed[this.__id] = this
671671
}
672-
672+
},
673+
display: {
674+
get: function() { return this.canvas },
675+
set: function(value) { throw new Error('Cannot change display of existing object')}
673676
},
674677
texpos: new attributeVector(null, 0,0,0),
675678
bumpaxis: new attributeVector(null, 1,0,0),
@@ -741,6 +744,10 @@
741744
this.__change()
742745
}
743746
},
747+
display: {
748+
get: function() { return this.canvas },
749+
set: function(value) { throw new Error('Cannot change display of existing object')}
750+
},
744751
pos: {
745752
get: function() { tri_quad_error('triangle', 'pos') },
746753
set: function(value) { tri_quad_error('triangle', 'pos') }
@@ -857,6 +864,10 @@
857864
get: function() { tri_quad_error('quad', 'shininess') },
858865
set: function(value) { tri_quad_error('quad', 'shininess') }
859866
},
867+
display: {
868+
get: function() { return this.canvas },
869+
set: function(value) { throw new Error('Cannot change display of existing object')}
870+
},
860871
__prev_texture: null,
861872
__prev_bumpmap: null,
862873
__update: function () { this.__model.id_object[this.__id] = this },
@@ -1038,6 +1049,14 @@
10381049
},
10391050
origin: new attributeVector(null, 0,0,0),
10401051
radius: 0,
1052+
display: {
1053+
get: function() { return this.canvas },
1054+
set: function(value) { throw new Error('Cannot change display of existing object')}
1055+
},
1056+
display: {
1057+
get: function() { return this.canvas },
1058+
set: function(value) { throw new Error('Cannot change display of existing object')}
1059+
},
10411060
__no_autoscale: false,
10421061
__get_extent: function (ext) {
10431062
if (this.__no_autoscale) return
@@ -1335,7 +1354,7 @@
13351354
if (this.__curve !== undefined) {
13361355
this.__curve.clear()
13371356
} else {
1338-
this.__curve = curve({__no_autoscale:true})
1357+
this.__curve = curve({canvas:this.canvas, __no_autoscale:true})
13391358
}
13401359
}
13411360

@@ -1376,6 +1395,10 @@
13761395
property.declare( vp_helix.prototype, {
13771396
axis: new attributeVectorAxis(null, 1,0,0),
13781397
size: new attributeVectorSize(null, 1,2,2),
1398+
display: {
1399+
get: function() { return this.canvas },
1400+
set: function(value) { throw new Error('Cannot change display of existing object')}
1401+
},
13791402
radius: {
13801403
get: function() { return this.__size.__y/2 },
13811404
set: function(value) {
@@ -1493,12 +1516,13 @@
14931516
}
14941517

14951518
function make_extrusion(args) {
1496-
var center, pos, shapelist, col, up, opacity
1519+
var center, pos, shapelist, col, up, opacity, can
1520+
can = args.canvas
14971521
pos = (args.pos === undefined) ? vec(0,0,0) : args.pos
14981522
if (args.shape === undefined) {
14991523
throw new Error('An extrusion object needs a shape attribute.')
15001524
} else shapelist = args.shape
1501-
up = (args.up === undefined) ? canvas.selected.up : args.up
1525+
up = (args.up === undefined) ? can.up : args.up
15021526
col = (args.color === undefined) ? color.white : args.color
15031527
opacity = (args.opacity === undefined) ? 1 : args.opacity
15041528

@@ -1612,7 +1636,11 @@
16121636
}
16131637
i++
16141638
}
1615-
return compound(quads)
1639+
var current = canvas.selected
1640+
canvas.selected = can
1641+
var comp = compound(quads)
1642+
canvas.selected = current
1643+
return comp
16161644
}
16171645

16181646
function extrusion(args) {return initObject(this, extrusion, args) }
@@ -1626,6 +1654,10 @@
16261654
get: function() {throw new Error("An extrusion has no radius.")},
16271655
set: function(val) {throw new Error("An extrusion has no radius.")}
16281656
},
1657+
display: {
1658+
get: function() { return this.canvas },
1659+
set: function(value) { throw new Error('Cannot change display of existing object')}
1660+
},
16291661
origin: new attributeVector(null, 0,0,0),
16301662
__initialize: true,
16311663
pos: {
@@ -1684,7 +1716,7 @@
16841716
}
16851717

16861718
if (this.__initialize) {
1687-
this.__comp = make_extrusion({pos:this.__pos, shape:this.__shape, color:this.__color, opacity:this.__opacity})
1719+
this.__comp = make_extrusion({canvas:this.canvas, pos:this.__pos, shape:this.__shape, color:this.__color, opacity:this.__opacity})
16881720
this.__lastsize = this.__size
16891721
this.__lastcolor = this.__color
16901722
this.__lastopacity = this.__opacity
@@ -1735,7 +1767,7 @@
17351767
}
17361768

17371769
if (this.__initialize) {
1738-
this.__comp = make_extrusion( {pos:paths.circle({make_ring:true, radius:0.5*(this.__size.y-this.__size.x)}),
1770+
this.__comp = make_extrusion( {canvas:this.canvas, pos:paths.circle({make_ring:true, radius:0.5*(this.__size.y-this.__size.x)}),
17391771
shape:shapes.circle({radius:0.5*this.__size.x}), color:this.__color, opacity:this.__opacity} )
17401772
this.__lastsize = this.__size
17411773
this.__lastcolor = this.__color
@@ -1755,6 +1787,10 @@
17551787
function vp_ring(args) { return initObject(this, vp_ring, args) }
17561788
subclass(vp_ring, ring)
17571789
property.declare( vp_ring.prototype, {
1790+
display: {
1791+
get: function() { return this.canvas },
1792+
set: function(value) { throw new Error('Cannot change display of existing object')}
1793+
},
17581794
size: new attributeVector(null, 0.2,2,2),
17591795
thickness: {
17601796
get: function() { return this.__size.__x/2 },

package/glow.1.1.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)