示例#1
0
void floodfill(int x, int y, int border)
{
    select_fill_color();
    if (bgiemu_handle_redraw || visual_page != active_page) { 
	FloodFill(hdc[1], x, y, PALETTEINDEX(border+BG));
    }
    if (visual_page == active_page) { 
	FloodFill(hdc[0], x, y, PALETTEINDEX(border+BG));
    } 
}
示例#2
0
LevelRoom GameLevel::FloodFill(int floodFillMap[], int col, int row, int clusterIndex)
{
    LevelRoom floodRm, adjTile;
    if (floodFillMap[col + row * LEVEL_WIDTH] != 0) return floodRm;

    floodRm.Left = col;
    floodRm.Right = col + 1;
    floodRm.Top = row;
    floodRm.Bottom = row + 1;
    floodFillMap[col + row * LEVEL_WIDTH] = clusterIndex;

    adjTile = FloodFill(floodFillMap, col, row - 1, clusterIndex);
    if (adjTile.Left == 1)
    {
        if (adjTile.Left < floodRm.Left) floodRm.Left = adjTile.Left;
        if (adjTile.Right > floodRm.Right) floodRm.Right = adjTile.Right;
        if (adjTile.Top < floodRm.Top) floodRm.Top = adjTile.Top;
        if (adjTile.Bottom > floodRm.Bottom) floodRm.Bottom = adjTile.Bottom;
    }

    adjTile = FloodFill(floodFillMap, col + 1, row, clusterIndex);
    if (adjTile.Left == 1)
    {
        if (adjTile.Left < floodRm.Left) floodRm.Left = adjTile.Left;
        if (adjTile.Right > floodRm.Right) floodRm.Right = adjTile.Right;
        if (adjTile.Top < floodRm.Top) floodRm.Top = adjTile.Top;
        if (adjTile.Bottom > floodRm.Bottom) floodRm.Bottom = adjTile.Bottom;
    }

    adjTile = FloodFill(floodFillMap, col, row + 1, clusterIndex);
    if (adjTile.Left == 1)
    {
        if (adjTile.Left < floodRm.Left) floodRm.Left = adjTile.Left;
        if (adjTile.Right > floodRm.Right) floodRm.Right = adjTile.Right;
        if (adjTile.Top < floodRm.Top) floodRm.Top = adjTile.Top;
        if (adjTile.Bottom > floodRm.Bottom) floodRm.Bottom = adjTile.Bottom;
    }

    adjTile = FloodFill(floodFillMap, col - 1, row, clusterIndex);
    if (adjTile.Left == 1)
    {
        if (adjTile.Left < floodRm.Left) floodRm.Left = adjTile.Left;
        if (adjTile.Right > floodRm.Right) floodRm.Right = adjTile.Right;
        if (adjTile.Top < floodRm.Top) floodRm.Top = adjTile.Top;
        if (adjTile.Bottom > floodRm.Bottom) floodRm.Bottom = adjTile.Bottom;
    }

    return floodRm;
}
示例#3
0
int main()
{
    int m, n;

    while (scanf("%d %d", &m, &n) == 2 && (m > 0 || n > 0)) {
        int i, count = 0;

        for (i = 0; i < m; ++i) {
            getchar();

            int j;

            for (j = 0; j < n; ++j) scanf("%c", &matrix[i][j]);
        }

        for (i = 0; i < m; ++i) {
            int j;

            for (j = 0; j < n; ++j) {
                if (matrix[i][j] == '@') {
                    FloodFill(i, j, m, n, '*');
                    ++count;
                }
            }
        }

        printf("%d\n", count);
        memset(is_visited, 0, sizeof is_visited);
    }

    return 0;
}
示例#4
0
void MyWidget::paintEvent(QPaintEvent * e) {
    if (!_flood) {
        if (_b) {
            Elipse(x1, y1, x2, y2);
        } else {
            Line(x1, y1, x2, y2);
        }
    } else {
        FloodFill(x1, y1);
        _flood = false;
    }
    QPainter paint(this);
    paint.drawImage(QPoint(0, 0), *_image);
}
示例#5
0
/**
 *\fn           HDC AddNullDC(int id, int cx, int cy)
 *\brief        Ìí¼Ó¿ÕµÄͼÏñDC
 *\param[in]    int id ͼÏñDCÐòºÅ
 *\param[in]    int cx ͼÏñ¿í
 *\param[in]    int cy ͼÏñ¸ß
 *\return       ͼÏñDC¾ä±ú
 */
HDC CXTDC::AddNullDC(int id, int cx, int cy)
{
    DeleteDC(IMAGEDC, id);

    XTDC xtDC;
    xtDC.dc = CreateCompatibleDC(NULL);
    xtDC.image = CreateCompatibleBitmap(dc_, cx, cy);
    xtDC.oldImage = SelectObject(xtDC.dc, xtDC.image);

    imageDcMap_[id] = xtDC;

    FloodFill(xtDC.dc, 0, 0, RGB(0, 0, 0));

    return xtDC.dc;
}
示例#6
0
/*****************************************************************************
* Function: FindNextPathSegment
*
* Description:	Compute the fastest route throught the maze. Simulate maze
*				solutions and ouput the next heading and the number of cells
*				to travel forward to get to that turn.
*****************************************************************************/
void SimpleFloodFill::FindNextPathSegment
	(
		uint32_t		robot_current_row,      // the current row of the robot
		uint32_t		robot_current_col,      // the current col of the robot
		heading_t		robot_current_heading,  // the current heading of the robot
		heading_t*		next_heading,           // out param of the next heading to travel
		uint32_t*		cells_to_travel         // out param of the number of cells to travel in the given direction
	)
{
    Cell* current_cell          = m->get_cell(robot_current_row, robot_current_col);
    uint32_t depth		        = FloodFill();
    uint32_t current_cell_depth = *((int32_t*)current_cell->get_data());
    *cells_to_travel            = 0;

    if (depth == MAX_FLOOD_DEPTH) return;
    
    
    
    Cell* adjacent_cell = current_cell->get_adjacent_cell(robot_current_heading);
    
    //Decide how many cells to travel forward (0->N cells) 
    while(adjacent_cell != _NULL &&                                             //Make sure no wall is in front of us
          *((int32_t*)adjacent_cell->get_data()) == current_cell_depth - 1 &&   //Check to see if the cell in front of us is the next best decision
          ( adjacent_cell->get_visited() || *cells_to_travel == 0 ) )           //If we are traveling more than one cell verify that we have visited it before
    {
        *cells_to_travel += 1;
        current_cell_depth--;
        current_cell = adjacent_cell;
        adjacent_cell = adjacent_cell->get_adjacent_cell(robot_current_heading);
    }
    
    //decide which direction to turn after moving forward
    for (heading_t h = north; h < num_cardinal_directions; h++)
    {
        if(h == robot_current_heading  || (h == GetReverseHeading(robot_current_heading) && cells_to_travel > 0)) continue;
        
        Cell* adjacent_cell = current_cell->get_adjacent_cell(h);

        if (adjacent_cell != _NULL && *((int32_t*)adjacent_cell->get_data()) == current_cell_depth - 1)
        {
            *next_heading = h;
            return;
        }   
        

    }

} // FindNextPathSegment()
示例#7
0
void FloodFill(int row, int col, int max_row, int max_col, char c)
{
    if (row < 0 || row >= max_row || col < 0 || col >= max_col) return;

    matrix[row][col] = c;
    is_visited[row][col] = true;

    int i, new_row, new_col;

    for (i = 0; i < 8; ++i) {
        new_row = row + dx[i];
        new_col = col + dy[i];

        if (!is_visited[new_row][new_col] && matrix[new_row][new_col] == '@')
            FloodFill(new_row, new_col, max_row, max_col, c);
    }
}
示例#8
0
// This function fills an enclosed area bordered by a given color.  If the
// reference poitn (x,y) is within the closed area, the area is filled.  If
// it is outside the closed area, the outside area will be filled.  The
// current fill pattern and style is used.
//
void floodfill( int x, int y, int border )
{
    HDC hDC;
    WindowData* pWndData = BGI__GetWindowDataPtr( );
    int color;

    // Set the text color for the fill pattern
    // Convert from BGI color to RGB color
    color = converttorgb( pWndData->fillInfo.color );
    border = converttorgb( border );
    hDC = BGI__GetWinbgiDC( );
    SetTextColor( hDC, color );
    FloodFill( hDC, x, y, border );
    // Reset the text color to the drawing color
    color = converttorgb( pWndData->drawColor );
    SetTextColor( hDC, color );
    BGI__ReleaseWinbgiDC( );

    RefreshWindow( NULL );
}
示例#9
0
NAMESPACE_UPP

void IconDes::LeftDown(Point p, dword flags)
{
	SetFocus();
	if(!IsCurrent())
		return;
	SaveUndo();
	startpoint = GetPos(p);
	if(IsPasting()) {
		if(Rect(Current().pastepos, Current().paste_image.GetSize()).Contains(startpoint)) {
			startpoint -= Current().pastepos;
			SetCapture();
		}
		else
			FinishPaste();
		return;
	}
	SetCapture();
	Current().base_image = CurrentImage();
	if(flags & K_SHIFT) {
		ImageBuffer ib(CurrentImage());
		if(!doselection) {
			RGBA c = CurrentColor();
			c.r += 127;
			MaskFill(ib, c, 0);
		}
		FloodFill(ib, CurrentColor(), startpoint, ib.GetSize());
		SetCurrentImage(ib);
		if(!doselection)
			MaskSelection();
		return;
	}
	if(selectrect)
		EmptyRectTool(startpoint, flags);
	else
	if(tool)
		(this->*tool)(startpoint, flags);
}
    inline void cut(Eigen::PlainObjectBase<DerivedO> &Handle_Seams)
    {
      F_visited.setConstant(F.rows(),0);
      Handle_Seams.setConstant(F.rows(),3,1);

      int index=0;
      for (unsigned f = 0; f<F.rows(); f++)
      {
        if (!F_visited(f))
        {
          index++;
          FloodFill(f, Handle_Seams);
        }
      }

      Retract(Handle_Seams);

      for (unsigned int f=0;f<F.rows();f++)
        for (int j=0;j<3;j++)
          if (IsRotSeam(f,j))
            Handle_Seams(f,j)=true;

    }
示例#11
0
LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	UINT code;      // код уведомления
	UINT idCtrl;     // идентификатор дочернего окна
	HWND hChild;
	HDC hdc;
	HBRUSH hBrush;
	switch (msg)
	{

	case WM_PAINT:
		HDC hdc;
		PAINTSTRUCT ps;
		RECT rc;

		// Перерисовываем внутреннюю область окна
		hdc = BeginPaint(hWnd, &ps);
		GetClientRect(hWnd, &rc);
		EndPaint(hWnd, &ps);
		break;
	case WM_COPYDATA:
		szBuf =(int*) ((PCOPYDATASTRUCT)lParam)->lpData;
		i = szBuf[0];
		j = szBuf[1];
		k = szBuf[2];
		break;
	case WM_RBUTTONDOWN:
	case WM_LBUTTONDOWN:
	{
		if (k == 1)
		{
			hdc = GetDC(hWnd);
			hBrush = CreateSolidBrush(RGB(255, 0, 0));
			switch (i)
			{
			case 1:
				hBrush = CreateSolidBrush(RGB(255, 0, 0));
				break;
			case 2:
				hBrush = CreateSolidBrush(RGB(0, 0, 255));
				break;
			case 3:
				hBrush = CreateSolidBrush(RGB(0, 255, 0));
				break;
			}
			SelectObject(hdc, hBrush);

			switch (j)
			{
			case 1:
				POINT poly[5];

				poly[0].x = LOWORD(lParam);
				poly[0].y = HIWORD(lParam)-50;

				poly[1].x = LOWORD(lParam) - 40;
				poly[1].y = HIWORD(lParam) ;

				poly[2].x = LOWORD(lParam);
				poly[2].y = HIWORD(lParam) + 50;

				poly[3].x = LOWORD(lParam) + 40;
				poly[3].y = HIWORD(lParam) ;

				poly[4].x = LOWORD(lParam);
				poly[4].y = HIWORD(lParam)-50;

				Polyline(hdc, poly, 5);
				FloodFill(hdc, LOWORD(lParam), HIWORD(lParam), 0);
				break;
			case 2:
				Rectangle(hdc, LOWORD(lParam)-50, HIWORD(lParam)-50, LOWORD(lParam) + 50, HIWORD(lParam) + 50);
				break;
			case 3:
				Ellipse(hdc, LOWORD(lParam)-50, HIWORD(lParam)-50, LOWORD(lParam) + 50, HIWORD(lParam) + 50);
				break;
			case 4:
				POINT poly1[11];

				poly1[0].x = LOWORD(lParam);
				poly1[0].y = HIWORD(lParam)-90;

				poly1[1].x = LOWORD(lParam) - 30;
				poly1[1].y = HIWORD(lParam) - 30;

				poly1[2].x = LOWORD(lParam) - 90;
				poly1[2].y = HIWORD(lParam) - 20;

				poly1[3].x = LOWORD(lParam) - 50;
				poly1[3].y = HIWORD(lParam) + 30;

				poly1[4].x = LOWORD(lParam) - 60;
				poly1[4].y = HIWORD(lParam) + 90;




				poly1[5].x = LOWORD(lParam);
				poly1[5].y = HIWORD(lParam) + 70;

				poly1[6].x = LOWORD(lParam) + 60;
				poly1[6].y = HIWORD(lParam) + 90;

				poly1[7].x = LOWORD(lParam) + 50;
				poly1[7].y = HIWORD(lParam) + 30;

				poly1[8].x = LOWORD(lParam) + 90;
				poly1[8].y = HIWORD(lParam) - 20;

				poly1[9].x = LOWORD(lParam) + 30;
				poly1[9].y = HIWORD(lParam) - 30;

				poly1[10].x = LOWORD(lParam);
				poly1[10].y = HIWORD(lParam)-90;

				Polyline(hdc, poly1, 11);
				FloodFill(hdc, LOWORD(lParam), HIWORD(lParam), 0);
				break;
			}


			ReleaseDC(hWnd, hdc);
		}
	}break;
	case WM_DESTROY:
	{
		PostQuitMessage(0);
	} break;
	default: return DefWindowProc(hWnd, msg, wParam, lParam);
	}
	return 0;
}
示例#12
0
void GameLevel::AttachClusters(LevelRoom rooms[], int numRooms)
{
    std::cout << "attaching clusters..." << std::endl;
    int clusters;
    do
    {
        std::cout << "\tattachment pass" << std::endl;
        clusters = 0;
        int floodFillMap[LEVEL_WIDTH * LEVEL_HEIGHT];
        for (int c = 0; c < LEVEL_WIDTH; c++)
            for (int r = 0; r < LEVEL_HEIGHT; r++)
            {
                switch (tileMap[c][r].TileType)
                {
                    case ' ':
                        floodFillMap[c + r * LEVEL_WIDTH] = -2;
                        break;
                    case '#':
                        floodFillMap[c + r * LEVEL_WIDTH] = -1;
                        break;
                    case '+':
                    case '.':
                    case 'H':
                        floodFillMap[c + r * LEVEL_WIDTH] = 0;
                        break;
                }
            }

        std::vector<LevelRoom> floodClusters;
        for (int c = 0; c < LEVEL_WIDTH; c++)
            for (int r = 0; r < LEVEL_HEIGHT; r++)
            {
                if (floodFillMap[c + r * LEVEL_WIDTH] != 0) continue;
                else floodClusters.push_back(FloodFill(floodFillMap, c, r, ++clusters));
            }
        std::cout << "\tNumber of room clusters: " << clusters << std::endl;
        if (clusters > 1)
        {
            int numClusters = (int)floodClusters.size();
            bool attached[numClusters * numClusters];

            for (int i = 0; i < numClusters; i++)
                for (int j = 0; j < numClusters; j++)
                    attached[i + j * numClusters] = false;

            for (int i = 0; i < numRooms; i++)
                rooms[i].Cluster = floodFillMap[rooms[i].Left + rooms[i].Top * LEVEL_WIDTH];

            for (int i = 0; i < numClusters; i++)
            {
                int ia, ja;
                int j = FindClosestClusterRoom(rooms, numRooms, i + 1, ia, ja);
                std::cout << "\tClosest cluster to " << i + 1 << ": " << j << std::endl;
                if (attached[i + j * numClusters]) continue;
                attached[i + j * numClusters] = true;
                attached[j + i * numClusters] = true;
                std::cout << "\tfinding point to attached..." << std::endl;
                int aX, aY, bX, bY;
                if (rooms[ia].Right < rooms[ja].Left)
                    aX = RandomGen::GetInt(rooms[ia].GetMidPtX(), rooms[ia].Right - 1);
                else
                    aX = RandomGen::GetInt(rooms[ia].Left, rooms[ia].GetMidPtX());
                if (rooms[ia].Right < rooms[ja].Left)
                    bX = RandomGen::GetInt(rooms[ja].Left, rooms[ja].GetMidPtX());
                else
                    bX = RandomGen::GetInt(rooms[ja].GetMidPtX(), rooms[ja].Right - 1);
                aY = rooms[ia].Bottom - 1;
                bY = rooms[ja].Bottom - 1;
                std::cout << "\tcreating corridor between (" << aX << "," << aY << ") and (" << bX << ", " << bY << ")";

                while ((aX != bX) || (aY != bY))
                {
                   if (aY != bY)
                   {
                       if (aY < bY) bY--;
                       else bY++;
                       tileMap[bX][bY].TileType = 'H';
                   }
                   else if (aX != bX)
                   {
                       if (aX < bX) bX--;
                       else bX++;
                       if (tileMap[bX][bY].TileType != 'H') tileMap[bX][bY].TileType = '+';
                   }
                   std::cout << ".";
                }
                std::cout << "done." << std::endl;
            }
        }

        bool allBlanks;
        for (int r = 0; r < LEVEL_HEIGHT; r++)
        {
            allBlanks = true;
            for (int c = 0; c < LEVEL_WIDTH; c++)
                if (floodFillMap[c + r * LEVEL_WIDTH] != -2) allBlanks = false;
            if (allBlanks) continue;
            for (int c = 0; c < LEVEL_WIDTH; c++)
            {
                int floodVal = floodFillMap[c + r * LEVEL_WIDTH];
                if (floodVal == -2) std::cout << ' ';
                else if (floodVal == -1) std::cout << '#';
                else std::cout << floodVal % 10;
            }
            std::cout << std::endl;
        }
        std::cout << std::endl;
    } while (clusters > 1);
}