Advertisement
Guest User

Untitled

a guest
Mar 14th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.24 KB | None | 0 0
  1. public class CMYKtoRGB {
  2.     public static void main(String[] args) {
  3.  
  4.         // Take 4 color values from command line argument.
  5.         // these numbers will be real numbers from 0.0 to 1.o
  6.         // use the double data type
  7.         // cyan, magenta, yellow, and black will be the order they're inputed
  8.  
  9.         double cyan = Double.parseDouble(args[0]);
  10.         double magenta = Double.parseDouble(args[1]);
  11.         double yellow = Double.parseDouble(args[2]);
  12.         double black = Double.parseDouble(args[3]);
  13.  
  14.         // convert these values to the RGB format
  15.  
  16.         double white = 1 - black;
  17.         double red = 255 * white * (1 - cyan);
  18.         double green = 255 * white * (1 - magenta);
  19.         double blue = 255 * white * (1 - yellow);
  20.  
  21.  
  22.         // now round these values to the nearest integer
  23.  
  24.  
  25.         double red1 = Math.round(red);
  26.         double green1 = Math.round(green);
  27.         double blue1 = Math.round(blue);
  28.  
  29.  
  30.         int red2 = (int) red1;
  31.         int green2 = (int) green1;
  32.         int blue2 = (int) blue1;
  33.  
  34.  
  35.         // now print out the values  :)
  36.  
  37.         System.out.println("red = " + red2);
  38.         System.out.println("green = " + green2);
  39.         System.out.println("blue = " + blue2);
  40.  
  41.  
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement