Logo

Programming-Idioms

History of Idiom 154 > diff from v13 to v14

Edit summary for version 14 by programming-idioms.org:
[Pascal] Incomplete impl

Version 13

2016-11-12, 21:07:54

Version 14

2016-11-12, 21:11:19

Idiom #154 Halfway between two hex color codes

Find color c, the average between colors c1, c2.

c, c1, c2 are strings of hex color codes: 7 chars, beginning with a number sign # .

Idiom #154 Halfway between two hex color codes

Find color c, the average between colors c1, c2.

c, c1, c2 are strings of hex color codes: 7 chars, beginning with a number sign # .

Extra Keywords
hexa hexadecimal css avg mean radix base
Extra Keywords
hexa hexadecimal css avg mean radix base
Imports
SysUtils, Graphics
Imports
SysUtils, Graphics
Code
var
  c1, c2: string;
  RGB1, RGB2: LongInt;
  R1, G1, B1, R2, G2, B2: Byte;
  c: TColor;
begin
  RGB1 := ColorToRGB(StrToInt(StringReplace(c1,'#','$',[])));
  RGB1 := ColorToRGB(StrToInt(StringReplace(c2,'#','$',[])));
  RedGreenBlue(RGB1, R1, G1, B1);
  RedGreenBlue(RGB2, R2, G2, B2);
  c := RGBToColor(R1+R2 div 2, G1+G2 div 2, B1+B2 div 2);
end.
Code
var
  c1, c2: string;
  RGB1, RGB2: LongInt;
  R1, G1, B1, R2, G2, B2: Byte;
  c: TColor;
begin
  RGB1 := ColorToRGB(StrToInt(StringReplace(c1,'#','$',[])));
  RGB1 := ColorToRGB(StrToInt(StringReplace(c2,'#','$',[])));
  RedGreenBlue(RGB1, R1, G1, B1);
  RedGreenBlue(RGB2, R2, G2, B2);
  c := RGBToColor(R1+R2 div 2, G1+G2 div 2, B1+B2 div 2);
end.
Comments bubble
No error checking on input (c1, c2) is done.
Comments bubble
No error checking on input (c1, c2) is done.

PROBLEM: c must be a string, not a TColor.