|
Calling Sequence
|
|
State(value)
|
|
Parameters
|
|
value
|
-
|
string, expression, table, or other value
|
|
|
|
|
Description
|
|
•
|
The State command is used in conjunction with NewCanvas to initialize a default state that can be subsequently used by the SetState script action.
|
|
|
Examples
|
|
>
|
|
In this example the length of the sides of the triangle are stored in hidden state
>
|
Check := proc(canvas)
local state := GetElements(canvas,"state")[1];
local ans := GetElements(canvas,'custom'="Input")[1];
local sc := Script();
SetActive(sc,ans);
Annotate(sc,`if`(is(sqrt(state:-value[1]^2+state:-value[2]^2) = ans:-math),"Correct","Incorrect"));
ToString(sc);
end proc:
|
>
|
TryAnother := proc(canvas)
# find and clear the input box
local elem := GetElements(canvas,'custom'="Input");
local sc := Script();
SetActive(sc,elem[1]);
SetMath(sc,"");
Annotate(sc,"-- Enter Hypotenuse");
# generate a new plot
randomize();
local l1 := rand(1..5)();
local l2 := rand(1..5)();
SetState(sc,[l1,l2]);
elem := GetElements(canvas,"plot");
SetActive(sc,elem[1]);
SetPlot(sc,DrawTriangle(l1,l2));
ToString(sc);
end proc:
|
>
|
DrawTriangle := proc( len1, len2 )
plots:-display( [
plots:-polygonplot( [[1,1],[1,1+len1],[1+len2,1],[1,1]], 'style'='line' ),
plots:-textplot( [[1,len1/2+1,len1,'align'='left'],[len2/2+1,1,len2,'align'='below']] )
], 'view'=[0.5 .. len2+1.5,0.5 .. len1+1.5], 'axes'='boxed');
end proc:
|
>
|
|
|
|
Compatibility
|
|
•
|
The DocumentTools[Canvas][State] command was introduced in Maple 2022.
|
|
|
|