Code :
public double decimal(double _a) { //retourne la partie decimal } public double rdecimal(double _a) { //retourne 1 moins la partie decimal } public void drawLine(int _x1, int _y1, int _x2, int _y2, int _couleur) { if(_x2 < _x1) { int buf = _x1; _x1 = _x2; _x2=buf; buf = _y1; _y1 = _y2; _y2 = buf; } double dx = _x2 - _x1; double dy = _y2 - _y1; double gradient = dy/dx; { //horizontal //1er point double xend = (double)round(_x1); double yend = (double)_y1 + gradient * (xend - (double)_x1); double xgap = (1-decimal(_x1 + 0.5)); double xpxl1 = xend ; double ypxl1 = yend; this.__tabJeux[((int)xpxl1+(int)(ypxl1*this.__width))] = defineColor((int)(((rdecimal(yend))* xgap)*255),0,0,0); this.__tabJeux[((int)xpxl1+((int)ypxl1+1)*this.__width)] = defineColor((int)(((decimal(yend)* xgap))*255),0,0,0); double intery = yend + gradient; // dernier point xend = round(_x2); yend = (int)(_y2 + gradient * (xend - _x2)); xgap = decimal(_x2 + 0.5); double xpxl2 = xend ; double ypxl2 = yend; this.__tabJeux[((int)xpxl2+(int)ypxl2*this.__width)] = defineColor((int)((((rdecimal(yend))* xgap))*255),0,0,0); this.__tabJeux[((int)xpxl2+(int)(ypxl2+1)*this.__width)] = defineColor((int)(((decimal(yend)* xgap))*255),0,0,0); // boucle principal for(double x = xpxl1 + 1.0; x<xpxl2 - 1.0;x++) { this.__tabJeux[((int)x+(int)intery*this.__width)] = defineColor((int)(((rdecimal(intery)))*255),0,0,0); this.__tabJeux[((int)x+((int)intery+1)*this.__width)] = defineColor((int)(((decimal(intery)))*255),0,0,0); intery = intery + gradient; } } else //ICI COMMENT FAIRE ? { } }
|