DocumentTools[Canvas]
State
canvas state initializer
Calling Sequence
Parameters
Description
Examples
Compatibility
State(value)
value
-
string, expression, table, or other value
The State command is used in conjunction with NewCanvas to initialize a default state that can be subsequently used by the SetState script action.
with⁡DocumentTools:-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:
cv≔NewCanvas⁡Calculate the Hypotenuse,StaticPlot⁡DrawTriangle⁡1,2,Math⁡0,custom=Input,annotation=-- Enter Hypotenuse,border=true,ScriptButton⁡Check,Check,ScriptButton⁡Try Another,TryAnother,include=DrawTriangle,State⁡1,2:
ShowCanvas⁡cv
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
Text
Download Help Document