name="CindyJSDemo"
. Using this handle, JavaScript can call an arbitrary CindyScript statement via the function doCindyScript(<statement>)
. The statement is given as a string. This string will be parsed and executed whenever the function doCindyScript
is called. The following piece of code exemplifies this procedure. It shows how to provide four buttons in the HTML text that manage to place a point D in various geometrically interesting positions with respect to A, B and C.⟨script language="JavaScript" type="text/javascript"⟩ function doScript(c) { document.CindyJSDemo.doCindyScript(c);}; ⟨/script⟩ ⟨input type="button" value="Middle of AB" onclick="doScript('D.xy=(A+B)/2');" /⟩ ⟨input type="button" value="Middle of AC" onclick="doScript('D.xy=(A+C)/2');" /⟩ ⟨input type="button" value="Middle of BC" onclick="doScript('D.xy=(B+C)/2');" /⟩ ⟨input type="button" value="Middle of ABC" onclick="doScript('D.xy=(A+B+C)/3');" /⟩ ⟨br⟩ ⟨applet name="CindyJSDemo" code = "de.cinderella.CindyApplet" archive = "cindyrun2.jar" width = 680 height = 336⟩ ... applet specifications ... ⟨/applet⟩
![]() |
repaint
statement within the call one can even trigger smooth transitions of a construction from one position to a new one. Unfortunately, in JavaScript, a string is not allowed to contain a usual newline
character. So it may be the case that complicated script calls look a bit cluttered. One can bypass this problem by subdividing a script into smaller strings. The following piece of code shows the code for a button that smoothly moves the points A, B and C to the positions [0,0]
, [4,0]
and [2,3]
.⟨input type="button" value="Smooth move of ABC" onclick="doScript( 'oldpos=[A.xy,B.xy,C.xy];'+ 'newpos=[[0,0],[4,0],[2,3]];'+ 'n=40;'+ 'repeat(n,i,'+ ' l=i/n;'+ ' pos=l*newpos+(1-l)*oldpos;'+ ' A.xy=pos_1;'+ ' B.xy=pos_2;'+ ' C.xy=pos_3;'+ ' repaint();'+ ' wait(10);'+ ');' );" /⟩
javascript(<string>)
javascript(...)
. The following piece of code shows how to raise a JavaScript alert whenever point A gets to close to the origin (a rather useless piece of code, by the way).if(|A,[0,0]|<1, javascript("alert('A is too close to the origin')"); );
Page last modified on Tuesday 30 of August, 2011 [10:28:41 UTC].
The original document is available at
http://doc.cinderella.de/tiki-index.php?page=Javascript