Hacking My function to draw a line (not just horiz or vert) that works In libwiiu

brienj

Trying to avoid getting cancer
OP
Member
Joined
Jan 3, 2016
Messages
1,232
Trophies
0
Website
twitter.com
XP
2,142
Country
United States
The function drawLine in libwiiu only draws a horizontal or vertical line. So what if you want to draw a 30, 45, or 60 degree angle? I was doing some testing, and found the DDA Algorithm, modified to work with libwiiu, to be the best. So here is the code for the DDA Algorithm I modified. You can replace the normal drawLine function with it if you want, it works just as well.

Code:
void draw2DLine(int x1, int y1, int x2, int y2, char r, char g, char b)
{
	int s, dx, dy, m;
	float xi, yi, x, y;
	dx = x2 - x1;
	dy = y2 - y1;
	if (abs(dx) > abs(dy)) {
		s = dx;
	}
	else {
		s = dy;
	}
	xi = dx / (float) s;
	yi = dy / (float) s;
	x = x1;
	y = y1;

	drawPixel(x1, y1, r, g, b);
	if (s > m) {
		m = 0;
		for (m; m < s; m++) {
			x += xi;
			y += yi;
			drawPixel(x, y, r, g, b);
		}
	}
	else {
		m = 0;
		for (m; m > s; m--) {
			x -= xi;
			y -= yi;
			drawPixel(x, y, r, g, b);
		}
	}
}
 
D

Deleted User

Guest
Awesome! Why don't you create a merge pull request in the libwiiu repo on github? ^_^

...unless you already have done?
 
  • Like
Reactions: brienj

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
    K3Nv2 @ K3Nv2: I'll just pretend like I know what's going on