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

raeburn lon-capa-cvs@mail.lon-capa.org
Sun, 14 Sep 2003 02:38:41 -0000


raeburn		Sat Sep 13 22:38:41 2003 EDT

  Modified files:              
    /modules/raeburn	layering.pl 
  Log:
  
  
  
Index: modules/raeburn/layering.pl
diff -u modules/raeburn/layering.pl:1.1 modules/raeburn/layering.pl:1.2
--- modules/raeburn/layering.pl:1.1	Wed Sep 10 11:31:57 2003
+++ modules/raeburn/layering.pl	Sat Sep 13 22:38:41 2003
@@ -17,11 +17,20 @@
 my $rowspace = 40;
 my $colspace = 40;
 my $fullradius = 550;
+open(PROB,">./layers_xml.problem");
 
-my $total = 1;
+my $output = qq|<problem>
+<allow src="/res/msu/raeburn/problems/images/*.gif" />
+<randomlist show="1">
+|;
+
+
+my $total = 20;
   
 for (my $j=0; $j<$total; $j++)
 {
+  my $correctimg = int(rand(6));
+  my $imagename = "xsection_".$j.".gif";
   open(FILE,">xsection_$j.png");
 # create a new image
   $im = new GD::Image(800,600);
@@ -43,7 +52,36 @@
 
   my $imgcount = 0;
   my %imgid = ();
+  my @shortletts = ("a","b","c","d","e","f");
   my @letts = ("(a)","(b)","(c)","(d)","(e)","(f)");
+
+# Draw the distance scale
+  my $yscale = 30;
+  my $yscale2 = 32;
+  my $xscale1 = 20;
+  my $xpos = 188;
+  
+  my $ysc1 = $yscale-2;
+  my $ysc2 = $yscale-8;
+
+  for (my $t=0; $t<=6; $t++)
+  {
+     $dist = $t*2000;
+     my $xdist = $xscale1+$t*28; 
+     $im->string(gdTinyFont,$xdist,$yscale-20,$dist,$black);
+     $im->line($xdist,$ysc1,$xdist,$ysc2,$black);
+     for (my $s=1; $s<4; $s++)
+     {
+       if($t<6)
+       {
+         $im->line($xdist+$s*7,$ysc1,$xdist+$s*7,$ysc2+4,$black);
+       }
+     }
+  }
+  $im->string( gdSmallFont,$xpos+10,$ysc2,"km",$black);
+  $im->filledRectangle($xscale1,$yscale,$xpos,$yscale2,$black);
+
+
   for (my $row=0; $row<2; $row++)
   {
     for (my $col=0; $col<3; $col++)
@@ -55,19 +93,18 @@
       my $xright = $xleft + $framewidth;
       $im->rectangle($xleft-1,$ytop-1,$xright+1,$ybot+1,$black);
       $im->string(gdMediumBoldFont,$xleft-15,$ytop-15,$letts[$imgcount],$blue);
-      $imgcount ++;
 
 # Create the earth cross section
 # Parameters are radii of inner core, outer core, mantle
 
       my $cy = $ytop + int ($frameheight/2);
       my $cx = $xleft + int ($framewidth/2);
-      my $icore = 278;
+      my $icore = 1215;
       my $ocore = 3478;
       my $mantle = 6328;
       my $whole = 6378;
       my $fullr = $framewidth/2-10;
-      my $conversion = $fullr/6378;
+      my $conversion = $fullr/6378;      
 
       my $sign1 = rand;
       if ($sign1 > 0.5)
@@ -100,21 +137,27 @@
         $sign3 = -1;
       }
 
-      
-      
-      my $ic = int( ($conversion * $icore) * (-1)*$sign1 * rand(0.2)  );
-#      my $oc = int( ($conversion * $ocore) * (-1)*$sign2 * rand(0.2)  );
-
-#      while ($ic >= $oc)
-#      {
-#        $oc = int( ($conversion * $ocore) * (-1)*$sign2 * rand(0.2)  );
-#      }
-
-#      my $mt = int( ($conversion * $mantle) * (-1) * rand(0.2)  );
-
       $mt = int( ($conversion * $mantle) );
       $oc = int( ($conversion * $ocore)  );
       $ic = int( ($conversion * $icore)  );
+      unless ($imgcount == $correctimg)
+      {
+         $oc = int( ($conversion * $ocore) * (1 + (-1)*$sign2 * (0.05 + rand(0.25)))  );
+         while ($oc >= $mt)
+         {
+           $oc = int( ($conversion * $ocore) * (1 + (-1)*$sign2 * (0.05 + rand(0.25)))  );
+         }
+         $ic = int( ($conversion * $icore) *(1 + (-1)*$sign1 * (0.05 +  rand(0.25)))  );
+         while ($ic >= $oc)
+         {
+           $ic = int( ($conversion * $icore) *(1 + (-1)*$sign1 * (0.05 + rand(0.25)))  );
+         }
+         $mt = int( ($conversion * $mantle) * (1 + (-1) * (0.05 + rand(0.4)))  );
+         while ($oc >= $mt)
+         {
+            $mt = int( ($conversion * $mantle) * (1 + (-1) * (0.05 + rand(0.35)))  );
+         }
+      }
 
       $im->arc($cx,$cy,$fullr*2,$fullr*2,0,360,$blue);
       $im->fillToBorder($cx,$cy,$blue,$blue);
@@ -124,13 +167,84 @@
       $im->fillToBorder($cx,$cy,$yellow,$yellow);
       $im->arc($cx,$cy,$ic*2,$ic*2,0,360,$red);
       $im->fillToBorder($cx,$cy,$red,$red);
-
-# make sure we are writing to a binary stream
-      binmode STDOUT;
+      $imgcount ++;
     }
   }
+# Draw the legend
+  my $ystart = $topindent + $frameheight*2 + $rowspace + $botindent/2;
+  my $yend = $ystart + 20;
+  my $crstart = $leftindent;
+  my $crend = $crstart + 20;
+  my $crkey = $crend + 5;
+  $im->rectangle($crstart,$ystart,$crend,$yend,$black);
+  $im->filledRectangle($crstart+1,$ystart+1,$crend-1,$yend-1,$blue);
+  $im->string(gdSmallFont,$crkey,$yend-10,"Crust",$black);
+
+  my $mastart = $leftindent + 100;
+  my $maend = $mastart + 20;
+  my $makey = $maend + 5;
+  $im->rectangle($mastart,$ystart,$maend,$yend,$black);
+  $im->filledRectangle($mastart+1,$ystart+1,$maend-1,$yend-1,$orange); 
+  $im->string(gdSmallFont,$makey,$yend-10,"Mantle",$black);
+
+  my $ocstart = $leftindent + 200;
+  my $ocend = $ocstart + 20;
+  my $ockey = $ocend + 5;
+  $im->rectangle($ocstart,$ystart,$ocend,$yend,$black);
+  $im->filledRectangle($ocstart+1,$ystart+1,$ocend-1,$yend-1,$yellow); 
+  $im->string(gdSmallFont,$ockey,$yend-10,"Outer Core",$black);
+
+  my $icstart = $leftindent + 300;
+  my $icend = $icstart + 20;      
+  my $ickey = $icend + 5;      
+  $im->rectangle($icstart,$ystart,$icend,$yend,$black);      
+  $im->filledRectangle($icstart+1,$ystart+1,$icend-1,$yend-1,$red);      
+  $im->string(gdSmallFont,$ickey,$yend-10,"Inner Core",$black);   
+
 # Convert the image to JPEG and print it on standard output
+# make sure we are writing to a binary stream
+  binmode FILE;
   print FILE $im->png;
   close(FILE);
+  $output .= qq| 
+<radiobuttonresponse max="6" randomize="yes">
+<startouttext />
+<table>
+<tr>
+<td>
+<img src="../images/$imagename" />
+</td>
+</tr>
+</table>
+<br/>
+The image above shows six different models for the thicknesses of the different layers in the earth (crust, mantle, outer core, inner core).
+Only one of these shows the layers with their correct thicknesses.  Pick the model that is correct 
+based on our knowledge of the internal structure of the earth that comes from the study of seismic waves.
+ <endouttext />
+ <foilgroup>
+  |;
+  for (my $k=0; $k<$imgcount; $k++)
+  {
+    my $foilname = "foil".$shortletts[$k];
+    if ($k == $correctimg)
+    {
+      $output .= qq|<foil location="random" value="true" name="$foilname">\n|;
+    }
+    else
+    {
+      $output .= qq|<foil location="random" value="false" name="$foilname">\n|;
+    }
+    $output .= qq|<startouttext />$letts[$k]
+  <endouttext />
+ </foil>
+    |;
+  }
+  $output .= "  </foilgroup>
+ </radiobuttonresponse>\n";
 }
+$output .= "</randomlist>
+</problem>";
+print PROB  $output;
+close(PROB);
+exit;