whats new ¦  programming tips ¦  indy articles ¦  intraweb articles ¦  informations ¦  links ¦  interviews
 misc ¦  tutorials ¦  Add&Win Game

Tips (1541)

Database (90)
Files (137)
Forms (107)
Graphic (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Math (76)
Misc (126)
Multimedia (45)
Objects/
ActiveX (51)

OpenTools API (3)
Printing (35)
Strings (83)
System (266)
VCL (242)

Top15

Tips sort by
component


Search Tip

Add new Tip

Add&Win Game

Advertising

46 Visitors Online


 
... calculate a string dependent color?
Autor: Martin Dörig
Homepage: http://www.oberaffig.ch
[ Print tip ]  

Tip Rating (13):  
     


{+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 Funktion MakeColorFromStr errechnet aus einem String eine Farbe.
 Dies kann zum Beispiel benutzt werden um verschiedene Benutzereingaben
 farblich Kennzeichnen zu können.
 Mit der Konstante 'Helligkeit' wird die Minimale Helligkeit verändert
 (z.B. wenn Farbe nicht dunkel sein darf aufgrund von dunkler Schrift
 im Vordergrund
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 This function gives a color back, that has been calculated using
 a string as algorythm parameter.
 The constante "Helligkeit" (brighness) can be used as a threshold to
 control the minimal darkness of the calculated color.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}

{ .... }

function MakeColorFromStr(str: string): TColor;

  { .... }

  
function MakeColorFromStr(str: string): TColor;
  var
    
i, x, y: Cardinal;
  const
    
Helligkeit = 0; //Minimale Helligkeit der Farben (0..255) -->
  
begin
    
y := 1; //initialisieren
    
for i := 1 to Length(str) do
    begin
      
x        := Ord(Str[i]);
      RandSeed := X * i;
      y        := y + Random(99);
    end;
    RandSeed := y;
    Result   := rgb(Random(255 - Helligkeit) + Helligkeit,
      Random(255 - Helligkeit) + Helligkeit,
      Random(255 - Helligkeit) + Helligkeit);
  end;


 

Rate this tip:

poor
very good


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners