A
is a free point, the line A.xy=[1,1]
sets this point to the coordinates [1,1]
. Another way of moving an element is with the moveto
operator.moveto(<geo>,<vec>)
:<geo>
is a free geometric object and <vec>
describes a position to which this object should be moved. Invoking this operator simulates a move for this geometric object.<geo>
is a free point, then <vec>
can be a list [x,y]
of two numbers or a list [x,y,z]
of three numbers. The first case is interpreted as Euclidean coordinates, while the second case is interpreted as homogeneous coordinates and sets the point to [x/z,y/z]
.<geo>
is a free line, then <vec>
has to be a list of three numbers [a,b,c]
, and the line is set to the line described by the equation a∗x + b∗y + c = 0
.//A is a free point moveto(A,[1,4]); //moves A to Euclidean coordinates [1,4] A.xy=[1,4]; //moves A to Euclidean coordinates [1,4] A.x=5; //sets the x coordinate of A to 5, lets the y coordinate unchanged A.y=3; //sets the y coordinate of A to 3, lets the x coordinate unchanged moveto(A,[2,3,2]); //moves A to homogeneous coordinates [2,3,2] A.homog=[2,3,2]; //moves A to homogeneous coordinates [2,3,2] //a is a free line moveto(a,[2,3,4]); //moves a to homogeneous coordinates [2,3,4] a.moveto=[2,3,4]; //moves a to homogeneous coordinates [2,3,4] //b is a line through a point a.slope=1; //sets the slope of the line to 1 //C is a circle with free radius C.radius=1; //sets the radius of the circle to 1
mover()
:simulation()
:mouse()
:mouse().xy
.key()
:print(<expr>)
:<expr>
to the console.err(<expr>)
:<expr>
to the console. If <expr>
is a variable, the variable name is printed as well. Very useful for debugging.println(<expr>)
:<expr>
to the console and adds a newline character to the end of the text.println()
:clearconsole()
:assert(<bool>,<expr>)
:if(!<bool>,println(<expr>))
. It can be used to test wheter a condition is met and otherwise generate an error message.assert(isinteger(k),"k is not an integer");
time()
:[h,m,s,ms]
of four integers. The four values correspond to "hour," "minute," "second," "millisecond" on the computer's clock.t
contains the time information. The subsequent code is used to produce a clocklike drawing on the view. An auxiliary function p(w)
is defined that produces points on the unit circle. The code must be placed in the "Tick" section of CindyScript in order for it to run continuously.t=time(); p(x):=[sin(2*pi*x),cos(2*pi*x)]; O=[0,0]; S=p(t_3/60)*4; M=p(t_2/60)*5; H=p((t_1*60+t_2)/(12*60))*3.5; draw(O,S); draw(O,M,size->2); draw(O,H,size->3); apply(1..12,draw(p(#/12)*5)); apply(1..60,draw(p(#/60)*5,size->1)); drawtext((3,5),t);
date()
:[y,m,d]
of three integers. The three values correspond to "year," "month," and "day" on the computer's calendar.seconds()
:resetclock()
. The time is scaled in a way such that one unit corresponds to one second. The time's resolution is on the millisecond scale.resetclock()
:seconds()
operator.simulationtime()
:load(<string>)
:<string>
, which is considered to be a file name (possibly preceded by directory information). If the file name is legitimate, then the entire information contained in the file will be returned as a string. This operator is particularly useful together with the tokenize
operator, which helps to analyze structured data. The data are read from the currently active directory, which can be set with the setdirectory
operator.LoadDemo.txt
the following data are stored:abc,gfdg;1,3,5.6,3.141;56,abc,xxx,yyy
x=load("LoadTest.txt"); y=tokenize(x,(";",",")); apply(y,println(#));
[abc,gfdg] [1,3,5.6,3.141] [56,abc,xxx,yyy]
import(<string>)
:<string>
, which is considered to be a file name (including directory information). If the file name is legitimate, then the whole content of the file is assumed to be able to be parsed by CindyScript code, and it is immediately executed. In this way, one can load libraries with predefined functionality. It is advisable to use the import
operator only in the "Init" section of CindyScript, since otherwise, the file will be read for each move.setdirectory(<string>)
:openurl(<string>)
:parse(<string>)
:expression | evaluates to |
parse("3+7") | 10
|
text="sin(x)+cos(x)"; f(x):=parse(text);
f(x)
to be sin(x)+cos(x)
.repaint()
:draw
or in the move
slot.locusdata(<locus>)
:<locus>
of a geometric element.incidences(<geo>)
:<geo>
.addforce(<mass>,<vec>)
:<vec>
to an existing mass <mass>
. This operator is very useful to implement user defined force fields. It should be called in the Integration Tick
slot.setforce(<mass>,<vec>)
:<vec>
for an existing mass <mass>
. This operator is very useful to implement user defined force fields. It should be called in the Integration Tick
slot.force(<vector>)
:force
is closely related to physics simulations in CindyLab. It can be used for testing the force that would affect a mass particle at a specific position. The vector <vector>
represents the position. The operator returns a two-dimensional vector that is the force at this position. If no modifiers are used, the operator assumes that the probe particle has mass=1
, charge=1
and radius=1
(see Free Mass).drawforces
operator and a color plot of the force
operator. It shows the force field and force strength of the electrostatic field of two charges.A.charge=(|C,G|-3)*3; B.charge=(|E,H|-3)*3; f(x):=max((0,min([x,1]))); colorplot([0.1,0.1,0.1]+hue(f(abs(force(#)/3))),(-10,-10),(20,10)); drawforces(stream->true,move->0.2,color->[0,0,0],resolution->10);
force((0,0),charge->2)
tests the force that would be present for a particle of charge=2
, mass=0
, and radius=0
at point [0,0]
.
Page last modified on Thursday 25 of May, 2006 [23:32:00 UTC].
The original document is available at
http://doc.cinderella.de/tiki-index.php?page=Special%20Operators