algorytm.org

Implementacja w Java



Baza Wiedzy
wersja offline serwisu przeznaczona na urządzenia z systemem Android
Darowizny
darowiznaWspomóż rozwój serwisu
Nagłówki RSS
Artykuły
Implementacje
Komentarze
Forum
Bookmarki






Sonda
Implementacji w jakim języku programowania poszukujesz?

Transformacja CMY RGB - Implementacja w Java
Ocena użytkownikóww: *****  / 1
SłabyŚwietny
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.java:
/**
  Transformacja pomiedzy modelami CMY i RGB
  www.algorytm.org
  (c)2007 Tomasz Lubinski
 */
public class Cmy_rgb {

	private static double[] cmy2rgb(double c, double m, double y) {
		double result[] = new double[3];
        result[0] = 1.0 - c;
        result[1] = 1.0 - m;
        result[2] = 1.0 - y;
        return result;
}

	private static double[] rgb2cmy(double r, double g, double b){
		double result[] = new double[3];
        result[0] = 1.0 - r;
        result[1] = 1.0 - g;
        result[2] = 1.0 - b;
        return result;
    }
	
	public static void main(String[] args) {
        int x;
        double c,m,y;
        double r,g,b;
        double result[];

        System.out.println("Zakres składowych 0.0 - 1.0");
        System.out.println("1. Dla transformacji CMY -> RGB");
        System.out.println("2. Dla transformacji RGB -> CMY");
        x = Console.readInt("?");
        if (x == 1){
        	c = Console.readDouble("C=");
        	m = Console.readDouble("M=");
        	y = Console.readDouble("Y=");
            result = cmy2rgb(c,m,y);
            System.out.println("R="+result[0]+", G="+result[1]+", B="+ result[2]);
        }
        else {
        	r = Console.readDouble("R=");
        	g = Console.readDouble("G=");
        	b = Console.readDouble("B=");
            result = rgb2cmy(r,g,b);
            System.out.println("C="+result[0]+", M="+result[1]+", Y="+ result[2]);
        }		
	}
}
Dodaj komentarz