AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Color mixer

Ein Thema von WojTec · begonnen am 27. Dez 2011 · letzter Beitrag vom 17. Aug 2012
Antwort Antwort
WojTec

Registriert seit: 17. Mai 2007
482 Beiträge
 
Delphi XE6 Professional
 
#1

Re: Color mixer

  Alt 27. Dez 2011, 20:37
  1. It returns different colors than above script.
  2. When steps > 15 then returns more colors than I want (in other words for steps 1-15 array has 1-15 colors, for more steps array hase more colors than should contain, eg for 16 it contains 19 colors or for 64 --> 99).

Maybe my idea is good but imprecise?
  Mit Zitat antworten Zitat
freeway

Registriert seit: 11. Jul 2009
57 Beiträge
 
Delphi XE Professional
 
#2

AW: Color mixer

  Alt 27. Dez 2011, 21:19
for 100 div (64 + 1) = 1 so you get 100 steps also 100 div (16 +1) = 5 you get 20 steps

Delphi-Quellcode:
 
var V,T : single;
    S : byte;

  V := 100 / (Steps + 1);
  T := 0;

  while T < 100 do
  begin
    T := T + V; //add real
    S := trunc(T); //get byte
    SetLength(Result, Length(Result) + 1);
    Result[High(Result)] := Blend(C1, C2, S);
  end;
end;

Geändert von freeway (27. Dez 2011 um 21:24 Uhr)
  Mit Zitat antworten Zitat
Benutzerbild von Aphton
Aphton

Registriert seit: 31. Mai 2009
1.198 Beiträge
 
Turbo Delphi für Win32
 
#3

AW: Color mixer

  Alt 28. Dez 2011, 05:12
Delphi-Quellcode:
uses Math;
(...)
function GetColors(const C1, C2: TColor; Steps: Byte): TColorArray;

function Blend(const Color1, Color2: TColor; const A: Byte): TColor; // by Aphton
var
  dA : Single;
  c1 : Array[0..3] of Byte Absolute Color1;
  c2 : Array[0..3] of Byte Absolute Color2;
  rs : Array[0..3] of Byte Absolute Result;
begin
  dA := A/100;
  rs[0] := Round(c1[0] + (c2[0] - c1[0]) * dA);
  rs[1] := Round(c1[1] + (c2[1] - c1[1]) * dA);
  rs[2] := Round(c1[2] + (c2[2] - c1[2]) * dA);
  rs[3] := 0;
end;

var
  i: Integer;
  V, T: Byte;
begin
  if Steps < 3 then Exit;

  SetLength(Result, Steps);
  dec(Steps);

  Result[0] := C1;
  Result[Steps] := C2;

  V := 100 div Steps;
  T := 0;

  for i := 1 to Steps - 1 do
  begin
    inc(T, V);
    Result[i] := Blend(C1, C2, Min(T, 100));
  end;
end;
10 Steps on color_tool_mixer.php = 12 with GetColors() (including Color1 and Color2)
Results in...
Angehängte Grafiken
Dateityp: png Untitled.png (35,4 KB, 45x aufgerufen)
das Erkennen beginnt, wenn der Erkennende vom zu Erkennenden Abstand nimmt
MfG

Geändert von Aphton (28. Dez 2011 um 05:36 Uhr)
  Mit Zitat antworten Zitat
Furtbichler
(Gast)

n/a Beiträge
 
#4

AW: Color mixer

  Alt 28. Dez 2011, 07:41
Die Sache mit dem V := 100 div Steps; ist unglücklich und führt zu ungenauen Ergebnissen.

Wieso nicht einfach eine Mischroutine schreiben, die einen Float-Wert als Mischungsverhältnis akzeptiert (also einfach die von Aphton leicht umschreiben).

Delphi-Quellcode:
function Blend(const Color1, Color2: TColor; const MixRatio: Double): TColor; // by Aphton
var
   c1 : Array[0..3] of Byte Absolute Color1;
   c2 : Array[0..3] of Byte Absolute Color2;
   rs : Array[0..3] of Byte Absolute Result;
begin
   rs[0] := Round(c1[0] + (c2[0] - c1[0]) * MixRatio);
   rs[1] := Round(c1[1] + (c2[1] - c1[1]) * MixRatio);
   rs[2] := Round(c1[2] + (c2[2] - c1[2]) * MixRatio);
   rs[3] := 0;
end;
...

Delta := 1/Steps;
MixRatio := 0;
For i:=0 To Steps-1 do begin
  ColorArray[i] := MixColors(Color1, color2, MixRatio);
  MixRatio := MixRatio + Delta
End;
Wer komplett auf Floatingpointarithmetik verzichten will, kann es so probieren
Delphi-Quellcode:
function Blend(const Color1, Color2: TColor; const MixColor1, MixColor2 : Integer): TColor; // by Aphton
// Mische zwei Farben im Verhältnis MixColor1:MixColor2
var
   c1 : Array[0..3] of Byte Absolute Color1;
   c2 : Array[0..3] of Byte Absolute Color2;
   rs : Array[0..3] of Byte Absolute Result;
   MixColors : Integer;

begin
   MixColors := MixColor1 + MixColor2;
   rs[0] := Min(255, (c1[0]*MixColor1 + c2[0]*MixColor2) div MixColors);
   rs[1] := Min(255, (c1[0]*MixColor1 + c2[0]*MixColor2) div MixColors);
   rs[2] := Min(255, (c1[0]*MixColor1 + c2[0]*MixColor2) div MixColors);
   rs[3] := 0;
end;

...
For i:=1 To Steps-1 do
  ColorArray[i] := MixColors(Color1, color2, i, Steps - i - 1);
Die Integer-Variante könnte marginal andere Ergebnisse liefern (sofern sie denn funktioniert).
  Mit Zitat antworten Zitat
Benutzerbild von Aphton
Aphton

Registriert seit: 31. Mai 2009
1.198 Beiträge
 
Turbo Delphi für Win32
 
#5

AW: Color mixer

  Alt 28. Dez 2011, 07:59
Ja stimmt, so ist es eig. besser.
Ich habs ja auch nur schnell hingeschrieben, nicht groß überlegt, sry xD
das Erkennen beginnt, wenn der Erkennende vom zu Erkennenden Abstand nimmt
MfG
  Mit Zitat antworten Zitat
WojTec

Registriert seit: 17. Mai 2007
482 Beiträge
 
Delphi XE6 Professional
 
#6

Re: Color mixer

  Alt 28. Dez 2011, 15:34
Hi, thanks!

Float point version working, but: first element in result is first input color, then steps-1 are real steps. Why?

Second int version is making black-white gradient, why?
Angehängte Grafiken
Dateityp: png Bez*tytułu.png (42,5 KB, 49x aufgerufen)
  Mit Zitat antworten Zitat
Iwo Asnet

Registriert seit: 11. Jun 2011
313 Beiträge
 
#7

AW: Color mixer

  Alt 28. Dez 2011, 15:49
There is a small error in the float-version: If you want 3 steps, you need a delta of 0.5 (0->0.5->1.0), so Delta should be 1/(Steps-1);

Delphi-Quellcode:
Delta := 1/ (Steps-1);
MixRatio := 0;
For i:=0 To Steps-1 do begin
  ColorArray[i] := MixColors(Color1, color2, MixRatio);
  MixRatio := MixRatio + Delta
End;
For question #2 I leave it up to you to find the error yourself (I found it in 5 secs).

Geändert von Iwo Asnet (28. Dez 2011 um 15:51 Uhr)
  Mit Zitat antworten Zitat
WojTec

Registriert seit: 17. Mai 2007
482 Beiträge
 
Delphi XE6 Professional
 
#8

Re: Color mixer

  Alt 19. Apr 2012, 19:48
Guys, how to do something similar, but with color wheel, mean not only 2 colors gradient, but N colors beetwen 2 input colors?
Angehängte Grafiken
Dateityp: png 0.png (6,3 KB, 34x aufgerufen)
  Mit Zitat antworten Zitat
Furtbichler
(Gast)

n/a Beiträge
 
#9

AW: Color mixer

  Alt 20. Apr 2012, 00:17
Are you lazy? Blend Color1->Color2, then Color2->Color3 etc.
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 10:54 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz