[LON-CAPA-cvs] cvs: modules /raeburn drift.pl

raeburn lon-capa-cvs@mail.lon-capa.org
Fri, 19 Sep 2003 18:27:33 -0000


raeburn		Fri Sep 19 14:27:33 2003 EDT

  Added files:                 
    /modules/raeburn	drift.pl 
  Log:
  drift.pl added to modules/raeburn. Used to create homework problem to test understanding of continental drift.
  
  
  

Index: modules/raeburn/drift.pl
+++ modules/raeburn/drift.pl
#!/usr/bin/perl
use GD;

# Setting random seed
srand (time() ^ ($$ + ($$  << 15)) );

# Global parameters
my $scaleEnd = 40;
my $framewidth = 390;
my $frameheight = 220;
my $leftindent = 5;
my $rightindent = 5;
my $topindent = 10;
my $botindent = 10;
my $rowspace = 10;
my $colspace = 10;
my $total = 20;
my $output = qq|
<problem>
<allow src="/res/msu/raeburn/problems/images/drift*.gif" />
<randomlist show="1">
|;

for (my $j=0; $j<$total; $j++)
{
  my $count = 0;
  my $duration =  0;
  my $end =0;
  my $start = 0;
  my $x1 = 0;
  my $x2 = 0;
  my $imagename = "drift_".$j.".png";
  open(FILE,">$imagename");
  
# create a new image
  $im = new GD::Image(800,700);

# allocate some colors
  my $white = $im->colorAllocate(255,255,255);
  my $black = $im->colorAllocate(0,0,0);
  my $green = $im->colorAllocate(255,255,0);
  my $blue =$im->colorAllocate(0,0,255);
  my @colors = ($black,$white);

# make the background transparent and interlaced
  $im->transparent($white);
  $im->interlaced('true');

# Put a black frame around the picture
  $im->rectangle(0,0,799,699,$black);
  
  my $imgcount = 0;
  my @letts = ("(a)","(b)","(c)","(d)","(e)","(f)");
  my @picked = ();
  for (my $row=0; $row<3; $row++)
  {
    for (my $col=0; $col<2; $col++)
    { 
# Draw bounding box.     
      my @mapcol = ();
      my $ytop = $topindent+($colspace+$frameheight)*$row;
      my $ybot = $ytop + $frameheight;
      my $xleft = $leftindent+($rowspace+$framewidth)*$col;
      my $xright = $xleft + $framewidth;
#      $im->rectangle($xleft-1,$ytop-1,$xright+1,$ybot+1,$black);
      $im->string(gdLargeBoldFont,$xleft+15,$ytop+15,$letts[$imgcount],$black);
      
      my $num = 20 * int( rand(12) );
      my $odd =  rand(1);
      if ($odd > 0.5)
      {
        $odd = 1;
      }
      else
      {
        $odd = 0;
      }
      if ($odd)
      {
        unless ($num == 220)
        {
          $num += 10;
        }
      }
      while (grep/^$num$/,@picked)
      { 
        $num = 20 * int( rand(12) );
        if ($odd)
        {
          unless ($num == 220)
          {
            $num += 10;
          }
        }
      }
      push @picked,$num;
      $maplett{$num} = $letts[$imgcount];
      my $file = "pangaea".$num.".png";
      open(DRIFTFILE,"<images/$file");
      my $img = GD::Image->newFromPng(\*DRIFTFILE);
      $img->transparent($img->getPixel(0,0));
      $im->copy($img,$xleft,$ytop,0,0,384,199);
      close(DRIFTFILE);
      $imgcount ++;
    }
  }
  
  # make sure we are writing to a binary stream
  binmode STDOUT;

# Convert the image to PNG and print it on standard output
  binmode FILE;
  print FILE $im->png;
  close(FILE);

# sort numerically
  my %rank = ();
  my @sorted = reverse sort { $a <=> $b } @picked;
  for (my $k=0; $k<@sorted; $k++)
  {
    $rank{$maplett{$sorted[$k]}} = $k+1;
  }
  $output .= qq| 
<rankresponse max="6" randomize="yes">
<startouttext />
<table>
<tr>
<td>
<img src="../images/$imagename" />
</td>
</tr>
</table>
<br/>
The maps above show the positions of the continents at siz different times during the past 220 million years.  Based on your knowledge of continental drift, 
order the maps from oldest to youngest, with the oldest ranked as 1, and the most recent ranked as 6.  As an example if you thought
that (b) was oldest, then (c), then (a) etc., you would set (a) to 3, (b) to 1, (c) to 2 and so on.<endouttext />
 <foilgroup>
  <foil location="random" value="$rank{'(a)'}" name="foila"><startouttext />(a)<endouttext /></foil>
  <foil location="random" value="$rank{'(b)'}" name="foilb"><startouttext />(b)<endouttext /></foil>
  <foil location="random" value="$rank{'(c)'}" name="foilc"><startouttext />(c)<endouttext /></foil>
  <foil location="random" value="$rank{'(d)'}" name="foild"><startouttext />(d)<endouttext /></foil>
  <foil location="random" value="$rank{'(e)'}" name="foile"><startouttext />(e)<endouttext /></foil>
  <foil location="random" value="$rank{'(f)'}" name="foilf"><startouttext />(f)<endouttext /></foil>
 </foilgroup>
</rankresponse>
  |;
}
$output .= "</randomlist>
</problem>";
print $output;
exit;