MP4
Stacks and Queues
|
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"
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... | |
![]() | |
virtual | ~colorPicker () |
Destructor: does nothing, but as it is virtual, you may overload it in derived classes if needed. More... | |
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.
gradientColorPicker::gradientColorPicker | ( | RGBAPixel | fadeColor1, |
RGBAPixel | fadeColor2, | ||
int | radius, | ||
int | centerX, | ||
int | centerY | ||
) |
Constructs a new gradientColorPicker.
fadeColor1 | The first color to start the gradient at. |
fadeColor2 | The second color to end the gradient with. |
radius | How quickly to transition to fadeColor2. |
centerX | X coordinate for the center of the gradient. |
centerY | Y coordinate for the center of the gradient. |
|
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.
x | The x coordinate to pick a color for. |
y | The y coordinate to pick a color for. |
Implements colorPicker.