Ocena użytkownikóww: ***** / 2
Nadesłany przez Tomasz Lubiński, 17 listopada 2007 01:00
Kod przedstawiony poniżej przedstawia główną część rozwiązania problemu.
Pobierz pełne rozwiązanie.Jeżeli nie odpowiada Ci sposób formatowania kodu przez autora skorzystaj z pretty printer'a i dostosuj go automatycznie do siebie.
cmy_rgb_d/cmy_rgb.dpr:
// Transformacja pomiedzy modelami CMY i RGB
// www.algorytm.org
// (c)2007 Tomasz Lubinski
program cmy_rgb;
{$APPTYPE CONSOLE}
uses
SysUtils, Math;
type
results = Array [1..3] of Integer;
function cmy2rgb(c: Integer; m: Integer; y: Integer): results;
var
rgb: results;
begin
rgb[1] := 255 - c;
rgb[2] := 255 - m;
rgb[3] := 255 - y;
result := rgb;
end;
function rgb2cmy(r: Integer; g: Integer; b:Integer): results;
var
cmy: results;
begin
cmy[1] := 255 - r;
cmy[2] := 255 - g;
cmy[3] := 255 - b;
result := cmy;
end;
var
x: Integer;
c,m,y: Integer;
r,g,b: Integer;
res: results;
begin
writeln('Zakresy skladowych 0-255');
writeln('1. Dla transformacji CMY -> RGB');
writeln('2. Dla transformacji RGB -> CMY');
readln(x);
if x = 1 then
begin
write('C=');
readln(c);
write('M=');
readln(m);
write('Y=');
readln(y);
res := cmy2rgb(c,m,y);
write('R='+FloatToStr(res[1])+
', G='+FloatToStr(res[2])+
', B='+FloatToStr(res[3]));
end
else
begin
write('R=');
readln(r);
write('G=');
readln(g);
write('B=');
readln(b);
res := rgb2cmy(r,g,b);
write('C='+FloatToStr(res[1])+
', M='+FloatToStr(res[2])+
', Y='+FloatToStr(res[3]));
end;
readln;
end.