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

Discussion in 'Wii U - Hacking & Backup Loaders' started by brienj, Feb 24, 2016.

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

515 Views
1. ### brienjTrying to avoid getting cancer

Member
Jan 3, 2016
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);
}
}
}

supermalloch and Voxel like this.
2. ### Voxel*Witty Title*

Member
GBAtemp Patron
Voxel is a Patron of GBAtemp and is helping us stay independent!

Our Patreon
Jun 27, 2015
¯\_(ツ)_/¯
Awesome! Why don't you create a merge pull request in the libwiiu repo on github?

brienj likes this.
3. ### brienjTrying to avoid getting cancer

Member
Jan 3, 2016
I'm not even on github. I really need to one of these days though.

4. ### Voxel*Witty Title*

Member
GBAtemp Patron
Voxel is a Patron of GBAtemp and is helping us stay independent!

Our Patreon
Jun 27, 2015
¯\_(ツ)_/¯
i don't even know how to set up a repository still.

Similar Threads - function draw line