MP4
Stacks and Queues
gradientColorPicker Class Reference

gradientColorPicker: a functor that determines the color that should be used given an x and y coordinate using a gradient strategy. More...

#include "gradientColorPicker.h"

+ Inheritance diagram for gradientColorPicker:
+ Collaboration diagram for gradientColorPicker:

Public Member Functions

 gradientColorPicker (RGBAPixel fadeColor1, RGBAPixel fadeColor2, int radius, int centerX, int centerY)
 Constructs a new gradientColorPicker. More...
 
virtual RGBAPixel operator() (int x, int y)
 Picks the color for pixel (x, y). More...
 
- Public Member Functions inherited from colorPicker
virtual ~colorPicker ()
 Destructor: does nothing, but as it is virtual, you may overload it in derived classes if needed. More...
 

Detailed Description

gradientColorPicker: a functor that determines the color that should be used given an x and y coordinate using a gradient strategy.

You can create private helper functions inside this class, as well as local storage, if necessary. Remember to overload a destructor if you need to.

Author
CS 225 Staff
Date
Fall 2010

Constructor & Destructor Documentation

gradientColorPicker::gradientColorPicker ( RGBAPixel  fadeColor1,
RGBAPixel  fadeColor2,
int  radius,
int  centerX,
int  centerY 
)

Constructs a new gradientColorPicker.

Parameters
fadeColor1The first color to start the gradient at.
fadeColor2The second color to end the gradient with.
radiusHow quickly to transition to fadeColor2.
centerXX coordinate for the center of the gradient.
centerYY coordinate for the center of the gradient.
Todo:
Construct your gradientColorPicker here! You may find it helpful to create additional member variables to store things.

Member Function Documentation

RGBAPixel gradientColorPicker::operator() ( int  x,
int  y 
)
virtual

Picks the color for pixel (x, y).

The first color fades into the second color as you move from the initial fill point, the center, to the radius. Beyond the radius, all pixels should be just color2.

You should calculate the distance between two points using the standard Manhattan distance formula,

\(d = |center\_x - given\_x| + |center\_y - given\_y|\)

Then, scale each of the three channels (R, G, and B) from fadeColor1 to fadeColor2 linearly from d = 0 to d = radius.

For example, the red color at distance d where d is less than the radius must be

\( redFill = fadeColor1.red - \left\lfloor \frac{d*fadeColor1.red}{radius}\right\rfloor + \left\lfloor\frac{d*fadeColor2.red}{radius}\right\rfloor\)

Note that all values are integers. If you do not follow this formula, your colors may be very close but round differently than ours.

Parameters
xThe x coordinate to pick a color for.
yThe y coordinate to pick a color for.
Returns
The color selected for (x, y).
Todo:
Return the correct color here!

Implements colorPicker.


The documentation for this class was generated from the following files: