########################################################################
DOCUMENT();
loadMacros(
"PGstandard.pl", # Standard macros for PG language
"MathObjects.pl",
"PGgraphmacros.pl",
"AppletObjects.pl",
"parserImplicitEquation.pl",
"source.pl",
);
# Print problem number and point value (weight) for the problem
TEXT(beginproblem());
# Show which answers are correct and which ones are incorrect
$showPartialCorrectAnswers = 1;
##############################################################
#
# Setup
#
#
Context("ImplicitEquation");
Context()->variables->are(x=>["Real", limits=>[-8,8]], y=>["Real", limits=>[-8,8]]);
Context()->noreduce('(-x)-y');
$a = non_zero_random(-3,7,1);
do{ $b = non_zero_random(-5,5,1); } until ( $a != 1 || $b != 1 );
$c = $a*$b;
$f = Formula("$b x+$a y")->reduce;
$answer = ImplicitEquation("$f = $c");
######################################
# Create link to applet:
###################################
# You can name your applet (anything reasonable :-) )
# Adjust the height and width as desired
# Paste the geogebra parameters in at the bottom of the page just above the
# command end command
# so that they don't get in the way
###################################
$appletName = "ggbfoo";
$applet = GeogebraWebApplet(
code => "geogebra.GeoGebraApplet",
archive => "geogebra.jar",
codebase => findAppletCodebase("geogebra.jar"),
appletName => $appletName,
appletId => $appletName,
submitActionAlias => 'getAppletValues', # default actionAlias
initializeActionAlias => 'configure', # default actionAlias
setStateAlias => 'setXML',
getStateAlias => 'getXML',
setConfigAlias => '',
getConfigAlias => '',
returnFieldName => '',
width => 400, # may want to modify width
height => 400, # may want to modify height
# mayscript => "true",
debugMode => 0, # set debugMode to 0 for no debug
# to 1 to make xml representation visible
# to 2 to add alerts detailing progression
# through the applet
onInit => 'ggbOnInit',
type => 'geogebraweb',
submitActionScript => qq{ getQE('answerBox').value = getAppletValues() },
#submitActionScript => '',
selfLoading => 1,
params => GEOGEBRA_PARAMS(),# paste parameters in
);
###############################################
#
# PNG picture of GeoGebra applet for hardcopy
$im = init_graph(-8,-8,8,8,
size=>[400,400],
grid=>[16,16],
axes=>[0,0]
);
##################################
# Setup GeogebraWebApplet --
###################################
###############################################
#
# For persistence of GeoGebra applet state
# when answers are submitted or page is refreshed.
# Uses JavaScript interface to GeoGebra.
HEADER_TEXT(
qq!
<script language="javascript">
function ggbOnInit(param) {</div>
<div> if (param == "$appletName") {</div>
<div> applet_loaded(param,1); // report that applet is ready. </div>
<div> ww_applet_list[param].safe_applet_initialize(2);</div>
<div> }
}
</script>
<noscript>For this question to work properly,
you must enable JavaScript, or use another browser
(or computer) on which JavaScript works.</noscript>
!);
#######################################################
#
# For setting initial values in GeoGebra from WeBWorK
# Uses JavaScript interface to GeoGebra.
TEXT( MODES(TeX=>'', HTML=><<END_SCRIPT ) );
<script language="javascript">
function setAppletCoefficients() {</div>
<div> var applet=getApplet("$appletName"); // alert("Updating coefficients");</div>
<div> if (typeof(applet)!="undefined") {</div>
<div> if (typeof(applet.setValue)!="undefined") {</div>
<div> </div>
<div> ////////////////////////////////////////////////////////////////</div>
<div> // List the values of the parameters to be set in the applet here</div>
<div> // Setup the grid, then establish values, points, then the line</div>
<div><br /></div>
<div> applet.setPerspective("G");</div>
<div> applet.setPointCapture(1,2);</div>
<div> applet.setCoordSystem(-8,8,-8,8);</div>
<div> applet.setAxisSteps(1,1,1);</div>
<div> applet.setGridVisible('true');</div>
<div><br /></div>
<div> applet.evalCommand("a = 1");</div>
<div> applet.evalCommand("b = 1");</div>
<div> applet.evalCommand("A = (a,0)");</div>
<div> applet.evalCommand("B = (0,b)");</div>
<div> applet.evalCommand("l = Line[A,B]");</div>
<div><br /></div>
<div> //applet.setColor('A',228,27,23);</div>
<div> //applet.setColor('B',228,27,23);</div>
<div> //applet.setColor('l',228,27,23);</div>
<div><br /></div>
<div><br /></div>
<div> } else {</div>
<div> setTimeout("setAppletCoefficients()", 1000);</div>
<div> }
} else {</div>
<div> setTimeout("setAppletCoefficients()",1000);</div>
<div> }
}
ww_applet_list["$appletName"].setConfig = function() {setAppletCoefficients()};
</script>
END_SCRIPT
#######################################################
#
# For retrieving values from GeoGebra into WeBWorK
#
HEADER_TEXT( MODES(TeX=>'', HTML=><<END_SCRIPT ) );
<script language="javascript">
function getAppletValues() {</div>
<div> console.log("getAppletValues() entered");</div>
<div><span style="white-space:pre;"> </span>// get a handle for the applet object</div>
<div> <span style="white-space:pre;"> </span>var applet = $appletName;</div>
<div> <span style="white-space:pre;"> </span>var l = applet.getLaTeXString("l");</div>
<div> return( l ); </div>
<div>}
</script>
END_SCRIPT
##############################################################
#
# Text
#
#
Context()->texStrings;
BEGIN_TEXT
Graph the line, and submit your answer.
\[$f = $c\]
END_TEXT
Context()->normalStrings;
###################################
# insert applet into body -- this does not need to be changed
# except to adjust the insertion of the reinitialize_button or
# a hidden AnswerBox
###################################
TEXT($PAR, MODES(TeX=>'geogebraweb code',
HTML=>"<div class='enclose_ggb_obj'>".$applet->insertAll(
debug =>0,
reinitialize_button => 1,
includeAnswerBox=>1 )."</div>"
));
##############################################################
#
# Answers
#
#
NAMED_ANS( 'answerBox' => $answer->cmp() );
sub GEOGEBRA_PARAMS {</div>
<div> my $result = {</div>
<div> appName=>"classic", # instead of using ggbbase64</div>
<div> enableShiftDragZoom=>"false",</div>
<div> showResetIcon=>"false" ,</div>
<div> enableRightClick=>"false" ,</div>
<div> enableLabelDrags=>"false",</div>
<div> showMenuBar=>"false" ,</div>
<div> showToolBar=>"false",</div>
<div> showAlgebraInput=>"false",</div>
<div> useBrowserForJS=>"true",</div>
<div> #ggbbase64=>''</div>
<div>};
$result;
}
ENDDOCUMENT();