DynamicImages3: Difference between revisions
		
		
		
		Jump to navigation
		Jump to search
		
|  (New page: <h2>Dynamic Graphic Images, with Filled Regions</h2>  <!--   Header for these sections -- no modification needed -->   <p style="background-color:#eeeeee;border:black solid 1px;padding:3px...) | No edit summary | ||
| Line 24: | Line 24: | ||
| <pre> | <pre> | ||
| DOCUMENT(); | DOCUMENT(); | ||
| loadMacros( | loadMacros( | ||
| "PGstandard.pl", | |||
| "PGgraphmacros.pl", | |||
| # "PGnumericalmacros.pl", # might be useful | |||
| ); | |||
| TEXT(beginproblem()); | TEXT(beginproblem()); | ||
| </pre> | </pre> | ||
| </td> | </td> | ||
| Line 55: | Line 48: | ||
| <td style="background-color:#ffffdd;border:black 1px dashed;"> | <td style="background-color:#ffffdd;border:black 1px dashed;"> | ||
| <pre> | <pre> | ||
| $xmin = random(-3,-1,1); | |||
| $ | $xmax = random(1,3,1); | ||
| $ymin = random(-3,-1,1); | |||
| $ymax = random(1,3,1); | |||
| #  | #  filled triangle with dark border | ||
| $ | $gr1 = init_graph(-4,-4,4,4,grid=>[8,8],axes=>[0,0],pixels=>[300,300]); | ||
| #  | $gr1->new_color("lightgreen",156,215,151); # RGB | ||
| ($ | $gr1->new_color("darkgreen",   0, 86, 34); | ||
| $gr1->moveTo($xmin,$ymin); | |||
| $gr1->lineTo($xmax,$ymin,"darkgreen",2); # bottom edge | |||
| $gr1->lineTo($xmin,$ymax,"darkgreen",2); # hypotenuse | |||
| $gr1->lineTo($xmin,$ymin,"darkgreen",2); # left edge | |||
| $gr1->fillRegion([$xmin+0.1,$ymin+0.1,"lightgreen"]); | |||
| #  filled rectangle with dark border | |||
| #  | $gr2 = init_graph(-4,-4,4,4,grid=>[8,8],axes=>[0,0],pixels=>[300,300]); | ||
| $ | $gr2->new_color("lightblue",148,201,255); | ||
| $gr2->new_color("darkblue", 100,100,255); | |||
| $gr2->im->filledRectangle($xmin,$ymin,$xmax,$ymax,"lightblue"); | |||
| $gr2->im->rectangle($xmin,$ymin,$xmax,$ymax,"darkblue"); | |||
| $ | |||
| </pre> | </pre> | ||
| </td> | </td> | ||
| Line 137: | Line 91: | ||
| <pre> | <pre> | ||
| BEGIN_TEXT | BEGIN_TEXT | ||
| $BCENTER | $BCENTER | ||
| \{  | \{ image( insertGraph($gr1), height=>300, width=>300, tex_size=>800 ) \} | ||
| $ECENTER | $ECENTER | ||
| $PAR | |||
| $ | |||
| $BCENTER | $BCENTER | ||
| \{  | \{ image( insertGraph($gr2), height=>300, width=>300, tex_size=>800 ) \} | ||
| $ECENTER | $ECENTER | ||
| END_TEXT | END_TEXT | ||
| </pre> | </pre> | ||
| Line 187: | Line 113: | ||
| <td style="background-color:#eeddff;border:black 1px dashed;"> | <td style="background-color:#eeddff;border:black 1px dashed;"> | ||
| <pre> | <pre> | ||
| $showPartialCorrectAnswers = 1; | |||
| $ | |||
| ENDDOCUMENT(); | ENDDOCUMENT(); | ||
| </pre> | </pre> | ||
| <td style="background-color:#eeccff;padding:7px;"> | <td style="background-color:#eeccff;padding:7px;"> | ||
Revision as of 00:50, 23 February 2010
Dynamic Graphic Images, with Filled Regions
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 | 
|---|---|
| DOCUMENT(); loadMacros( "PGstandard.pl", "PGgraphmacros.pl", # "PGnumericalmacros.pl", # might be useful ); TEXT(beginproblem()); | 
Initialization:
To do ..(what you are doing)........., we don't have to change the 
tagging and documentation section of the problem file.  
In the initialization section, we need to include the macros file  | 
| 
$xmin = random(-3,-1,1);
$xmax = random(1,3,1);
$ymin = random(-3,-1,1);
$ymax = random(1,3,1);
#  filled triangle with dark border
$gr1 = init_graph(-4,-4,4,4,grid=>[8,8],axes=>[0,0],pixels=>[300,300]);
$gr1->new_color("lightgreen",156,215,151); # RGB
$gr1->new_color("darkgreen",   0, 86, 34);
$gr1->moveTo($xmin,$ymin);
$gr1->lineTo($xmax,$ymin,"darkgreen",2); # bottom edge
$gr1->lineTo($xmin,$ymax,"darkgreen",2); # hypotenuse
$gr1->lineTo($xmin,$ymin,"darkgreen",2); # left edge
$gr1->fillRegion([$xmin+0.1,$ymin+0.1,"lightgreen"]);
#  filled rectangle with dark border
$gr2 = init_graph(-4,-4,4,4,grid=>[8,8],axes=>[0,0],pixels=>[300,300]);
$gr2->new_color("lightblue",148,201,255);
$gr2->new_color("darkblue", 100,100,255);
$gr2->im->filledRectangle($xmin,$ymin,$xmax,$ymax,"lightblue");
$gr2->im->rectangle($xmin,$ymin,$xmax,$ymax,"darkblue");
 | 
Setup: 
We specify that the Context should be  Notes: on using this and related Contexts. | 
| BEGIN_TEXT
$BCENTER
\{ image( insertGraph($gr1), height=>300, width=>300, tex_size=>800 ) \}
$ECENTER
$PAR
$BCENTER
\{ image( insertGraph($gr2), height=>300, width=>300, tex_size=>800 ) \}
$ECENTER
END_TEXT
 | Main Text: The problem text section of the file is as we'd expect. | 
| $showPartialCorrectAnswers = 1; ENDDOCUMENT(); | Answer Evaluation: As is the answer. |