Entwickler-Ecke

Multimedia / Grafik - Wieder mal Farbverlauf Fehler


ALF - Mi 03.11.10 15:26
Titel: Wieder mal Farbverlauf Fehler
Dabei hab ich das schon mal gemacht :oops: Allerdings von einem vorgegenen RGB zu weiss
Hier mal mein Code. Die Vorlage hab ich von user profile iconjaenicke.
zur Erklärung, es sollen nur die letzten 70 Pixel von 200 in der Breite ein Farbverlauf erhalten.

Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
if FillSize > 130 then
begin
    RValueInc := GetRValue(FEndColor - FStartColor) / W-130;// W = 200 Pixel
    GValueInc := GetGValue(FEndColor - FStartColor) / W-130;
    BValueInc := GetBValue(FEndColor - FStartColor) / W-130;
    for I:= 130 to FillSize do
    begin  //ab hier passiert alles mögliche nur nicht der gewünschte Farbverlauf
        Pen.Color := FStartColor + RGB(Round((i-130) * RValueInc), Round((i-130) * GValueInc),Round((i-130) * BValueInc));

       //Pen.Color:=  RGB(Round((RValueInc+(255-RValueInc))/ (W-130)*(I-130)), Round((GValueInc+(255-GValueInc))/ (W-130)*(I-130)),Round((BValueInc+(255-BValueInc))/ (W-130)*(I-130)));
        
        moveto(I, 0);
        LineTo(I, W);
    end;
end;
Wo hab ich da schon wiedermal einen Denkfehler? Ich erhalte zwar ein Farbverlauf aber nicht in den Farben von StartColor zu EndColor. Dabei ist es nur Mathe, aber in welcher Reihenfolge? :gruebel:

Gruss Alf


Oliver Marx - Mi 03.11.10 16:55

Hi,

ich glaube, du hast da nur ein paar Klammern vergessen.


Delphi-Quelltext
1:
2:
3:
    RValueInc := GetRValue(FEndColor - FStartColor) / (W-130);// W = 200 Pixel
    GValueInc := GetGValue(FEndColor - FStartColor) / (W-130);
    BValueInc := GetBValue(FEndColor - FStartColor) / (W-130);


Viele Grüße

Oliver


ALF - Mi 03.11.10 17:47

Ne, gerade rausgefunden das kann so nicht funcen. Ich muss wahrscheinlich für beide, StartColor und EndColor, ne differenz zu 255 machen oder zur Pixelzahl oder so :gruebel: Weil, wenn StartColor > als EndColor oder auch umgekehrt, irgendwann ja der RGBWert >255 bzw <0 wird zur Pixelzahl mh.... :?!?: Blöde Logik
DAs wird ja richtig kompliziert :eyecrazy:
Edit: Leider noch nicht ganz? Aber fast, der Anfangswert stimmt nicht ganz?


Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
if fillSize > 130 then
begin
    RsValue:= GetRValue(FStartColor);
    GsValue:= GetGValue(FStartColor);
    BsValue:= GetBValue(FStartColor);
    
    ReValue:= GetRValue(FEndColor);
    GeValue:= GetGValue(FEndColor);
    BsValue:= GetBValue(FEndColor);
    
    for I:=130 to FillSize do
    begin
        Pen.Color:=  RGB(Round(RsValue +(ReValue-RsValue)/ (W-130)*(I-130)),
                         Round(GsValue +(GeValue-GsValue)/ (W-130)*(I-130)),
                         Round(BsValue +(BeValue-BsValue)/ (W-130)*(I-130)));

        moveto(I, 0);
        LineTo(I, W);
    end;
end;


Gruss ALf


platzwart - Mi 03.11.10 18:35


Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
    RsValue:= GetRValue(FStartColor);
    GsValue:= GetGValue(FStartColor);
    BsValue:= GetBValue(FStartColor);
    
    ReValue:= GetRValue(FEndColor);
    GeValue:= GetGValue(FEndColor);
    BsValue:= GetBValue(FEndColor);


ALF - Mi 03.11.10 18:44

Ach ich liebe meine Blindheit

THX nun klappts auch mit der Farbe.

Gruss Alf