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
|
typedef tuple<int,int,int,int,float,float,float,float,float,float> midPointArg;
class midPointAlgorithm {
protected:
midPointArg mArgs ;
enum { X0, Y0, X1, Y1, R0, G0, B0, R1, G1, B1 } ;
int x0,y0,x1,y1 ;
int changeColor ; // for color interpolation. Would be wither x1-x0 or y1-y0
float r0,g0,b0,r1,g1,b1; // color co-ordinates that needs to be interpolated along the line
float r, g, b ; // actual color that has been used to draw the pixel
float dr, dg, db ; // change in color
float point ; // pixel point size
void draw(int x, int y,float r, float g, float b,int point) ; // draw a pixel
virtual void calculatePoints(void) = 0 ; // calculate x,y co-ordinates to draw the pixel, (draw function is called from this)
private:
void initArguments() ; // initialize x0,y0,x1 ... values
public:
explicit midPointAlgorithm(const midPointArg &args, float p = 2.0) : mArgs(args),point(p) {
initArguments() ;
}
} ;
class slopePositiveOne : public midPointAlgorithm {
protected:
virtual void calculatePoints() ; // calculate x,y co-ordinates when slope m is 0< m <1
public:
explicit slopePositiveOne(const midPointArg &args, float p = 2.0) : midPointAlgorithm(args,p) {
calculatePoints() ;
}
} ;
class slopePositiveInfinity : public midPointAlgorithm {
protected:
virtual void calculatePoints() ;
public:
explicit slopePositiveInfinity(const midPointArg &args, float p = 2.0) : midPointAlgorithm(args,p) {
calculatePoints() ;
}
} ;
class slopeNegativeOne : public midPointAlgorithm {
protected:
virtual void calculatePoints() ;
public:
explicit slopeNegativeOne(const midPointArg &args, float p = 2.0) : midPointAlgorithm(args,p) {
calculatePoints() ;
}
} ;
class slopeNegativeInfinity : public midPointAlgorithm {
protected:
virtual void calculatePoints() ;
public:
explicit slopeNegativeInfinity(midPointArg &args,float p = 2.0) : midPointAlgorithm(args,p) {
calculatePoints() ;
}
} ;
|