When CLUCalc starts up, the tool window is nearly hidden at the bottom of the visualization window. Only a line a few pixels thick can be seen, as shown in the following screenshot. The white arrow points to this line.
By placing the mouse pointer over the top end of this line, the mouse pointer should change its form to indicate that this line may be dragged up and down. By dragging this line up, another window appears, which is initially grey, while the OpenGL window is reduced in size. A screenshot may now look like this, where the white arrow points to the window where the tools will appear.
The following script will now place a number of tools in the tool window. Whenever a tool is changed by the user, the script is re-executed.
?r = Slider("Radius", 0 min. val. , 2 max. val. , 0.1 step size , 1 init. val. ); ?bShow = CheckBox("Show Sphere", 1 init. val. ); ?xval = Input("x pos.", 0 min. val. , 2 max. val. , 0.5 init. val. ); lYPos = [ -1, 0, 1 ]; // A list of y positions ?choice_val = Choice("y pos.", lYPos, A list of choices 2 Initial choice index ); if (bShow) { :Red; :SphereN3(xval, lYPos(choice_val), 0, r); }
Here is a screenshot of the result.
Depending on the size of the window, the tools are organized differently in the tool window. For example,
If the tool window is too small to show all tools at the same time, a scroll bar apears on the right hand side of the window, which can be used to scroll through the tools.
The first time a tool command is encountered, a corresponding tool is created and displayed in the tool window. Subsequent executions of the same tool command, for example when the script is re-executed, do not change the current value of the tools, but can change their parameters, like the minimum and maximum allowed values. If a tool has already been created and you would like to extract its value at a later stage in the same script, it is enough to simply execute the tool command with the name of the tool. This is particularly useful, when the tool is created after loading the script, and in subsequent executions only the value of the tool is of interest. Here is an example of this.
// Has code changed? if (ExecMode & EM_CHANGE) { // if yes, then either the script was just loaded, // or the user has changed the script. // Create a slider tool Slider("Radius", 0, 2, 0.1, 0); } // This part of the code is always executed. // Now get value of slider ?rad = Slider("Radius");
A tool is automatically removed from the tool window when it is no longer needed. CLUCalc determines whether a tool is still needed by checking after each execution of the script, whether the value of the tool was asked by the script. If this is not the case, the tool is removed. Therefore, the following script will only display the tool once, after it is loaded or changed. It will disappear as soon as the script is executed for any other reason than a change of the script. In particular, it will disappear as soon as the user tries to use the tool, which is not nice. Try to avoid such scripts.
// Has code changed? if (ExecMode & EM_CHANGE) { // if yes, then either the script was just loaded, // or the user has changed the script. // Create a slider tool and get the value rad = Slider("Radius", 0, 2, 0.1, 1); } // This part of the code is always executed. // Print the value of the slider ?rad;
The tool functions currently available are
:N3_SOLID; :DRAW_POINT_AS_SPHERE; SetPointSize(6); SetLineWidth(4); DefVarsN3(); // A slider for the radius ?rad = Slider("1. Radius", 0.1, 3, 0.1, 1); :MRed; // Create a sphere :S = SphereN3(VecE3(1), rad); :Color(0.587, 0.922, 1.000, 0.8); // Create a plane :P = 20 * VecN3(0,0,0) ^ VecN3(1,0,0) ^ VecN3(0,0,1) ^ e; if (CheckBox("2. Show 2nd Sphere", 0)) { :MWhite; :S2 = SphereN3(0.5,0,0, 1); if (CheckBox("3. Sphere1 v Sphere2", 0)) { :Green; // Evaluate the intersection circle :C = S & S2; if (CheckBox("4. Circle v Plane", 0)) { :Cyan; // Evaluate the intersection points :X = C & P; } } }
The reason to start the names of the tools with a number is that the tools are automatically ordered alphabetically in the tool window. The script produces the following visualizations.
The Button() tool is useful when an action defined by the script should simply be executed. For example, suppose you do some processing with a set of randomly chosen points. The user should be able to generate a new set of random points without re-parsing the script. This is achieved by the following script.
// Create a tool button "New Points" Button("New Points"); // Check whether script is executed for the first time, // or whether the tool button "New Points" was pressed. if (ExecMode & EM_CHANGE || (ExecMode & EM_TOOL && ToolName == "New Points")) { // Generate a set of random vectors lPoints = []; i = 1; loop { if (i > 50) break; lPoints << VecP3(Ran(), Ran(), Ran()); i = i + 1; } } // Draw the set of random points. :lPoints;
Every time the user presses the button "New Points", the script is re-executed and a new set of random points is generated.