I'm learning how to draw basic shapes using points in my graphics course, and I can't figure out how to draw a triangle. I thought it would be similar to drawing a rectangle, but a lot of variables (such as slope and different kinds of triangles) need to be taken into account.
Below is my working function of drawing a rectangle
drawRectangle(point 1, point 2){
xStart = min(point 1.x, point 2.x)
yStar = min(point 1.y, point 2.y)
xEnd = max(point 1.x, point 2.x)
yEnd = max(point 1.y, point 2.y)
for(int i = yStart, i<= yEnd, i++){
for(int j = xStart, j<= yEnd, j++){
drawPoint(i, j);
}
}
}
drawRectangle is pretty straight forward, since I just have to loop over the starting point to the ending points of the vertices. However, a triangle has three points, what should I do? I thought about maybe dividing a triangle into two halves, so each half would have a flat "base", but I am not sure if that's a viable approach or not.
Edit: Maybe I was unclear, when I say draw a triangle, I meant a color-filled triangle