-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgradientColorPicker.h
More file actions
82 lines (76 loc) · 2.53 KB
/
Copy pathgradientColorPicker.h
File metadata and controls
82 lines (76 loc) · 2.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/**
* @file gradientColorPicker.h
* Definition of a gradient color picker.
*
* @author CS 225 Staff
* @date Fall 2010
*/
#ifndef GRADIENTCOLORPICKER_H
#define GRADIENTCOLORPICKER_H
#include "colorPicker.h"
#include <math.h>
#include <iostream>
/**
* 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
*/
class gradientColorPicker : public colorPicker {
public:
/**
* Constructs a new gradientColorPicker.
*
* @param fadeColor1 The first color to start the gradient at.
* @param fadeColor2 The second color to end the gradient with.
* @param radius How quickly to transition to fadeColor2.
* @param centerX X coordinate for the center of the gradient.
* @param centerY Y coordinate for the center of the gradient.
*/
gradientColorPicker( RGBAPixel fadeColor1, RGBAPixel fadeColor2, int radius, int centerX, int centerY );
/**
* 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,
*
* \f$d = |center\_x - given\_x| + |center\_y - given\_y|\f$
*
* 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
*
* \f$ redFill = fadeColor1.red - \left\lfloor
\frac{d*fadeColor1.red}{radius}\right\rfloor +
\left\lfloor\frac{d*fadeColor2.red}{radius}\right\rfloor\f$
*
* Note that all values are integers. If you do not follow this
* formula, your colors may be very close but round differently
* than ours.
*
* @param x The x coordinate to pick a color for.
* @param y The y coordinate to pick a color for.
* @return The color selected for (x, y).
*/
virtual RGBAPixel operator()( int x, int y );
private:
/**
* @todo Add any necessary private storage here! You may also add
* private helper functions as you see fit.
*/
RGBAPixel color1;
RGBAPixel color2;
int rad;
int center_x;
int center_y;
};
#endif