The realization of the Edge sign algorithm C + + program in computer graphics 2

Source: Internet
Author: User

Summary: Tell me about the error encountered by this program 1. Is the last point, when he has only one point, he is the back of the full fill, this is because the flag filling algorithm must have two boundaries to be able to solve this problem is to stagger a point 2. is when there are three points, The middle part of the 2nd and 3 points will not be filled, the above solution is to stagger a point, that is, the second point into two points 3, using the midpoint to draw a circle method, in this algorithm, because the point he chose may not be the next point, but with the current point parallel to the one, this time he will fill the two points , so there will be padding blanks above the center of the result graph, especially when the radian is relatively horizontal.

#include <iostream>
#include <conio.h>
#include <stdio.h>
#include <graphics.h>
using namespace Std;
int a[1000][1000];
int side[1000];

Midpoint Draw Circle
void midpointcircle (int x0,int y0,int r,int color)

{
int x=0,y=r;
float D=5.0/4-r;
while (x<=y) {
Putpixel (X0+x,y0-y,color);
A[x0+x][y0-y]=1;
Putpixel (X0-x,y0-y,color);
A[x0-x][y0-y]=1;
Putpixel (X0+y,y0-x,color);
A[x0+y][y0-x]=1;
Putpixel (X0-y,y0-x,color);
A[x0-y][y0-x]=1;
if (d<0)
d+=x*2.0+3;
else{
d+=2.0* (x-y) +5;y--;
}
x + +;
}
}

void Edge_mark_fill (int color) {

int Driver=vga,mode=vgahi;
Initgraph (&driver,&mode, "");
SetBkColor (0);
int x;
int y;

Midpointcircle (100,100,100,255);
Midpointcircle (301,100,100,255);//Circle stagger a bit

Draw graphics
For (x=0,y=100;x<=200 && y<=300;x++,y++)
{
Putpixel (X,y,color);
A[x][y]=1;
}
200 Stagger a bit
For (x=201,y=300;x<=400 && y>=100;x++,y--)
{
Putpixel (X,y,color);
A[x][y]=1;
}

BOOL Inside=false;
for (y=0;y<=300;y++)
{
Inside=false;

for (x=0;x<=400;x++)
{
if (side[y]==1)
Break
Else
{
if (a[x][y]==1)
inside=! (inside);
if (Inside!=false)
Putpixel (x,y,255)
;
Else
Putpixel (x,y,0)
;
}
}
}
Getch ();
}

int main ()
{

/*
Tell me about the errors encountered by this program
1. Is the last point, when he has only one point, he is the full padding behind,
2. That is, when there are three points, the middle part of 2 and 3 points will not be filled, the solution is to stagger a little
3, when using the midpoint to draw the circle method, because his choice of points may not be the next point, so there will be padding, especially when the radian level
*/
Edge_mark_fill (255);
return 0;
}

The realization of the Edge sign algorithm C + + program in computer graphics 2

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.