Skip to content

Commit

Permalink
Merge pull request vpython#141 from vpython/Fix_bug_in_print_of_multi…
Browse files Browse the repository at this point in the history
…line_text

Fix bug in print of multiline text
  • Loading branch information
BruceSherwood authored Apr 11, 2021
2 parents 5c67301 + 9b482e1 commit 828f8ab
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 33 deletions.
2 changes: 1 addition & 1 deletion ForInstalledPython/glow.min.js

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion GlowScriptOffline/glowscript_libraries/compiler.3.1.min.js

Large diffs are not rendered by default.

Binary file modified GlowScriptOffline3.1.zip
Binary file not shown.
6 changes: 4 additions & 2 deletions docs/VPythonDocs/compound.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@
<div>
<p class="Normal">The <strong>compound</strong> object lets you group objects together and manage them as though they were one object, by specifying in the usual way <span class="attribute">pos</span>, <span class="attribute">color</span>, <span class="attribute">size</span> (or <span class="attribute">length</span>, <span class="attribute">width</span>, <span class="attribute">height</span>), <span class="attribute">axis</span>, <span class="attribute">up</span>, <span class="attribute">opacity</span>, <span class="attribute">shininess</span>, <span class="attribute">emissive</span>, and <span class="attribute">texture</span>. Moreover, the display of a complicated compound object is faster than displaying the individual objects one at a time. (In GlowScript version 2.1 the <strong><a href="compound2.1.html" target="_blank">details were somewhat different</a></strong>.)</p>
<p class="Normal">The object shown above is a compound of a cylinder and a box:</p>
<p class="program">handle = cylinder( size=vector(1,.2,.2), &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;color=vector(0.72,0.42,0) )<br />
<p class="program">handle = cylinder( size=vector(1,.2,.2), &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; color=vector(0.72,0.42,0) )<br />
<br />
head = box( size=vector(.2,.6,.2), pos=vector(1.1,0,0), &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;color=color.gray(.6) )<br />
head = box( size=vector(.2,.6,.2), pos=vector(1.1,0,0), &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;c<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;color=color.gray(.6) )<br />
<br />
hammer = compound([handle, head])<br />
hammer.axis = vector(1,1,0)</p>
Expand Down
34 changes: 19 additions & 15 deletions lib/compiling/GScompiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ where compile() was called, in untrusted/run.js.
const defpatt = new RegExp('^def\\s+(\\w+)\\s*\\(') // find a Python def
const asyncpatt1 = new RegExp('\\Wfunction\\s*(\\w+)\\s*\\(') // find "function f(...."
const awaitpatt = new RegExp('\\W([ρσ\\w]+)\\s*\\(') // find a function call
//const jsasyncpatt1 = new RegExp('\\Wfunction\\s*([\\w\.]+)\\s*\\(') // find "function f(...."

// fcts is a list of GlowScript functions that need "await" and of all user functions that are not
// classes, instances of classes, or methods of classes:
Expand Down Expand Up @@ -927,15 +926,33 @@ where compile() was called, in untrusted/run.js.

// Prepend "await " to calls to user functions and the GlowScript async functions (all user functions and class methods are marked async).
start = initialstart

// Python and VPython and RapydScript and JavaScript key words that can precede '(':
let no_await = ['if', 'elif', 'return', 'for', 'while', 'function', 'else', 'dict', 'str',
'float', 'hex', 'int', 'iter', 'len', 'list', 'vec', 'vector', 'catch', 'enumerate',
'oct', 'ord', 'print', 'range', 'arange', 'update', 'print', 'GSprint', 'clock', 'msclock',
'canvas', 'graph', 'gcurve', 'gdots', 'gvbars', 'ghbars', 'rotate', 'box', 'cylinder',
'cone', 'pyramid', 'sphere', 'simple_sphere', 'arrow', 'curve', 'points', 'paths',
'shapes', 'helix', 'ring', 'compound', 'vertex', 'triangle', 'quad', 'label',
'distant_light', 'local_light', 'attach_trail', 'attach_arrow', 'text', 'extrusion',
'wtext', 'winput', 'radio', 'checkbox', 'button', 'slider', 'menu', 'input',
'mag', 'mag2', 'norm', 'hat', 'dot', 'cross', 'proj', 'diff_angle',
'abs', 'sin', 'cos', 'tan', 'asin', 'acos', 'atan', 'atan2', 'exp', 'log', 'pow', 'sqrt',
'ceil', 'floor', 'sign', 'round', 'max', 'min', 'random', "factorial", "combin"]

// VPython_import is the prefix of VPython objects, with value 'null' if no import statement
// const awaitpatt = new RegExp('\\W([ρσ\\w]+)\\s*\\(') // find a function call
while (true) {
m = prog.slice(start).match(awaitpatt)
var period = false
if (m === null) break
period = (prog[start+m.index] == '.')
name = m[1]
let preceding = prog[start+m.index]
period = (preceding == '.')
if ( (preceding == '\\') || (!period && no_await.indexOf(name) >= 0) ) {
start += m.index+name.length+2
continue
}

// If this is a class, delete the call to __init__ (we will insert this call after creating the class instance)
if (options.lang == 'vpython' && !period && classes.indexOf(name) >= 0) {
Expand Down Expand Up @@ -1036,19 +1053,6 @@ where compile() was called, in untrusted/run.js.
continue
}

// Python and VPython and RapydScript and JavaScript key words that can precede '(':
let no_await = ['if', 'elif', 'return', 'for', 'while', 'function', 'else', 'dict', 'str',
'float', 'hex', 'int', 'iter', 'len', 'list', 'vec', 'vector', 'catch', 'enumerate',
'oct', 'ord', 'print', 'range', 'arange', 'update', 'print', 'GSprint', 'clock', 'msclock',
'canvas', 'graph', 'gcurve', 'gdots', 'gvbars', 'ghbars', 'rotate', 'box', 'cylinder',
'cone', 'pyramid', 'sphere', 'simple_sphere', 'arrow', 'curve', 'points', 'paths',
'shapes', 'helix', 'ring', 'compound', 'vertex', 'triangle', 'quad', 'label',
'distant_light', 'local_light', 'attach_trail', 'attach_arrow', 'text', 'extrusion',
'wtext', 'winput', 'radio', 'checkbox', 'button', 'slider', 'menu', 'input',
'mag', 'mag2', 'norm', 'hat', 'dot', 'cross', 'proj', 'diff_angle',
'abs', 'sin', 'cos', 'tan', 'asin', 'acos', 'atan', 'atan2', 'exp', 'log', 'pow', 'sqrt',
'ceil', 'floor', 'sign', 'round', 'max', 'min', 'random', "factorial", "combin"]

// Python and VPython key words that can be preceded by 'xxx.'
// 'defineProperties' is a RapydScript-NG element.
// slice is part of the RapydScript-generated JavaScript for list comprehensions.
Expand Down
11 changes: 0 additions & 11 deletions lib/glow/extrude.js
Original file line number Diff line number Diff line change
Expand Up @@ -557,17 +557,6 @@ function extrusion(args) {
}
}

// let c = vec(0,0,0)
// if (args.up === undefined) {
// let a = args.path[1].sub(args.path[0]) // first segment
// if (args.path.length > 2) {
// let b = args.path[2].sub(args.path[1]) // second segment
// c = cross(a,b).norm()
// }
// if (args.path.length == 2 || c.mag === 0) {

// }
// } else args.up = norm(args.up)
args.color = (args.color === undefined) ? color.white : args.color
args.twist = (args.twist === undefined) ? 0 : args.twist
args.opacity = (args.opacity === undefined) ? 1 : args.opacity
Expand Down
2 changes: 1 addition & 1 deletion package/RScompiler.3.1.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package/compiler.3.1.min.js

Large diffs are not rendered by default.

0 comments on commit 828f8ab

Please sign in to comment.