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
  • The Real Jdbye @ The Real Jdbye:
    shows what you know nobody would ever say that about my mom
    +1
  • K3Nv2 @ K3Nv2:
    Except all of reddit 4chan and YouTube reviewers
  • BigOnYa @ BigOnYa:
    yAawn
  • BigOnYa @ BigOnYa:
    eez nuts
  • K3Nv2 @ K3Nv2:
    I tried that new prime X flavor and almost gagged in my mouth lol
  • BigOnYa @ BigOnYa:
    I'm surprised, with your awesome gag reflexs you have B-)
  • K3Nv2 @ K3Nv2:
    Well for being with your wife for so long I have self control
    +1
  • K3Nv2 @ K3Nv2:
    If you wanna commit suicide just drink prime
    +1
  • Sicklyboy @ Sicklyboy:
    obamna
  • The Catboy @ The Catboy:
    SODA
  • Sonic Angel Knight @ Sonic Angel Knight:
    Catboy back in chat. :ninja:
  • Sonic Angel Knight @ Sonic Angel Knight:
    Don't forget to pet it for good luck
  • K3Nv2 @ K3Nv2:
    That cat bites
    +1
  • Psionic Roshambo @ Psionic Roshambo:
    Hmmm yes she does
  • Psionic Roshambo @ Psionic Roshambo:
    Float like a butterfly burns when I pee lol
    +1
  • BigOnYa @ BigOnYa:
    So does that mean your date was not good? It burns now?
    +1
  • K3Nv2 @ K3Nv2:
    Got two new stds in one night
    +1
  • BigOnYa @ BigOnYa:
    Giggity
    +1
  • The Catboy @ The Catboy:
    I don't bite! Minus the times when I did bite
  • The Catboy @ The Catboy:
    Like 5 minutes ago
  • K3Nv2 @ K3Nv2:
    Billie needs her lunch
  • K3Nv2 @ K3Nv2:
    Ffs papa brought back the cheeseburger pizza it's like the only decent pie they had since the 80s
    K3Nv2 @ K3Nv2: Ffs papa brought back the cheeseburger pizza it's like the only decent pie they had since the 80s