Tux L i n u x * G u i d e

v o n * I n g o * B l e c h s c h m i d t * ( c ) * 2 0 0 1
Tux
|Home|

|Neue Artikel|

|Index|

|Liste|

|Code-Snippets|

|Links|

|Allgemeines|

|Cool Stuff|
Farbverlauf mit Perl
Mon Aug 27 13:32:52 MEST 2001
Verlauf Farbverlauf Perl HTML

Sie wollen einen Farbverlauf automatisch mittels Perl generieren.

LinuxGuide Druckbare Version
Man-Page
Sourcecode
Verwandte Artikel:

Bilder-Archiv
HTML-Markups in Text umsetzen
Perl-Sicherheitslücken decken
Term::Cap in Perl
VIM als HTML-Editor
Zeitdiagramm erstellen
Operationen mit Dateien in Perl
CSV2HTML
Der HTML-Automat
Entropie
Perl-Präprozessor
Text2HTML
Sichere Passwörter generieren



      .~.   
      /V\   
     // \\  
    /(   )\ 
     ^`~'^  
     


Hosted at Sorceforge.net
No ePATENTS
Viewable With Any Browser
Burn All GIFs!



  •                                                   
                                                      
                                                      
                                                      
                                                      
  •                                                   
                                                      
                                                      
                                                      
                                                      
  •                                                   
                                                      
                                                      
                                                      
                                                      
  •                                                   
                                                      
                                                      
                                                      
                                                      
  •                                                   
                                                      
                                                      
                                                      
                                                      
  •                                                   
                                                      
                                                      
                                                      
                                                      
Dabei lässt sich die Größe und Start- und End-Farbe natürlich ändern.
Der Aufruf:
# Aufruf
 
# ./verlauf.pl d s1 s2 s3 e1 e2 e3 maxx maxy
 
 

Die Parameter:
d
Kann r oder l sein, gibt die Stelle des Hotspots an.
s1, s2, s3
Die Hexadezimalen Start-RGB-Werte des Farbverlaufs.
e1, e2, e3
Die Hexadezimalen End-RGB-Werte des Farbverlaufs.
maxx, maxy
Maximale Breite und Höhe

Die Ausgabe des Skripts ist eine HTML-Tabelle, die sofort in HTML-Dateien eingebunden werden kann.
Das Skript, Download:
# verlauf.pl
 
#!/usr/bin/perl -w
#
#  This program is free software; you can redistribute it
#  and/or modify it under the terms of the GNU General Public
#  License as published by the Free Software Foundation;
#  either version 2 of the License, or (at your option) any
#  later version.
#
#  This program is distributed in the hope that it will be
#  useful, but WITHOUT ANY WARRANTY; without even the implied
#  warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
#  PURPOSE.  See the GNU General Public License for more
#  details.
#
#  You should have received a copy of the GNU General Public
#  License along with this program; if not, write to the Free
#  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA
#  02139, USA.
#
# Ingo Blechschmidt
# Arberstraße 5
# 86179 Augsburg
# E-Mail: iblech@web.de, http://www.way.to/uselinux/
# Tel.: +49 / 821 882955
#
# 

@start  = ();
@ende   = ();
@stepx  = ();
@stepy  = ();
$maxx   = 10;
$maxy   = 20;
$i      = 0;
$j      = 0;
$k      = 0;
@matrix = ();
$spot   = '';
$spot   = $ARGV[0] ? $ARGV[0] : 'l';

@start = qw(nil ff 80 33);			# Initialisierung
@ende  = qw(nil ff 89 44);
@start = (0, "$ARGV[1]", "$ARGV[2]", "$ARGV[3]")
              if (defined $ARGV[1]);
@ende  = (0, "$ARGV[4]", "$ARGV[5]", "$ARGV[6]")
              if (defined $ARGV[4]);
$maxx  = $ARGV[7] if (defined $ARGV[7]);
$maxy  = $ARGV[8] if (defined $ARGV[8]);
for ($i = 1; $i <= 3; $i++) {
  $start[$i] = hex($start[$i]);
  $ende[$i]  = hex($ende[$i]);
}
for ($i = 1; $i <= 3; $i++) {
  $stepx[$i] = abs(($start[$i] - $ende[$i]) / $maxx);
  $stepy[$i] = abs(($start[$i] - $ende[$i]) / $maxy);
}

for($i = 1; $i <= $maxx; $i++) {		# Berechnung
  for($j = 1; $j <= $maxy; $j++) {
    for($k = 1; $k <= 3; $k++) {
      $matrix[$maxx - $i + 1][$j][$k] = $ende[$k] +
                              ($stepx[$k] * ($i - 1) +
			      $stepy[$k] * ($j - 1)) / 4
			          if ($spot eq 'r');
      $matrix[$maxx - $i + 1][$maxy - $j + 1][$k] = $ende[$k] +
                              ($stepx[$k] * ($i - 1) +
			      $stepy[$k] * ($j - 1)) / 4
			          if ($spot eq 'l');
    }
  }
}

print
  '<table border="0" cellpadding="0" cellspacing="0" summary="">' .
  "\n";
for ($i = 1; $i <= $maxx; $i++) {		# Umrechnung in hex
  print "<tr>";
  for ($j = 1; $j <= $maxy; $j++) {		# und Ausgabe
    print '<td bgcolor="#';
    for ($k = 1; $k <= 3; $k++) {
      $matrix[$i][$j][$k] = 255 if ($matrix[$i][$j][$k] > 255);
      print ((0 .. 9, 'a' .. 'f')[int($matrix[$i][$j][$k] / 16)],
             (0 .. 9, 'a' .. 'f')[$matrix[$i][$j][$k] % 16]);
#      print " ";
    }
    print '">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>';
  }
  print "</tr>\n";
}
print "</table>";

1;
 
 

Document Informations: Content-Type: text/html; charset=iso-8859-1
Author: Ingo Blechschmidt
Description: LinuxGuide - Sie wollen einen Farbverlauf automatisch mittels Perl generieren.
Keywords: Verlauf, Farbverlauf, Perl, HTML, LinuxGuide
Robots: all
Copyright: Copyright (C) 2002 by Ingo Blechschmidt
Date: 2003-08-27T13:32:52+02:00

Stichwortverzeichnis | Neue Artikel | Übersicht | Codesnippets | Links | Copyright | Cool Stuff | Home | Druckbare Version | Manpage | Sourcecode |
Diesen Artikel kritisieren, kommentieren oder ergänzen
Einen Neuen Artikel schreiben

 
This website is distributed under the GNU Free Documentation License .