Accessing Geometric ElementsAccessing Geometric ElementsThe main communication between CindyScript and the geometry part of Cinderella is accomplished by accessing the geometric objects of a construction. Geometric elements can be accessed in two different ways: either one can access an element by the name of its label or one can access lists of elements by special CindyScript operators. The interaction between Cinderella and CindyScript gives CindyScript the possibility to read essentially all properties of the elements of a geometric construction. Most properties can also be set by CindyScript. The following sections first describe the possible ways to address geometric objects and then provide a detailed list of the supported properties. Accessing Elements by Their NamesEvery element in a geometric construction has a unique name, its label. This name can be used as a handle in CindyScript. Formally, in CindyScript the element plays the role of a predefined variable. The different properties can be read and set via the . operator (dot operator). For instance, the line of code A.size=20 sets the size of point A in a construction to the value 20. If a point or a line is contained in an arithmetic operator without a dot operator, then it is automatically converted to a vector representing its position. Thus a point is converted into an [x,y] vector representing its two-dimensional coordinates. A line is converted to an [x,y,z] vector representing its homogeneous coordinates. However,if one intends to set the coordinates of a point, then one has to use the dot operator explicitly. If a handle to a geometric object is not used in an arithmetic expression, then it is still passed to the calculation as the geometric object. Since these concepts are a bit subtle, we will clarify them with a few examples.Assume that A, B, and C are points in a Cinderella construction. The line A.xy=(B+C)/2 sets the point A to be the midpoint of B and C. These two points are contained in an arithmetic expression, and therefore they are immediately inverted to an [x,y] vector. Setting the position of point A has to be done by explicitly using the .xy property.The following program sets the color of all three points to green: pts=[A,B,C]; forall(pts,p, p.color=[0,1,0]; ) In this code the point names are passed as handles to the list pts . Traversing the list with the forall operator puts this handles one after the other into the variable p , from which their color property is accessed.Lists of ElementsSometimes it is not necessary to access points individually by their name. In particular, this happens whenever one is interested in performing an operation on all points in a construction. This may happen, for instance, when one wants to calculate the convex hull of a point set. For this, CindyScript provides several operators that return lists of elements. For instance, the operator allpoints() returns a list of all points of a construction. We will demonstrate this with a very tiny example. The following program changes the color of the points depending on their position relative to the y-axis:pts=allpoints(); forall(pts,p, if(p.x<0, p.color=[1,1,0], p.color=[0,1,0]; ) ) The following picture shows the application of the code to a random collection of points.
Properties of Geometric ObjectsWe now start with a complete description of all properties that are currently accessible via CindyScript. Every property is at least readable. For each property we list the type of value expected for the property, whether it is read only or also writeable, and a short description of its purpose. Possible property types are usually as follows:
Some properties, like the current position, are only writable for free objects. We mark this by the word "free" in the corresponding column. Properties Common to All Geometric Objects
Each geometric element has a unique name. the string that represents this name may be accessed by .name . So for instance A.name returns the string "A" . The name may not be identical with the caption of the element shown in the construction. If A.caption is the empty string the name is shown, otherwise the caption.Properties of Points
Properties of Lines
Properties of Circles and Conics
Properties of Texts
Properties of Animations
Properties of Transformations
Properties of CindyLab ObjectsIt is not only geometric properties that can be accessed by CindyScript. The simulation parameters of CindyLab constructions can also be read and sometimes set via CindyScript. Properties of All CindyLab Elements
Properties of Masses
Sometimes one is interested to add a user defined force potential between masses. This can be done by scripting a suitable piece of code in the Integeration Tick event. Since internally the position of masses has a finer time scale than usual geometric movements it is necessary to access their position via the pos , posx and posy accessors.Properties of Springs and Coulomb Forces
Property for Velocities
Properties of Gravity
Properties of Suns
Properties of Magnetic Areas
Properties of Bouncers and Floors
Properties of the EnvironmentThe environment can be accessed by the built-in operator simulation() . The following slots of the environment can be accessed:
Inspecting ElementsYou can also use the generic CindyScript function inspect(<element>) to access all the attributes that are available in the Inspector. For example, if a point A exists in the construction, the functioninspect(A) will return the array of strings [name,definition,color,visibility,drawtrace,tracelength, traceskip,tracedim,render,isvisible,text.fontfamily, pinning,incidences,labeled,textsize,textbold,textitalics, ptsize,pointborder,printname,point.image, point.image.rotation,freept.pos] Using the two-parameter form inspect(<element>,<string>) you can read all the attributes of A that are listed in the above array:inspect(A,"text.fontfamily") returns SansSerif With the three-parameter form inspect(<element>,<string>,<expr>) you can also set the attributes that are not read-only (for example, you cannot change the list of incidences or the definition of an element). The following function will set the font of A to a Serif font:inspect(A,"text.fontfamily","Serif") The inspect command is very powerful, as you can automate all actions you normally would have to do in the Inspector using the mouse. Also, it gives you fine grained control over all properties. Set a user attribute:
|