J'ai un projet d'école où je dois avoir une fonction qui peut dessiner une ligne de n'importe où sur l'écran à n'importe quel endroit sur l'écran. Je sais qu'il y a certaines fonctions incluses qui le font pour moi.Comment dessiner des lignes dans C#
ce que j'ai jusqu'à présent: (la chose vga.setpixel définit le (uint) pixel x, au (uint) y pixal, la couleur (uint) couleur)
class drawaline
{
public static void swap(ref int a, ref int b)
{
int temp = a; // Copy the first position's element
a = b; // Assign to the second element
b = temp; // Assign to the first element
}
public static int abs(int value)
{
if (value < 0)
value = value * -1;
return value;
}
public static int fpart(int x)
{
return x;
}
public static int rfpart(int x)
{
x = 1 - fpart(x);
return x;
}
public static int ipart(int x)
{
return x;
}
public static void line(int x1, int y1, int x2, int y2, uint color)
{
int dx = x2 - x1;
int dy = y2 - y1;
if (abs(dx) < (dy))
{
swap(ref x1, ref y1);
swap(ref x2, ref y2);
swap(ref dx, ref dy);
}
if (x2 < x1)
{
swap(ref x1, ref x2);
swap(ref y1, ref y2);
}
int gradient = dy/dx;
// handle first endpoint
int xend = x1;
int yend = y1 + gradient * (xend - x1);
int x1p = x1 + (int).5;
int xgap = rfpart(x1p);
int xpxl1 = xend; // this will be used in the main loop
int ypxl1 = ipart(yend);
VGAScreen.SetPixel320x200x8((uint)xpxl1, (uint)ypxl1, (uint)color);
int intery = yend + gradient; // first y-intersection for the main loop
// handle second endpoint
xend = x2;
yend = y2 + gradient * (xend - x2);
xgap = fpart(x2 + (int)0.5);
int xpxl2 = xend; // this will be used in the main loop
int ypxl2 = ipart(yend);
VGAScreen.SetPixel320x200x8((uint)xpxl2, (uint)ypxl2, (uint)color);
VGAScreen.SetPixel320x200x8((uint)xpxl2, (uint)ypxl2 + 1, (uint)color);
// main loop
for (x = 0; x < xpxl1 + 1; x++)
{
VGAScreen.SetPixel320x200x8((uint)x, (uint)intery, (uint)color);
VGAScreen.SetPixel320x200x8((uint)x, (uint)intery, (uint)color);
intery = intery + gradient;
}
}
}
votre fonction de permutation ne fonctionnera pas. vous devez déclarer a et b comme dehors. – BlackBear
comment je fais ça? (im a noob) – dude
juste mettre "out" avant eux;) public static void swap (int int, out int b) – BlackBear