State - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

Online Help

All Products    Maple    MapleSim


DocumentTools[Canvas]

  

State

  

canvas state initializer

 

Calling Sequence

Parameters

Description

Examples

Compatibility

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

withDocumentTools:-Canvas:

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:

cvNewCanvasCalculate the Hypotenuse,StaticPlotDrawTriangle1,2,Math0,custom=Input,annotation=-- Enter Hypotenuse,border=true,ScriptButtonCheck,Check,ScriptButtonTry Another,TryAnother,include=DrawTriangle,State1,2:

ShowCanvascv

Compatibility

• 

The DocumentTools[Canvas][State] command was introduced in Maple 2022.

• 

For more information on Maple 2022 changes, see Updates in Maple 2022.

See Also

Annotate

GetCanvas

GetMath

Math

NewCanvas

Script

ScriptButton

SetState

ShareCanvas

ShareCanvas

Text