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 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

 > $\mathrm{with}\left(\mathrm{DocumentTools}:-\mathrm{Canvas}\right):$

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:
 > $\mathrm{cv}≔\mathrm{NewCanvas}\left(\left["Calculate the Hypotenuse",\mathrm{StaticPlot}\left(\mathrm{DrawTriangle}\left(1,2\right)\right),\mathrm{Math}\left(0,'\mathrm{custom}'="Input",'\mathrm{annotation}'="-- Enter Hypotenuse",'\mathrm{border}'=\mathrm{true}\right),\mathrm{ScriptButton}\left("Check",\mathrm{Check}\right),\mathrm{ScriptButton}\left("Try Another",\mathrm{TryAnother},'\mathrm{include}'=\left[\mathrm{DrawTriangle}\right]\right),\mathrm{State}\left(\left[1,2\right]\right)\right]\right):$
 > $\mathrm{ShowCanvas}\left(\mathrm{cv}\right)$

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