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
|
class Line
{
Surface image;//create a surface, texture, image
int dx;
int dy;
public:
void init(int lenght,int height)
{
dx=abslLenght);
dy=abs(height);
for(int i =0; i<dx*dy;i++)
image.pixel[i].Color== Color(0,0,0,0);//Set each pixel from the image to transparent alpha =0
}
void calculateLine()
{
int x=0;
int y=0;
if (dx >= dy)
//Draw line by travelling along x coordinate
while (x < dx)
{
y = (int)((dy * x) / dx);
image.pixel[y * dx + x].Color = Colo(1,1,1,1);
x++;
}
else if (dx < dy)
//Draw line by travelling along y coordinate
while (y < (dy))
{
x = (int)((dx * y) / dy);
image.pixel[y * dx + x].Color = Colo(1,1,1,1);
y++;
}
}
void drawLine(Surface window)
{
BlitSurface(Image,NULL,window,NULL);
}
~Line()
{
}
};
|