1: # The LearningOnline Network with CAPA
2: # Quick Student Grades Display
3: #
4: # $Id: lonquickgrades.pm,v 1.65 2011/01/30 01:21:29 www Exp $
5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28:
29: package Apache::lonquickgrades;
30:
31: use strict;
32: use Apache::Constants qw(:common :http);
33: use POSIX;
34: use Apache::loncommon;
35: use Apache::lonlocal;
36: use Apache::lonnet;
37: use Apache::grades;
38:
39: sub handler {
40: my $r = shift;
41: return real_handler($r);
42: }
43:
44: sub real_handler {
45: my $r = shift;
46:
47: &Apache::loncommon::get_unprocessed_cgi($ENV{QUERY_STRING});
48:
49: # Handle header-only request
50: if ($env{'browser.mathml'}) {
51: &Apache::loncommon::content_type($r,'text/xml');
52: } else {
53: &Apache::loncommon::content_type($r,'text/html');
54: }
55: if ($r->header_only) {
56: $r->send_http_header;
57: return OK;
58: }
59:
60: # Send header, don't cache this page
61: &Apache::loncommon::no_cache($r);
62: $r->send_http_header;
63:
64: my $showPoints =
65: $env{'course.'.$env{'request.course.id'}.'.grading'} eq 'standard';
66: my $notshowSPRSlink =
67: (($env{'course.'.$env{'request.course.id'}.'.grading'} eq 'external')
68: || ($env{'course.'.$env{'request.course.id'}.'.grading'} eq 'externalnototals'));
69: my $notshowTotals=
70: $env{'course.'.$env{'request.course.id'}.'.grading'} eq 'externalnototals';
71: my $showCategories=
72: $env{'course.'.$env{'request.course.id'}.'.grading'} eq 'categories';
73:
74:
75: my $title = "Grading and Statistics";#$showPoints ? "Points Display" : "Completed Problems Display";
76: my $brcrum = [{href=>"/adm/quickgrades",text => "Points Display"}];
77: $r->print(&Apache::loncommon::start_page($title,undef,
78: {'bread_crumbs' => $brcrum})
79: );
80:
81: &startGradeScreen($r,'quick');
82:
83: $r->rflush();
84:
85: # my $uname='korte';
86: # my $udom='gerd';
87:
88: my $uname;
89: my $udom;
90:
91: my ($navmap,$totalParts,$totalPossible,$totalRight,$totalAttempted,$topLevelParts,$topLevelRight,$topLevelAttempted)=
92: &getData($showPoints,$uname,$udom);
93:
94: if ($showCategories) {
95: &outputCategories($r,$showPoints,$notshowTotals,
96: $navmap,$totalParts,$totalPossible,$totalRight,$totalAttempted,$topLevelParts,$topLevelRight,$topLevelAttempted);
97: } else {
98: &outputTable($r,$showPoints,$notshowTotals,
99: $navmap,$totalParts,$totalPossible,$totalRight,$totalAttempted,$topLevelParts,$topLevelRight,$topLevelAttempted);
100: }
101: &endGradeScreen($r);
102: return OK;
103:
104: }
105:
106: sub startGradeScreen {
107: my ($r,$mode)=@_;
108:
109: my $showPoints =
110: $env{'course.'.$env{'request.course.id'}.'.grading'} eq 'standard';
111: my $notshowSPRSlink =
112: (($env{'course.'.$env{'request.course.id'}.'.grading'} eq 'external')
113: || ($env{'course.'.$env{'request.course.id'}.'.grading'} eq 'externalnototals')
114: || ($env{'course.'.$env{'request.course.id'}.'.grading'} eq 'categories'));
115: my $notshowTotals=
116: $env{'course.'.$env{'request.course.id'}.'.grading'} eq 'externalnototals';
117: my $showCategories=
118: $env{'course.'.$env{'request.course.id'}.'.grading'} eq 'categories';
119:
120: my $allowed_to_view = &Apache::lonnet::allowed('vgr',$env{'request.course.id'});
121: my $allowed_to_edit = &Apache::lonnet::allowed('mgr',$env{'request.course.id'});
122:
123: if ($allowed_to_view) {
124: my @notes;
125: push(@notes,&mt('Students do not see total points.')) if ($notshowTotals);
126: push(@notes,&mt('Students do not see link to spreadsheet.')) if ($notshowSPRSlink);
127: push(@notes,&mt('Students will see points based on problem weights.')) if ($showPoints);
128: push(@notes,&mt('Students will see points based on categories.')) if ($showCategories);
129: push(@notes, &Apache::lonhtmlcommon::coursepreflink(&mt('Grade display settings'),'grading'));
130: $r->print(&Apache::loncommon::head_subbox(join(' ',@notes)));
131: }
132:
133:
134: $r->print("\n".'<ul class="LC_TabContentBigger" id="main">');
135: $r->print("\n".'<li'.($mode eq 'quick'?' class="active"':'').'><a href="/adm/quickgrades"><b> '.
136: ($showPoints?&mt('Individual Points Overview'):($showCategories?&mt('Grades Overview'):&mt('Completion Overview'))).
137: ' </b></a></li>');
138:
139: if (!($showPoints || $notshowSPRSlink) || ($allowed_to_view)) {
140: $r->print("\n".'<li'.($mode eq 'spreadsheet'?' class="active"':'').'><a href="/adm/'.($allowed_to_view?'classcalc':'studentcalc').'"><b>'.
141: &mt('Spreadsheet (Detailed)').'</b></a></li>');
142: }
143: if ($allowed_to_view) {
144: $r->print("\n".'<li'.($mode eq 'statistics'?' class="active"':'').'><a href="/adm/statistics"><b>'.
145: &mt('Statistics and Reports').'</b></a></li>');
146:
147: $r->print("\n".'<li'.($mode eq 'chart'?' class="active"':'').'><a href="/adm/statistics?reportSelected=student_assessment"><b>'.
148: &mt('Assessment Overview Chart').'</b></a></li>');
149:
150: }
151: if ($allowed_to_edit) {
152: $r->print("\n".'<li'.($mode eq 'grading'?' class="active"':'').'><a href="/adm/grades"><b> '.
153: &mt('Problem Grading').' </b></a></li>');
154: }
155: $r->print("\n".'</ul>'."\n");
156: $r->print('<div class="LC_Box" style="clear:both;margin:0;"><div id="maincoursedoc" style="margin:0 0;padding:0 0;"><div class="LC_ContentBox" id="mainCourseDocuments" style="display: block;">');
157: }
158:
159: sub endGradeScreen {
160: my ($r)=@_;
161: $r->print('</div></div></div>');
162: }
163:
164:
165: sub getData {
166:
167: my ($showPoints,$uname,$udom)=@_;
168:
169: &Apache::lonnet::logthis("About to call with $uname $udom");
170:
171: # Create the nav map
172: my $navmap = Apache::lonnavmaps::navmap->new($uname,$udom);
173:
174: my $res = $navmap->firstResource(); # temp resource to access constants
175:
176: my $iterator = $navmap->getIterator(undef, undef, undef, 1);
177: my $depth = 1;
178: $iterator->next(); # ignore first BEGIN_MAP
179: my $curRes = $iterator->next();
180:
181: # General overview of the following: Walk along the course resources.
182: # For every problem in the resource, tell its parent maps how many
183: # parts and how many parts correct it has. After that, each map will
184: # have a count of the total parts underneath it, correct and otherwise.
185: # After that, we will walk through the course again and read off
186: # maps in order, with their data.
187: # (If in the future people decide not to be cumulative, only add
188: # the counts to the parent map.)
189: # For convenience, "totalParts" is also "totalPoints" when we're looking
190: # at points; I can't come up with a variable name that makes sense
191: # equally for both cases.
192:
193: my $totalParts = 0; my $totalPossible = 0; my $totalRight = 0;
194: my $totalAttempted = 0;
195: my $now = time();
196: my $topLevelParts = 0; my $topLevelRight = 0; my $topLevelAttempted = 0;
197:
198: # Pre-run: Count parts correct
199: while ( $depth > 0 ) {
200: if ($curRes == $iterator->BEGIN_MAP()) {$depth++;}
201: if ($curRes == $iterator->END_MAP()) { $depth--; }
202:
203: if (ref($curRes) && $curRes->is_problem() && !$curRes->randomout)
204: {
205: # Get number of correct, incorrect parts
206: my $parts = $curRes->parts();
207: my $partsRight = 0;
208: my $partsCount = 0;
209: my $partsAttempted = 0;
210: my $stack = $iterator->getStack();
211:
212: for my $part (@{$parts}) {
213: my $completionStatus = $curRes->getCompletionStatus($part);
214: my $dateStatus = $curRes->getDateStatus($part);
215:
216: if ($completionStatus == $curRes->EXCUSED()) {
217: next;
218: }
219: if ($showPoints) {
220: my $score = 0;
221: # If we're not telling status and the answer date isn't passed yet,
222: # it's an "attempted" point
223: if ((($curRes->problemstatus($part) eq 'no') ||
224: ($curRes->problemstatus($part) eq 'no_feedback_ever')) &&
225: ($dateStatus != $curRes->ANSWER_OPEN)) {
226: my $status = $curRes->simpleStatus($part);
227: if ($status == $curRes->ATTEMPTED) {
228: $partsAttempted += $curRes->weight($part);
229: $totalAttempted += $partsAttempted;
230: }
231: } else {
232: $score = &Apache::grades::compute_points($curRes->weight($part), $curRes->awarded($part));
233: }
234: $partsRight += $score;
235: $totalRight += $score;
236: $partsCount += $curRes->weight($part);
237:
238: if ($curRes->opendate($part) < $now) {
239: $totalPossible += $curRes->weight($part);
240: }
241: $totalParts += $curRes->weight($part);
242: } else {
243: my $status = $curRes->simpleStatus($part);
244: my $thisright = 0;
245: $partsCount++;
246: if ($status == $curRes->CORRECT ||
247: $status == $curRes->PARTIALLY_CORRECT ) {
248: $partsRight++;
249: $totalRight++;
250: $thisright = 1;
251: }
252:
253: if ($status == $curRes->ATTEMPTED) {
254: $partsAttempted++;
255: $totalAttempted++;
256: }
257:
258: my $dateStatus = $curRes->getDateStatus($part);
259: $totalParts++;
260: if ($curRes->opendate($part) < $now) {
261: $totalPossible++;
262: }
263: }
264: }
265:
266: if ($depth == 1) { # in top-level only
267: $topLevelParts += $partsCount;
268: $topLevelRight += $partsRight;
269: $topLevelAttempted += $partsAttempted;
270: }
271:
272: # Crawl down stack and record parts correct and total
273: for my $res (@{$stack}) {
274: if (ref($res) && $res->is_map()) {
275: if (!defined($res->{DATA}->{CHILD_PARTS})) {
276: $res->{DATA}->{CHILD_PARTS} = 0;
277: $res->{DATA}->{CHILD_CORRECT} = 0;
278: $res->{DATA}->{CHILD_ATTEMPTED} = 0;
279: }
280:
281: $res->{DATA}->{CHILD_PARTS} += $partsCount;
282: $res->{DATA}->{CHILD_CORRECT} += $partsRight;
283: $res->{DATA}->{CHILD_ATTEMPTED} += $partsAttempted;
284: }
285: }
286: }
287: $curRes = $iterator->next();
288: }
289: return ($navmap,$totalParts,$totalPossible,$totalRight,$totalAttempted,$topLevelParts,$topLevelRight,$topLevelAttempted);
290: }
291:
292: #
293: # Outputting everything.
294: #
295:
296: sub outputTable {
297:
298: my ($r,$showPoints,$notshowTotals,
299: $navmap,$totalParts,$totalPossible,$totalRight,$totalAttempted,$topLevelParts,$topLevelRight,$topLevelAttempted)=@_;
300:
301: my @start = (255, 255, 192);
302: my @end = (0, 192, 0);
303:
304: my $indentString = ' ';
305:
306: # Second pass: Print the maps.
307: $r->print(&Apache::loncommon::start_data_table()
308: .&Apache::loncommon::start_data_table_header_row()
309: .'<th>'.&mt('Folder').'</th>');
310: my $title = &mt($showPoints ? "Points Scored" : "Done");
311: if ($totalAttempted) {
312: $title .= " / " . &mt("Attempted");
313: }
314: $r->print("<th>$title".($notshowTotals?'':" / ".&mt('Total')).'</th>'
315: .&Apache::loncommon::end_data_table_header_row());
316: #
317: # Output of folder scores
318: #
319:
320: my $iterator = $navmap->getIterator(undef, undef, undef, 1);
321: my $depth = 1;
322: $iterator->next(); # ignore first BEGIN_MAP
323: my $curRes = $iterator->next();
324:
325: while ($depth > 0) {
326: if ($curRes == $iterator->BEGIN_MAP()) {$depth++;}
327: if ($curRes == $iterator->END_MAP()) { $depth--; }
328:
329: if (ref($curRes) && $curRes->is_map()) {
330: my $title = $curRes->compTitle();
331:
332: my $correct = $curRes->{DATA}->{CHILD_CORRECT};
333: my $total = $curRes->{DATA}->{CHILD_PARTS};
334: my $attempted = $curRes->{DATA}->{CHILD_ATTEMPTED};
335:
336: if ($total > 0) {
337: my $ratio;
338: $ratio = $correct / $total;
339: my $color = &mixColors(\@start, \@end, $ratio);
340: $r->print(&Apache::loncommon::start_data_table_row()
341: .'<td style="background-color:'.$color.';">');
342:
343: my $thisIndent = '';
344: for (my $i = 1; $i < $depth; $i++) { $thisIndent .= $indentString; }
345:
346: $r->print("$thisIndent$title</td>");
347: if ($totalAttempted) {
348: $r->print('<td valign="top">'
349: .$thisIndent
350: .'<span class="LC_nobreak">'
351: .$correct.' / '.$attempted.($notshowTotals?'':' / '.$total)
352: .'</span></td>'
353: .&Apache::loncommon::end_data_table_row()
354: );
355: } else {
356: $r->print('<td valign="top">'
357: .$thisIndent
358: .'<span class="LC_nobreak">'
359: .$correct.($notshowTotals?'':' / '.$total)
360: .'</span></td>'
361: .&Apache::loncommon::end_data_table_row());
362: }
363: }
364: }
365:
366: $curRes = $iterator->next();
367: }
368:
369: # If there were any problems at the top level, print an extra "catchall"
370: if ($topLevelParts > 0) {
371: my $ratio = $topLevelRight / $topLevelParts;
372: my $color = mixColors(\@start, \@end, $ratio);
373: $r->print(&Apache::loncommon::start_data_table_row()
374: .'<td style="background-color:'.$color.';">');
375: $r->print(&mt("Problems Not Contained In A Folder")."</td><td>");
376: $r->print("$topLevelRight / $topLevelParts</td>"
377: .&Apache::loncommon::end_data_table_row());
378: }
379:
380: #
381: # show totals (if applicable), close table
382: #
383: if ($showPoints) {
384: my $maxHelpLink = Apache::loncommon::help_open_topic("Quick_Grades_Possibly_Correct");
385:
386: $title = $showPoints ? "Points" : "Parts Done";
387: my $totaltitle = $showPoints ? &mt("Awarded Total Points") : &mt("Total Parts Done");
388: $r->print(&Apache::loncommon::start_data_table_row()
389: .'<td colspan="2" align="right">'.$totaltitle.': <b>'.$totalRight.'</b><br />');
390: $r->print(&mt('Max Possible To Date')." $maxHelpLink: <b>$totalPossible</b><br />");
391: $title = $showPoints ? "Points" : "Parts";
392: $r->print(&mt("Total $title In Course").': <b>'.$totalParts.'</b></td>'
393: .&Apache::loncommon::end_data_table_row());
394: }
395:
396: $r->print(&Apache::loncommon::end_data_table()
397: .&Apache::loncommon::end_page());
398:
399: }
400:
401: #
402: # === Outputting category-based grades.
403: #
404: # $category{'order'}: output order of categories by id
405: # $category{'all'}: complete list of all categories
406: # $category{$id.'_name'}: display-name of category
407: #
408:
409: sub outputCategories {
410:
411: my ($r,$showPoints,$notshowTotals,
412: $navmap,$totalParts,$totalPossible,$totalRight,$totalAttempted,$topLevelParts,$topLevelRight,$topLevelAttempted)=@_;
413: # Take care of storing and retrieving categories
414:
415: my $cangrade=&Apache::lonnet::allowed('mgr');
416:
417: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
418: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
419: my %categories=();
420: # Loading old categories
421: %categories=&Apache::lonnet::dump('grading_categories',$cdom,$cnum);
422: # Storing
423: if (($cangrade) && (($env{'form.storechanges'}) || ($env{'form.storemove'} ne ''))) {
424: # Process the changes
425: %categories=&process_category_edits($r,$cangrade,%categories);
426: # Actually store
427: &Apache::lonnet::put('grading_categories',\%categories,$cdom,$cnum);
428: }
429: # new categories loaded now
430: # Form only generated if user can change the grading categories
431: if ($cangrade) {
432: $r->print('<form method="post">');
433: }
434: #
435: &output_category_table($r,$cangrade,$navmap,%categories);
436: #
437: if ($cangrade) {
438: $r->print('<input type="hidden" name="storemove" value="" />'.
439: '<input type="submit" name="storechanges" value="'.&mt("Save changes to grading categories").'" /></form>');
440: }
441: }
442:
443: #
444: # Process editing commands, update category hash
445: #
446:
447: sub process_category_edits {
448: my ($r,$cangrade,%categories)=@_;
449: unless ($cangrade) { return %categories; }
450: #
451: # Business logic here
452: #
453: return %categories;
454: }
455:
456: #
457: # Output the table
458: #
459:
460: sub output_category_table {
461: my ($r,$cangrade,$navmaps,%categories)=@_;
462: my $sum=0;
463: $r->print(&Apache::loncommon::start_data_table());
464: #
465: &output_category_table_header($r,$cangrade);
466: #
467: my @order=split(/\,/,$categories{'order'});
468: #
469: # FIXME: Debug only
470: @order=('3131_4123_42124','4124_34231_3412');
471: #
472: my $maxpos=$#order;
473: for (my $i=0;$i<=$maxpos;$i++) {
474: my ($value,$weight)=&output_and_calc_category($r,$cangrade,$navmaps,$order[$i],$i,$maxpos,%categories);
475: }
476: #
477: &bottom_line_category($r,$cangrade);
478: #
479: $r->print(&Apache::loncommon::end_data_table());
480: return $sum;
481: }
482:
483: sub output_category_table_header {
484: my ($r,$cangrade)=@_;
485: $r->print(&Apache::loncommon::start_data_table_header_row());
486: if ($cangrade) {
487: $r->print('<th colspan="2">'.&mt("Move").'</th><th>'.&mt('Action').'</th>');
488: }
489: $r->print('<th>'.&mt('Category').'</th>'.
490: '<th>'.&mt('Contents').'</th>'.
491: '<th>'.&mt('Calculation').'</th>'.
492: '<th>'.&mt('Weight').'</th>'.
493: '<th>'.&mt('Percent Overall').'</th>');
494: $r->print(&Apache::loncommon::end_data_table_header_row());
495: }
496:
497:
498: #
499: # Output one category to table
500: #
501:
502: sub output_and_calc_category {
503: my ($r,$cangrade,$navmaps,$id,$currentpos,$maxpos,%categories)=@_;
504: my $value=0;
505: my $weight=0;
506: my $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL') . "/");
507: my %lt=&Apache::lonlocal::texthash(
508: 'up' => 'Move Up',
509: 'dw' => 'Move Down');
510: $r->print("\n".&Apache::loncommon::start_data_table_row());
511:
512: if ($cangrade) {
513: $r->print(<<ENDMOVE);
514: <td>
515: <div class="LC_docs_entry_move">
516: <a href='/adm/quickgrades?cmd=up_$id&storechanges=1'>
517: <img src="${iconpath}move_up.gif" alt='$lt{'up'}' class="LC_icon" />
518: </a>
519: </div>
520: <div class="LC_docs_entry_move">
521: <a href='/adm/quickgrades?cmd=down_$id&storechanges=1'>
522: <img src="${iconpath}move_down.gif" alt='$lt{'dw'}' class="LC_icon" />
523: </a>
524: </div>
525: </td>
526: ENDMOVE
527: $r->print("\n<td>\n<select name='newpos_$id' onchange='this.form.storemove.value=\"$id\";this.form.submit()'>");
528: for (my $i=0;$i<=$maxpos;$i++) {
529: if ($i==$currentpos) {
530: $r->print('<option value="" selected="selected">('.$i.')</option>');
531: } else {
532: $r->print('<option value="'.$i.'">'.$i.'</option>');
533: }
534: }
535: $r->print("\n</select>\n</td>\n");
536:
537: }
538: $r->print(&Apache::loncommon::end_data_table_row()."\n");
539: return ($value,$weight);
540: }
541:
542: #
543: # Bottom line with grades
544: #
545:
546: sub bottom_line_category {
547: my ($r,$cangrade)=@_;
548: }
549:
550: #
551: # Make one new category
552: #
553:
554: sub make_new_category {
555: my ($r,$cangrade,$ordernum,%categories)=@_;
556: unless ($cangrade) { return %categories; }
557: # Generate new ID
558: my $id=time.'_'.$$.'_'.rand(10000);
559: # Add new ID to list of all IDs ever created in this course
560: $categories{'all'}.=','.$id;
561: $categories{'all'}=~s/^\,//;
562: # Add new ID to ordered list of displayed and evaluated categories
563: $categories{'order'}.=','.$id;
564: $categories{'order'}=~s/^\,//;
565: # Move it into desired space
566: if (defined($ordernum)) {
567: %categories=&move_category($id,$cangrade,$ordernum,%categories);
568: }
569: return %categories;
570: }
571:
572: #
573: # Move a category to a desired position n the display order
574: #
575:
576: sub move_category {
577: my ($id,$cangrade,$ordernum,%categories)=@_;
578: unless ($cangrade) { return %categories; }
579: my @order=split(/\,/,$categories{'order'});
580: # Where is the index currently?
581: my $currentpos=¤t_pos_category($id,%categories);
582: if (defined($currentpos)) {
583: if ($currentpos<$ordernum) {
584: # This is moving to a higher index
585: # ....X1234....
586: # ....1234X....
587: for (my $i=$currentpos;$i<$ordernum;$i++) {
588: $order[$i]=$order[$i+1];
589: }
590: $order[$ordernum]=$id;
591: }
592: if ($currentpos>$ordernum) {
593: # This is moving to a lower index
594: # ....1234X....
595: # ....X1234....
596: for (my $i=$currentpos;$i>$ordernum;$i--) {
597: $order[$i]=$order[$i-1];
598: }
599: $order[$ordernum]=$id;
600: }
601: }
602: $categories{'order'}=join(',',@order);
603: return %categories;
604: }
605:
606: #
607: # Find current postion of a category in the order
608: #
609:
610: sub current_pos_category {
611: my ($id,%categories)=@_;
612: my @order=split(/\,/,$categories{'order'});
613: for (my $i=0;$i<=$#order;$i++) {
614: if ($order[$i] eq $id) { return $i; }
615: }
616: # not found
617: return undef;
618: }
619:
620: #
621: # Set name of a category
622: #
623: sub set_category_name {
624: my ($canedit,$id,$name,%categories)=@_;
625: unless ($canedit) { return %categories; }
626: $categories{$id.'_name'}=$name;
627: return %categories;
628: }
629:
630: #
631: # === end category-related
632: #
633: #
634: # Pass this two refs to arrays for the start and end color, and a number
635: # from 0 to 1 for how much of the latter you want to mix in. It will
636: # return a string ready to show ("#FFC309");
637:
638: sub mixColors {
639: my $start = shift;
640: my $end = shift;
641: my $ratio = shift;
642:
643: my ($a,$b);
644: my $final = "";
645: $a = $start->[0]; $b = $end->[0];
646: my $mix1 = POSIX::floor((1-$ratio)*$a + $ratio*$b);
647: $a = $start->[1]; $b = $end->[1];
648: my $mix2 = POSIX::floor((1-$ratio)*$a + $ratio*$b);
649: $a = $start->[2]; $b = $end->[2];
650: my $mix3 = POSIX::floor((1-$ratio)*$a + $ratio*$b);
651:
652: $final = sprintf "%02x%02x%02x", $mix1, $mix2, $mix3;
653: return "#" . $final;
654: }
655:
656: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>