Skip to content

Commit e51dcee

Browse files
committed
radius=0 default for trails
1 parent 2fba648 commit e51dcee

8 files changed

Lines changed: 41 additions & 31 deletions

File tree

docs/GlowScriptDocs/curve.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@
105105
<p class="attributes"> <span class="attribute">color </span> Color
106106
of a point; if specified for the curve as a whole, it specifies the color of any points for which no specific color was given.</p>
107107
<p class="attributes"> <span class="attribute">radius</span> Radius of
108-
the cross-section of this segment of the curve; if specified for the curve as a whole, it specifies the radius of any points for which no specific radius was given.</p>
108+
the cross-section of this segment of the curve; if specified for the curve as a whole, it specifies the radius of any points for which no specific radius was given. The default radius is 0, which makes a thin curve.</p>
109109
<p class="attributes"><span class="attribute">visible</span> If False,
110110

111111
point is not displayed; if False for the curve as a whole, no points are displayed.</p>

docs/GlowScriptDocs/trail.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
<br />
7878
attach_trail(center) </p>
7979
<div></div>
80-
<p class="Normal">In summary, you can specify a trail to be constructed as a curve or a set of spheres, using the position of an object or the vector result of a function. You can specify options to control <span class="attribute">color</span>, <span class="attribute">radius</span>, <span class="attribute">retain</span>, <span class="attribute">pps</span>, and <span class="attribute">type</span>. The default radius is 0.1 times the size.y of the moving object. You can change <span class="attribute">color</span> or <span class="attribute">radius</span> and the following points will be displayed with the new attributes.</p>
80+
<p class="Normal">In summary, you can specify a trail to be constructed as a curve or a set of spheres, using the position of an object or the vector result of a function. You can specify options to control <span class="attribute">color</span>, <span class="attribute">radius</span>, <span class="attribute">retain</span>, <span class="attribute">pps</span>, and <span class="attribute">type</span>. <span class="attributes">The default for the &quot;curve&quot; option is 0, which makes a thin curve (this works best in the xy plain; if it doesn't give the result you want, set trail_radius to the desired value). The default for the &quot;points&quot; option is 0.2 times the radius, 0.1 times the height or size.y, of the moving object.</span> You can change <span class="attribute">color</span> or <span class="attribute">radius</span> and the following points will be displayed with the new attributes.</p>
8181
<p class="Normal"><strong><font color="#0000A0">start, stop, clear</font></strong></p>
8282
<div>
8383
<div> </div>

docs/VPythonDocs/curve.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@
114114
<p class="attributes"> <span class="attribute">color </span> Color
115115
of a point; if specified for the curve as a whole, it specifies the color of any points for which no specific color was given.</p>
116116
<p class="attributes"> <span class="attribute">radius</span> Radius of
117-
the cross-section of this segment of the curve; if specified for the curve as a whole, it specifies the radius of any points for which no specific radius was given.</p>
117+
the cross-section of this segment of the curve; if specified for the curve as a whole, it specifies the radius of any points for which no specific radius was given. The default radius is 0, which makes a thin curve.</p>
118118
<p class="attributes"><span class="attribute">visible</span> If False,
119119

120120
point is not displayed; if False for the curve as a whole, no points are displayed.</p>

docs/VPythonDocs/trail.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
<p class="attributes"> <span class="attribute">pps</span> If trail_type is &quot;curve&quot;, and no interval is specified, pps=15 means &quot;add a point to the curve approximately 15 times per second&quot;.</p>
8181
<p class="attributes"> <span class="attribute">retain</span> If retain=50, only the 50 most recently added points will be retained </p>
8282
<p class="attributes"> <span class="attribute">trail_color</span> The color of the curve or points<span class="Normal"></span> (default is the object's color). If you change this during the motion, later portions of the trail will have this color.</p>
83-
<p class="attributes"> <span class="attribute">trail_radius</span> The radius of the curve or points<span class="Normal"></span> (default is <span class="Normal">0.2 times the radius, 0.1 times the height or size.y, of the moving object).</span> If you change this during the motion, later portions of the trail will have this radius.</p>
83+
<p class="attributes"> <span class="attribute">trail_radius</span> The radius of the curve or points. The default for the &quot;curve&quot; option is 0, which makes a thin curve (this works best in the xy plain; if it doesn't give the result you want, set trail_radius to the desired value). The default for the &quot;points&quot; option is <span class="Normal">0.2 times the radius, 0.1 times the height or size.y, of the moving object.</span> If you change this during the motion, later portions of the trail will have this radius.</p>
8484
<p class="attributes"> <span class="attribute">clear_trail()</span> Clears all points from the existing trail before adding more. Note that setting make_trail to False stops adding more points.</p>
8585
<p class="Normal"></p>
8686
<!-- InstanceEndEditable --></td>

lib/glow/WebGLRenderer.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@
533533
if (tnow-a.__last_time > 1000/a.pps) a.__last_time = tnow
534534
else if (tnow != a.__last_time) continue
535535
}
536-
a.__trail.push({pos:pos})
536+
a.__trail.push({pos:pos, color:a.__options.color, radius:a.radius, retain:a.retain})
537537
a.__last_pos = vec(pos) // save a copy of pos
538538
}
539539
}
@@ -1066,7 +1066,7 @@
10661066
var length = p.length
10671067
var save_radius = obj.__data[15]
10681068
if (save_radius === 0) { // overall radius
1069-
obj.__data[15] = 6*canvas.__range/canvas.__width
1069+
obj.__data[15] = 4*canvas.__range/canvas.__width
10701070
}
10711071
gl.uniform4fv(program.uniforms.objectData, obj.__data) // overall curve data
10721072
for (var t=1; t<length; t++) {

lib/glow/graph.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,14 @@
520520
if (data === null) throw new Error("Must be plot(x,y) or plot(pos=[x,y]) or plot([x,y]) or plot([x,y], ...) or plot([ [x,y], ... ])")
521521
else {
522522
if (this.__type != 'line') {
523-
for (var i=0; i<data.length; i++) this.options.data.push(data[i])
523+
for (var i=0; i<data.length; i++) {
524+
if (this.__interval > 0) {
525+
this.__ninterval++
526+
if (this.__ninterval >= this.__interval) this.__ninterval = 0
527+
else continue
528+
}
529+
this.options.data.push(data[i])
530+
}
524531
} else { // for gcurve, eliminate points that are very close together
525532
var pt, x, y, xscale, yscale, dx, dy, x1, x2, y1, y2
526533
var g = this.__graph

lib/glow/primitives.js

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,12 @@
114114
obj.__trail_color = args.trail_color
115115
delete args.trail_color
116116
}
117-
obj.__trail_radius = 0.1*obj.__size.y // the default for attach_trail
117+
obj.__trail_radius = 0 //0.1*obj.__size.y // the default for attach_trail
118118
if (args.trail_radius !== undefined) {
119119
obj.__trail_radius = args.trail_radius
120120
delete args.trail_radius
121+
} else {
122+
if (obj.__trail_type == 'points') obj.__trail_radius = 0.1*obj.__size.y
121123
}
122124
obj.__pps = 0
123125
if (args.pps !== undefined) {
@@ -2403,11 +2405,28 @@
24032405
if (options.canvas !== undefined) this.canvas = options.canvas
24042406
else this.canvas = canvas.selected
24052407
var radius = 0
2408+
if (options.type === undefined) {
2409+
this.type = 'curve'
2410+
} else {
2411+
switch (options.type) {
2412+
case 'curve':
2413+
this.type = options.type
2414+
break
2415+
case 'spheres': // JavaScript name
2416+
case 'points': // VPython name
2417+
this.type = "points"
2418+
this.__options['size_units'] = "world" // make default size units same as those of curve
2419+
break
2420+
default:
2421+
throw new Error("attach_trail type must be 'curve' or 'points' (or 'spheres')")
2422+
}
2423+
}
24062424
if (typeof objectOrFunction !== "function" && typeof objectOrFunction !== "string") { // an object
24072425
this.canvas = objectOrFunction.canvas
24082426
this.__options['color'] = objectOrFunction.color
2409-
if (options.radius === undefined) radius = 0.1*objectOrFunction.size.y
2410-
else radius = options.radius
2427+
if (options.radius === undefined) {
2428+
if (this.type == 'points') radius = 0.1*objectOrFunction.size.y
2429+
} else radius = options.radius
24112430
} else {
24122431
if (options.radius !== undefined) radius = options.radius
24132432
}
@@ -2425,22 +2444,6 @@
24252444
this.pps = options.pps
24262445
}
24272446
this.__options['pickable'] = false
2428-
if (options.type === undefined) {
2429-
this.type = 'curve'
2430-
} else {
2431-
switch (options.type) {
2432-
case 'curve':
2433-
this.type = options.type
2434-
break
2435-
case 'spheres': // JavaScript name
2436-
case 'points': // VPython name
2437-
this.type = "points"
2438-
this.__options['size_units'] = "world" // make default size units same as those of curve
2439-
break
2440-
default:
2441-
throw new Error("attach_trail type must be 'curve' or 'points' (or 'spheres')")
2442-
}
2443-
}
24442447
var send = {} // send a copy to curve or points, to prevent overwrite of this.__options
24452448
for (var a in this.__options) send[a] = this.__options[a]
24462449
if (this.type == 'curve') this.__trail = curve(send)

package/glow.2.1.min.js

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

0 commit comments

Comments
 (0)