Scripting Physical Environments
There are many ways in which CindyScript can be used to enhance the possibilities of CindyLab. We will present a few of them here. On the one hand, CindyScript provides several special operators that have been implemented for use with CindyScript (for instance, an oscilloscope for viewing physical magnitudes and a statement for plotting force fields). On the other hand, CindyScript has direct access to most of the parameters that are relevant for physics simulations. Moreover, CindyScript can enable or disable physical functionalities of CindyLab objects. In this way one can implement machine-like behavior in CindyLab scenarios. We will give several examples here that use CindyScript together with CindyLab.
Here the x and y coordinates of point B are shown. If B is a point moving around a sun, the picture might look like the one below.
By default, the display range of the curve is automatically adapted to the range of values. The
Here many modifiers were used in order to get the desired color behavior and the text display. The example was constructed using the following CindyScript program:
linecolor((1,1,1)); drawcurves((-7,-3), textcolor((1,1,1)); (A.x,B.x,A.ke,B.ke,a.pe+b.pe+c.pe), height->50, color->(1,1,1), back->(0,0,0), backalpha->1,showranges->true, range->"peek",width->400, colors->[ [1,0.5,0.5], [0.5,1,0.5], [1,0.5,0.5], [0.5,1,0.5], [0.5,0.5,1]], texts->[ "PosA = "+ A.x, "PosB = "+B.x, "EnergyA = "+A.ke, "EnergyB = "+B.ke, "PotentialEnergy = "+(a.pe+b.pe+c.pe) ]);
Another CindyScript operator that was designed to support CindyLab is the
then all gravitational forces, Coulomb forces, ball interactions, etc. are measured and the flux is drawn. The probe particle is standardized to have mass = 1, charge = 1, and radius = 1. If, for instance, two charged particles are present with opposite charges, then the
The code fragment that generated this flux picture uses several modifiers.
drawforces(stream->true, color->(1,1,1), factor->3, resolution->5)
In particular, the
Programming CindyLab Scenarios
Since CindyScript can influence all the parameters of CindyLab, it is also easy to implement complicated behavior. As an example, we present here an implementation of a simple table tennis game. First, a few bouncers are used to draw the boundary of the table. Another bouncer is constructed geometrically that is bound to a point so that it can be freely moved like a table tennis paddle. Finally, a table tennis ball is added as a particle with velocity. So far, the construction makes use only of CindyLab and Cinderella. The situation is already quite functional. One can indeed play table tennis. However, if the ball leaves the screen, it will be lost forever.
This is the point at which CindyScript comes into play. With CindyScript one can detect whether the ball is leaving the screen and react to such an event. The following program detects the ball leaving the screen with the code line
if(H.x>D.x+9, H.x=F.x; r=random(); H.y=(r*D.y+(1-r)*G.y); w=random()*pi/2+3*pi/4; H.vx=-cos(w)*.4; H.vy=sin(w)*.4; H.color=(hue(random())); count=count+1; ); drawtext((-1,-3),"Missed balls: "+count,size->20);
In order to initialize the counter, there must also be one additional line of code in the simulation start tag that sets the counter to zero.
The picture below shows a snapshot that was taken during a game. Observe how the yellow ball leaves the game and the blue ball is thrown in.
The content on this page is licensed under the terms of the License.