[LON-CAPA-cvs] cvs: loncom /homework imageresponse.pm randomlylabel.pm
albertel
lon-capa-cvs@mail.lon-capa.org
Tue, 11 Nov 2003 00:39:33 -0000
albertel Mon Nov 10 19:39:33 2003 EDT
Modified files:
/loncom/homework randomlylabel.pm imageresponse.pm
Log:
- now shows the area of correctness after it is graded correct
(I am open to comments about this bad idea? good idea?)
Index: loncom/homework/randomlylabel.pm
diff -u loncom/homework/randomlylabel.pm:1.11 loncom/homework/randomlylabel.pm:1.12
--- loncom/homework/randomlylabel.pm:1.11 Mon Nov 10 19:25:24 2003
+++ loncom/homework/randomlylabel.pm Mon Nov 10 19:39:33 2003
@@ -2,7 +2,7 @@
# The LearningOnline Network with CAPA
# randomlabel.png: composite together text and images into 1 image
#
-# $Id: randomlylabel.pm,v 1.11 2003/11/11 00:25:24 albertel Exp $
+# $Id: randomlylabel.pm,v 1.12 2003/11/11 00:39:33 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -98,6 +98,19 @@
}
$image->setThickness($width);
$image->line($x1,$y1,$x2,$y2,$imcolor);
+ }
+ for(my $i=0;$i<$ENV{"cgi.$id.BOXCOUNT"};$i++) {
+ my ($x1,$y1,$x2,$y2,$color,$width)=split(':',$ENV{"cgi.$id.BOX$i"});
+ if ($x1 > $x2) { my $temp=$x1;$x1=$x2;$x2=$temp; }
+ if ($y1 > $y2) { my $temp=$y1;$y1=$y2;$y2=$temp; }
+ my (undef,$red,undef,$green,undef,$blue)=split(/(..)/,$color);
+ $red=hex($red);$green=hex($green);$blue=hex($blue);
+ my $imcolor;
+ if (!($imcolor = $image->colorResolve($red,$green,$blue))) {
+ $imcolor = $image->colorClosestHWB($red,$green,$blue);
+ }
+ $image->setThickness($width);
+ $image->rectangle($x1,$y1,$x2,$y2,$imcolor);
}
$image->setThickness(1);
$r->print($image->png);
Index: loncom/homework/imageresponse.pm
diff -u loncom/homework/imageresponse.pm:1.41 loncom/homework/imageresponse.pm:1.42
--- loncom/homework/imageresponse.pm:1.41 Mon Nov 10 19:25:24 2003
+++ loncom/homework/imageresponse.pm Mon Nov 10 19:39:33 2003
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# image click response style
#
-# $Id: imageresponse.pm,v 1.41 2003/11/11 00:25:24 albertel Exp $
+# $Id: imageresponse.pm,v 1.42 2003/11/11 00:39:33 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -104,7 +104,7 @@
}
sub prep_image {
- my ($image)=@_;
+ my ($image,$mode,$name)=@_;
my $part=$Apache::inputtags::part;
my $respid=$Apache::inputtags::response['-1'];
my $id=&Apache::loncommon::get_cgi_id();
@@ -131,6 +131,20 @@
join(':',(($x-$length),($y+$length),($x+$length),($y-$length),
"FF0000",($width)));
}
+ if ($mode eq 'answer') {
+ my $width = 1;
+ my $extrawidth = 2;
+ my @areas = @{ $Apache::response::foilgroup{"$name.area"} };
+ foreach my $area (@areas) {
+ my ($x1,$y1,$x2,$y2)=
+ ($area=~m/rectangle:\(([0-9]+),([0-9]+)\)\-\(([0-9]+),([0-9]+)\)/);
+ my $i=$x{"cgi.$id.BOXCOUNT"}++;
+ $x{"cgi.$id.BOX$i"}=join(':',($x1,$y1,$x2,$y2,"FFFFFF",
+ ($width+$extrawidth)));
+ $i=$x{"cgi.$id.BOXCOUNT"}++;
+ $x{"cgi.$id.BOX$i"}=join(':',($x1,$y1,$x2,$y2,"00FF00",$width));
+ }
+ }
&Apache::lonnet::appenv(%x);
return $id;
}
@@ -157,7 +171,7 @@
if ($target eq 'tex') {
$result.=$Apache::response::foilgroup{"$name.image"}."\\vskip 0 mm \n";
} else {
- my $token=&prep_image($image);
+ my $token=&prep_image($image,'answer',$name);
$result.="<img src=\"/adm/randomlabel.png?token=$token\" /><br />\n";
}
} else {