Difference between revisions of "FlashPointAndGraph"
Line 54: | Line 54: | ||
<td style="background-color:#ffffcc;padding:7px;"> |
<td style="background-color:#ffffcc;padding:7px;"> |
||
<p> |
<p> |
||
− | In the problem set-up section of the file, we specify that the Context should be <code>Point</code>, |
+ | In the problem set-up section of the file, we specify that the Context should be <code>Point</code>, and setup and define the mathematics information. (We will be asking the student to drag the dot to the inflection point of the function.) |
− | and setup and define the mathematics information. (We will be asking the student to drag the dot |
||
− | to the inflection point of the function. |
||
</p> |
</p> |
||
</td> |
</td> |
||
Line 100: | Line 100: | ||
</td> |
</td> |
||
</tr> |
</tr> |
||
+ | <tr valign="top"> |
||
+ | <td style="background-color:#ffffdd;border:black 1px dashed;"> |
||
+ | <pre> |
||
+ | ################################### |
||
+ | # Configure applet |
||
+ | ################################### |
||
+ | |||
+ | #data to set up the equation |
||
+ | $applet->configuration(qq{<XML expr='$function' />}); |
||
+ | # initial points |
||
+ | $applet->initialState(qq{<XML> <pt xval='0' yval='0'/></XML>}); |
||
+ | ################################### |
||
+ | #insert applet into body |
||
+ | ################################### |
||
+ | |||
+ | TEXT( MODES(TeX=>'object code', HTML=>$applet->insertAll( |
||
+ | debug=>0, |
||
+ | includeAnswerBox=>1, |
||
+ | reinitialize_button=>$permissionLevel>=10, |
||
+ | ))); |
||
+ | |||
+ | </pre> |
||
+ | </td> |
||
+ | <td style="background-color:#ffffcc;padding:7px;"> |
||
+ | <p> |
||
+ | Now we configure the applet. The contents of <code>configuration</code> is sent to the applet when <code>setConfig</code> is called. In this case it defines the function the student will see. The contents of <code>initialState</code> is used for <code>setState</code> if the student has never looked at the problem. After that the applet is set to the state in which the student left the flash applet in the previous session. |
||
+ | </p> |
||
+ | <p> The <code>debug</code> switch is an alternate to the <code>debugMode</code> flag in the applet definition. The <code>includeAnswerBox</code> should be set to one if you are using the default answerBox. The <code>reinitialize_button</code> allows one to return the flash applet to its virgin state, before the student has ever looked at the WeBWorK question. In this example it is only showed to professors (users with permission level greater than 10) so that they can reset a student's problem if they manage to jam it in some way. |
||
+ | </p> |
||
+ | </td> |
||
+ | </tr> |
||
+ | |||
+ | |||
<!-- Question text section --> |
<!-- Question text section --> |
||
Revision as of 19:59, 30 April 2009
Flash applet example: Graph and Point
This code snippet shows the essential PG code to check student answers that are equations. Note that these are insertions, not a complete PG file. This code will have to be incorporated into the problem file on which you are working.
PG problem file | Explanation |
---|---|
loadMacros("AppletObjects.pl", "answerHints.pl" ); |
In the initialization section, we need to include the macros file |
Context("Point"); $a = Real( random(-4,4,0.5) ); $b = Real( random(-3,3,1) ); $function = Formula("(x - $a)^3 + ($b/$a) * x")->reduce; $x0 = $a; $y0= $function->eval(x=>$x0); $answer_point = Compute("($x0, $y0)"); |
In the problem set-up section of the file, we specify that the Context should be |
################################### # Create link to applet ################################### $appletName = "PointGraph"; $applet = FlashApplet( codebase => findAppletCodebase("$appletName.swf"), appletName => $appletName, appletId => $appletName, setStateAlias => 'setXML', getStateAlias => 'getXML', setConfigAlias => 'setConfig', answerBoxAlias => 'answerBox', debugMode => 0, submitActionScript => qq{getQE("answerBox").value=getApplet("$appletName").getAnswer() }, ); |
This snippet defines the applet The aliases match names used by WeBWorK javaScript code to the subroutine and function names used by the FlashApplet. If the applet has been designed specifically to work with WeBWorK questions you will not need to change these, but if you are adapting an applet designed for other uses to a WeBWorK question then you can use these aliases to avoid making modifications to the applet.
|
################################### # Configure applet ################################### #data to set up the equation $applet->configuration(qq{<XML expr='$function' />}); # initial points $applet->initialState(qq{<XML> <pt xval='0' yval='0'/></XML>}); ################################### #insert applet into body ################################### TEXT( MODES(TeX=>'object code', HTML=>$applet->insertAll( debug=>0, includeAnswerBox=>1, reinitialize_button=>$permissionLevel>=10, ))); |
Now we configure the applet. The contents of The |
BEGIN_TEXT ...... question text ...... END_TEXT |
The problem text section of the file is as we'd expect. |
ANS( $expr->cmp() ); |
As is the answer. |