====== cs19s23as07: HSV Color Class ====== ===== Goals ===== * Practice with object-oriented design and operator overloading in C++. * Learn a bit about color representation and color theory. ----- ====== Prerequisites ====== This assignment requires familiarity with the [[:lecture materials/]] presented in class through [[:lecture materials/week 07]]. ----- ====== Background ====== {{:pixel_geometry_01_pengo.jpg?nolink|Image showing different kinds of RGB pixels on different kinds of displays. Courtesy https://commons.wikimedia.org/wiki/File:Pixel_geometry_01_Pengo.jpg}} You may be familiar with RGB colors, and/or the [[https://en.wikipedia.org/wiki/RGB_color_model|RGB color model]]. It's a pretty simple idea, where values representing an amount of red, green, and blue light are "added" together to form a color. This is a common representation due to the fact that the [[https://en.wikipedia.org/wiki/Pixel_geometry|pixels]] on most screens (such as LCDs and CRTs) are generated by devices that emit red, green or blue light, mainly because [[https://en.wikipedia.org/wiki/RGB_color_model#Physical_principles_for_the_choice_of_red,_green,_and_blue|those are three wavelengths of light to which human eyes are most sensitive]] (for fairly obvious reasons). As [[https://en.wikipedia.org/wiki/HSL_and_HSV|per the arbiter of all human information]]: > **HSL** (for **hue, saturation, lightness**) and **HSV** (for **hue, saturation, value**; also known as **HSB**, for hue, saturation, brightness) are alternative representations of the RGB color model, designed in the 1970s by computer graphics researchers to more closely align with the way human vision perceives color-making attributes. In these models, colors of each hue are arranged in a radial slice, around a central axis of neutral colors which ranges from black at the bottom to white at the top. {{:hsv_color_solid_cylinder.png?nolink|Illustration of the three components of the HSV color model on a cylinder, where the distance from the vertical center shows increasing saturation, values increase vertically, and hues are uniformly distributed around the circumference of the cylinder. Courtesy https://commons.wikimedia.org/wiki/File:HSV_color_solid_cylinder.png}} Using a representation like HSV makes it much easier to modify and interpret colors in an intuitive way, such as calculating [[https://en.wikipedia.org/wiki/Complementary_colors|complementary colors]] or varying a color's apparent brightness/intensity.
----- ====== Assignment ====== You shall create a class in the ''cs19'' namespace named ''HsvColor'', defined in header file ''cs19_hsv_color.h'' and implemented in file ''cs19_hsv_color.cpp''. Instances of ''cs19::HsvColor'' represent immutable HSV colors, where each of the three components (**hue**, **saturation** and **value**) of a color is represented as a ''float''. ''cs19::HsvColor'' also offers a few overloaded operators and other functions, including several related to converting a HSV color to its equivalent 24-bit RGB components. Specifically, design your class to accommodate at least the public functions specified in [[http://jeff.cis.cabrillo.edu/datasets/docs_cs19_hsv_color/classcs19_1_1HsvColor.html|this documentation]]. You may add other functions if you'd like, as long as they don't interfere with the expected functionality. Once the basic parts of your class are complete, you can try running [[http://jeff.cis.cabrillo.edu/datasets/docs_cs19_hsv_color/hsv_color_demo.cpp|this demo code]] that exercises class ''cs19::HsvColor'' and produces an HTML document on standard output. If your class has enough functionality to support this demo, it should produce a web page identical to [[https://jeff.cis.cabrillo.edu/datasets/docs_cs19_hsv_color/hsv_color_demo.html|this one]]. You can try the following and compare your results with those expected: g++ hsv_color_demo.cpp cs19_hsv_color.cpp -o hsv_color_demo ./hsv_color_demo >~/public_html/hsv_color_demo.html Now visit the following URLs and compare them visually to check for any discrepancies: * ''jeff.cis.cabrillo.edu/datasets/docs_cs19_hsv_color/hsv_color_demo.html'' * ''jeff.cis.cabrillo.edu/~@USER@/hsv_color_demo.html'' ===== Tips ===== * No need to really know anything about hexadecimal numbers if you're totally unfamiliar. '''' makes it very easy to [[https://en.cppreference.com/w/cpp/io/manip/hex|print and parse]] integers formatted in hexadecimal into output streams and from input streams. * Feel free to find **and cite** [[https://duckduckgo.com/?q=rgb+to+hsv+c%2B%2B&t=h_&ia=web|pre-existing code]] that can convert from HSV to RGB, unless you want to write it from scratch. * There are [[https://duckduckgo.com/?q=rgb+to+hsv&t=h_&ia=answer|plenty of online tools]] for checking whether your conversions between HSV and RGB are correct. ----- ====== Submission ====== Submit ''cs19_hsv_color.h'' and ''cs19_hsv_color.cpp'' via [[info:turnin]]. {{https://jeff.cis.cabrillo.edu/images/feedback-robot.png?nolink }} //**Feedback Robot**// This project has a feedback robot that will run some tests on your submission and provide you with a feedback report via email within roughly one minute. Please read the feedback carefully. ====== Due Date and Point Value ====== Due at 23:59:59 on the date listed on the [[:syllabus|syllabus]]. ''Assignment 07'' is worth 60 points. Possible point values per category: --------------------------------------- Class functionality 60 (split as evenly as possible between member functions) Possible deductions: Style and practices 10–20% Possible extra credit: Submission via Git 5% ---------------------------------------