The static graphics example
To obtain this problem
(1 pt) rochesterLibrary/setMAAtutorial/staticgraphicsexample/staticgraphicsexample.pg
WARNINGS µ¦å{h
Enter this code:
DOCUMENT(); loadMacros("PGbasicmacros.pl", "PGchoicemacros.pl", "PGanswermacros.pl" ); TEXT($BEGIN_ONE_COLUMN); TEXT(beginproblem(), $BR,$BBOLD, "Static graphics Example", $EBOLD, $BR,$BR);
$showPartialCorrectAnswers = 0; # Define which of the three sets of pictures to use
# The pictures are labeled 1.png, 2.png and 3.png and # stored in the same directory as staticgraphicsexample.png # These are the corresponding transformed pictures. # Be careful with the labeling, since the URL's could give the # correct answers away. # (In this example the middle integer tells you # the correct position.)
$pictID[1] = [ "131126.png", # "\( F(x+3)\)", "176239.png", # "\(F(x3) \)" , "196355.png", # "\( F(x)\)", "124438.png", # "\( F(x) \)", "189540.png", # "\( 5F(x) \)", "142639.png", # "\( F(3x) \)" , "191734.png", # "\( F(x/3) \)", "134859.png", # "\( F(x^2) \)", ]; $pictID[2] = [ "270190.png", # ditto "249261.png", "262384.png", "254427.png", "264591.png", "242653.png", "281779.png", "292879.png", ]; $pictID[3] = [ "314197.png", "389262.png", "399389.png", "368458.png", "314538.png", "337616.png", "346739.png", "352898.png", ]; $ml = new_match_list();
$pictSet=random(1,3,1); # Choose one of the three picture sets $pictSet=1; $pictSetname = $pictSet.".png"; $ml>qa ( "\( F(x+3)\) ", image($pictID[$pictSet][0],tex_size=>200), "\(F(x3) \)" , image($pictID[$pictSet][1],tex_size=>200), "\( F(x)\) ", image($pictID[$pictSet][2],tex_size=>200), "\( F(x) \)", image($pictID[$pictSet][3],tex_size=>200), "\( 5F(x) \)", image($pictID[$pictSet][4],tex_size=>200), "\( F(3x) \)" , image($pictID[$pictSet][5],tex_size=>200), "\( F(x/3) \)", image($pictID[$pictSet][6],tex_size=>200), "\( F(x^2) \)", image($pictID[$pictSet][7],tex_size=>200), );
$ml>choose(4); sub format_graphs { my $self = shift; my @in = @_; my $out = ""; while(@in) { $out .= shift(@in). "#" ; } $out; # The output has to be a string in order to conform to the # specs for the match list object, but I've put some # markers in (#) so that # I can break the string up into a list for use # as an input into row. }
# We need to change the output, since the normal # output routine will put the pictures one above another. $ml>rf_print_a(~~&format_graphs);
BEGIN_TEXT This is a graph of the function \( F(x) \): ($BBOLD Click on image for a larger view $EBOLD) $PAR \{ image($pictSetname, tex_size => 200) \} $PAR Enter the letter of the graph below which corresponds to the transformation of the function. \{ $ml > print_q \} END_TEXT
# Place the output into a table TEXT( begintable(4), row( split("#",$ml>print_a() ) ), row('A', 'B', 'C', 'D' ), endtable(), );
ANS(str_cmp( $ml >ra_correct_ans() ) ) ;
TEXT($END_ONE_COLUMN); ENDDOCUMENT();
Comments:
 Set
$showPartialCorrectAnswers to 0 so that students can't tell which matches are wrong.

pictID is perl's version of a multidimensional array. Strictly speaking @pictID is a list of references (pointers) to arrays, each of which has a number of entries. $pictID[1] is a pointer to an array, and $pictID[1][3] chooses an item in that array (the 4th item since we are counting from 0).
 The way the code is set up the first entry,
$pictID[0] is blank, $pictIC[1] points to an array with entries numbered from 0 to 7, and so forth.

GIF files containing the appropriate graphs have already been created
and placed in the directory containing the static graphics PG template.
The numbering convention is meant to try to keep from giving the answer
away, while still allowing the instructor to do some error checking.
Note the center numbers in each label.
 The variable
$pictSet , chosen as a number
between 1 and 3, chooses a picture set. This set is placed in the
matching list object $ml, along with the matching answers. David Eck's
program xFunctions (for the Macintosh, and now available in java) was
used to draw the graphs and the transformations of the graphs.  Next we want to print the graphs in a table. The standard
print function for matching list objects prints the answers in a
vertically spaced, ordered list which would take up too much space, so
we write a new print function (or subroutine) for the matching list
object called
format_graphs . This print function outputs a string of IMG
tags for the chosen graphs, separated by the # symbol. (The specs for
the matching list require that the output of the print function be a
string and not an array.) 
$ml>rf_print_a(~~&format_graphs); installs the new print function in the matching list object $ml . (The convenction rf_... means that we require a reference to a function. ) &format_graphs is a function, and ~~&format_graphs
is a value which is a reference to that function. Recall that in PG we
use ~~ rather than \ as in ordinary perl, because backslashes are
reserved for TeX like commands for formatting mathematics.  Next comes the text of the problem, including the graph of the original function F
{ image($pictSet) } and the questions involving the transformation of F { $ml > print_q } .
 Next we print the table, with just one row of pictures. The command
split("\#",$ml>print_a() ) splits the string of answers at the # symbol into a list, which is what the macro row requires.
 The answers are letters and are placed in the
ANS function by $ml>ra_correct_ans() . The ra_... convention, means that the ouput is a reference to an array.
< Post or View Comments >
