• Порядковый алгоритм заполнения с затравкой для многоугольных областей?

    Vitalianskiy
    @Vitalianskiy Автор вопроса
    Student
    #include<iostream>
    #include<windows.h>
    
    using namespace std;
    
    struct dot
    {
    	int x, y;
    };
    
    struct color
    {
    	int r, g, b;
    };
    
    void drawLine(int x1, int y1, int x2, int y2, HDC& hdc)
    {
    	MoveToEx(hdc, x1, y1, NULL);
    	LineTo(hdc, x2 + 1, y2);
    }
    
    void drawPolygon(dot* dots, int n, HDC& hdc)
    {
    	int i;
    	for (i = 0; i < n - 1; i++)
    	{
    		drawLine(dots[i].x, dots[i].y, dots[i + 1].x, dots[i + 1].y, hdc);
    	}
    	drawLine(dots[i].x, dots[i].y, dots[0].x, dots[0].y, hdc);
    }
    
    bool equalColor(int x1, int y1, HDC& hdc, color test)
    {
    
    	COLORREF col = GetPixel(hdc, x1, y1);
    	if ((int)GetRValue(col) != test.r)
    	{
    		return false;
    	}
    	if ((int)GetGValue(col) != test.g)
    	{
    		return false;
    	}
    	if ((int)GetBValue(col) != test.b)
    	{
    		return false;
    	}
    	return true;
    }
    
    void lineFill(int x, int y, HDC& hdc, color bound, color newColor)
    {
    	int x0 = x, xl, xr;
    	while (!equalColor(x0, y, hdc, bound))
    	{
    		x0--;
    	}
    	xl = ++x0;
    	x0 = x;
    	while (!equalColor(x0, y, hdc, bound))
    	{
    		x0++;
    	}
    	xr = --x0;
    
    	drawLine(xl, y, xr, y, hdc);
    	Sleep(50);
    
    	x0 = xl;
    	while (x0 < xr)
    	{
    		if (equalColor(x0, y + 1, hdc, bound) == false && equalColor(x0, y + 1, hdc, newColor) == false)
    		{
    			lineFill(x0, y + 1, hdc, bound, newColor);
    		}
    		x0++;
    	}
    	x0 = xl;
    	while (x0 < xr)
    	{
    		if (equalColor(x0, y - 1, hdc, bound) == false && equalColor(x0, y - 1, hdc, newColor) == false)
    		{
    			lineFill(x0, y - 1, hdc, bound, newColor);
    		}
    		x0++;
    	}
    	
    }
    
    
    
    int main()
    {
    	HWND hwnd = GetConsoleWindow();
    	HDC hdc = GetDC(hwnd);
    	HBRUSH brush;
    	HPEN pen;
    	dot* dots;
    	color cred = { 255, 0, 0 }, cgreen = { 0, 255, 0 }, cblue = { 0, 0, 255 };
    	pen = CreatePen(PS_SOLID, 1, RGB(cgreen.r, cgreen.g, cgreen.b));
    	brush = CreateSolidBrush(RGB(cgreen.r, cgreen.g, cgreen.b));
    	dots = new dot[5];
    
    	dots[0] = { 150, 270 };
    	dots[1] = { 350, 330 };
    	dots[2] = { 460, 180 };
    	dots[3] = { 170, 60 };
    	dots[4] = { 130, 190 };
    
    
    	SelectObject(hdc, brush);
    	Ellipse(hdc, 190, 200, 250, 270);
    	SelectObject(hdc, pen);
    	drawPolygon(dots, 5, hdc);
    
    	pen = CreatePen(PS_SOLID, 1, RGB(cred.r, cred.g, cred.b));
    	SelectObject(hdc, pen);
    	lineFill(270, 210, hdc, cgreen, cred);
    
    	ReleaseDC(hwnd, hdc);
    	cin.ignore();
    
    }
    Ответ написан
    Комментировать
  • Задача на С про точки на координатной площади?

    Vitalianskiy
    @Vitalianskiy Автор вопроса
    Student
    #include <stdio.h>
    #include <stdlib.h>
    
    /* run this program using the console pauser or add your own getch, system("pause") or input loop */
    
    int main(int argc, char *argv[]) {
    	float a,b,c,d,e,f,g,h,f1,f2;
    	printf("a,b,c,d,e,f,g,h,\n");
    	scanf("%f%f%f%f%f%f%f%f", &a,&b, &c, &d, &e, &f, &g, &h);
    f1=(a-e)*(h-f)-(b-f)*(g-e);
          scanf ("(a-e)*(h-f)-(b-f)*(g-e)=%f", f1 );
    	f2=(c-e)*(h-f)-(d-f)*(g-e);
        	 scanf("(c-e)*(h-f)-(d-f)*(g-e)=%f", f2 );
    
    	
    	if ((f1>0) && (f2>0)) 
    	{printf("Yes");}
    	  else if ((f1<0) && (f2<0))
    	 {printf("Yes");}
    	    else   
    	    {printf("NO");}
    	   
    
    	return 0;
    }
    Ответ написан
    Комментировать