Posts

Showing posts from December 14, 2018

Color of a Pixel

Image
Clash Royale CLAN TAG #URR8PPP up vote 8 down vote favorite 5 Write a program that prints the RGB color of a given pixel on the screen. The program should read a line from stdin in the format x,y , where x and y are unsigned integers. The pixel (0,0) is the top left pixel in the screen. The program should then output a line to stdout in the format RRR,GGG,BBB , which represents the color of the pixel at ( x , y ). RRR , GGG , and BBB should be floating-point numbers between 0 and 1, OR integers in the range [0, 255]. Leading zeros do not matter, for example: both 074 and 74 are acceptable. Undefined Behavior It is okay for the program to exhibit undefined behavior (crash, give incorrect output, etc) in the following conditions: The user inputs a string, signed integer, float, or any other invalid data type The user input is not in the format x,y The specified pixel is off-screen Notes: The program cannot modify the pixel at the given coordinates. If you have multiple m