[Date Index][Thread Index]
[Date Prev][Date Next][Thread Prev][Thread Next]

[Patch wml::des::imgbg] Gradients



Here is the third patch i wrote.
It draws gradient colors ; the new specification of ``contents'' is a
comma separated list of 
  pixels:#rrggbb[:#rrggbb[[:number]]
Square brackets mean optional arguments ; if a second color is
specified, a gradient will be drawn from the first color to the second.
Total number of colors used in this gradient is ``number'' (default 10).

Feel free to modify what youy want.

Greetings

   Denis

--- wml-1.6.7/wml_include/des/imgbg.src	Fri Jan 16 17:22:23 1998
+++ wml-1.6.7/wml_include/des/imgbg.src	Wed Dec 30 08:54:58 1998
@@ -12,7 +12,9 @@
 #   general function for creating the image
 sub imgbg {
     my ($base, $direction, $content) = @_;;
-    my ($file, $id, @C, $size, $im, $c, $r, $g, $b, $col, $w, $x, $y);
+    my ($file, $id, @C, $size, $im, $c, $r, $g, $b, $col, $w, $x);
+    my ($nbcol, $bcol, $ecol, $rmin, $gmin, $bmin, $rmax, $gmax, $bmax);
+    my ($i, $dx, $dy);
     local (*FP);
 
     #   determine filename
@@ -35,31 +37,42 @@
         $size += $1 if ($c =~ m|^(\d+):.+|);
     }
 
-    #   create GIF image if still not exits
+    #   create GIF image if still not exists
     if (not -f $file) {
+        $x = 0;
         if ($direction eq 'h') {
             #   horizontal image
             $im = new GD::Image($size, 1);
-            $x = 0;
-            foreach $c (@C) {
-                ($w, $col) = ($c =~ m|^(\d+):(.+)$|);
-                ($r, $g, $b) = &triple2rgb($col);
-                $col = $im->colorAllocate($r, $g, $b);
-                $im->rectangle($x, 0, $x+$w, 1, $col);
-                $x += $w;
-            }
-        }
-        else {
+            $dx = 1;
+            $dy = 0;
+        } else {
             #   vertical image
             $im = new GD::Image(1, $size);
-            $y = 0;
-            foreach $c (@C) {
-                ($w, $col) = ($c =~ m|^(\d+):(.+)$|);
-                ($r, $g, $b) = &triple2rgb($col);
+            $dx = 0;
+            $dy = 1;
+        }
+        foreach $c (@C) {
+            ($w, $bcol, $ecol, $nbcol) =
+                ($c =~ m|^(\d+):([^:]+)(?::)?([^:]+)?(?::)?(\d+)?$|);
+            if ($ecol eq '' ) {
+                ($ecol, $nbcol) = ($bcol, 1);
+            } elsif ($nbcol eq '' ) {
+                $nbcol = 10;
+            }
+            ($rmin, $gmin, $bmin) = &triple2rgb($bcol);
+            ($rmax, $gmax, $bmax) = &triple2rgb($ecol);
+            for ($i=1; $i<=$nbcol; $i++) {
+                $r = $rmin + ($rmax-$rmin)*$i/$nbcol;
+                $g = $gmin + ($gmax-$gmin)*$i/$nbcol;
+                $b = $bmin + ($bmax-$bmin)*$i/$nbcol;
                 $col = $im->colorAllocate($r, $g, $b);
-                $im->rectangle(0, $y, 1, $y+$w, $col);
-                $y += $w;
+                $im->line($dx*($x+$w*($i-1)/$nbcol),
+                          $dy*($x+$w*($i-1)/$nbcol),
+                          $dx*($x+$w*$i/$nbcol),
+                          $dy*($x+$w*$i/$nbcol),
+                          $col);
             }
+            $x += $w;
         }
         open(FP, ">$file");
         print FP $im->gif;
@@ -73,7 +86,7 @@
 <preserve base>
 <preserve direction>
 <preserve content>
-<set-var %0 %1 %2 %3 %4 %5 %6 %7 %8 %9>
+<set-var %attributes>
 <:
     #   import attributes to ePerl 
     $base      = qq|<get-var base>|;
@@ -153,10 +166,17 @@
 
 =item C<content>
 
-This is a comma-separated list of size/color pairs. The syntax of these pairs
-is ``I<pixels>C<:#>I<rrggbb>''. To get a backround with two columns, a black
-one with 150 point in size and a white one which fills the rest of the page
-use ``C<150:#000000,1200:#ffffff>''. 
+This is a comma-separated list of size/color specifications. The syntax
+is ``I<pixels>C<:#>I<rrggbb>C<[:#>I<rrggbb>C<[:>I<number>C<]]>''.
+``I<pixels>'' is the width of this line of color.
+When olny one color is used, it is the color of this line.
+If a second color is used, a gradient will be drawn from
+the former to the latter colors. The number of colors used in this
+gradient is ``I<number>'' (default=10).
+To get a backround with two columns, a black one with 150 point in size
+and a white one which fills the rest of the page use
+``C<150:#000000,1200:#ffffff>''.  To have a nice gradient-grey, use
+``C<70:#000000,80:#000000:#ffffff:40,1200:#ffffff>''.
 
 =back


______________________________________________________________________
Website META Language (WML)                www.engelschall.com/sw/wml/
Official Support Mailing List                   sw-wml@engelschall.com
Automated List Manager                       majordomo@engelschall.com