// The recursion lies here
void Flood(char pattern[82][82], int x,int y)
 {
 	pattern[x][y] = '*';
 	
 		
	  if(pattern[x][y-1] == '.')
 	 	{
 			Flood(pattern,x,y-1);
 	 	}
 	 	
	  if(pattern[x][y+1] == '.')
 	 	{
 	   		Flood(pattern,x,y+1);
	 	}
	 	
	  if(pattern[x-1][y] == '.')
 		{
 			Flood(pattern,x-1,y);
 	 	}
	 
	  if(pattern[x+1][y] == '.')
 	 	{
 			Flood(pattern,x+1,y);
 	 	}  
 }
예제 #2
0
파일: gfxtest.c 프로젝트: michalsc/AROS
VOID test_flood(struct Window *w)
{

    struct TmpRas tmpras;
    BYTE *buffer;
    
D(bug("Window layer: %p\n", w->WLayer));    

    buffer = AllocRaster(w->WLayer->Width, w->WLayer->Height);
D(bug("buffer: %p\n", buffer));    
    if (!buffer)
    	return;
	
    InitTmpRas(&tmpras, buffer, RASSIZE(w->WLayer->Width, w->WLayer->Height));
    w->RPort->TmpRas = &tmpras;
    
    SetOutlinePen(w->RPort, 1);
    SetAPen(w->RPort, 1);
    
    SetDrPt(w->RPort, ~0L);
    
    Move(w->RPort, 50, 50);
    Draw(w->RPort, 100, 100);
    Draw(w->RPort, 50,  100);
    Draw(w->RPort, 50, 50);
    
D(bug("Calling Flood()\n"));    
    Flood(w->RPort, 0, 70, 80);   /* outline mode */

    w->RPort->TmpRas = NULL;
    
}
예제 #3
0
파일: view.cpp 프로젝트: drodin/Crimson
void View::Refresh( void ) {
  Window *win = static_cast<Window *>( windows.Tail() );

  Flood( Color(CF_COLOR_WHITE) );
  while ( win ) {
    if ( !win->Closed() ) {
      win->Blit( this, Rect( 0, 0, win->Width(), win->Height() ),
                 win->LeftEdge(), win->TopEdge() );
    }
    win = static_cast<Window *>( win->Prev() );
  }

  // now update the display
  Update();
}
예제 #4
0
파일: flood.cpp 프로젝트: xiejianhe/CSIE
void Flood(int x, int y, int new_color, int old_color)
{
	if (!(x >= 0 && x < k_Width && y >= 0 && y < k_Height)) {
		return;
	}
	if (g_Image[x][y] != old_color) {
		return;
	}
	g_Image[x][y] = new_color;
	for (int i = 0;i < 4;i++) {
		static int dx[4] = {1, -1, 0, 0};
		static int dy[4] = {0, 0, 1, -1};
		Flood(x + dx[i], y + dy[i], new_color, old_color);
	}
}
int main()
  {
  	short int N;
    scanf("%hd%*c",&N);

	short int a,b,c,row,column;
	int status;
	for(a = 0; a < N; a++)
	 {
	 	scanf("%hd%*c %hd%*c",&row,&column);
	 	for(b = 0; b < row; b++)
	 	  {
	 	  	//gets(bangunan[b]);
	 	   scanf("%[^\n]%*c",bangunan[b]);
		  }
		
		 // Mencari starting point dari rekursinya	 
		 status= 0;
		 for(b = 0; b <= row; b++)
		 {
		 	for(c = 0; c < column; c++)
		 	  {
		 	   if(b == 0 || b == row-1 || c == 0 || c == column-1)
			   {	
		 	  	if(bangunan[b][c] == '.')
		 	  	  {
		 	  	  	bangunan[b][c] = '*';
		 	  	  	Flood(bangunan,b,c);
		 	  	  }
		 	   }
		 	  }
		 }
		 
		 /*
		 // Debugging
	  	 printf("\n");
	 	// Hasil Rekursi
	 	for(b = 0; b < row; b++)
	 	  {
	 	  	printf("%s\n",bangunan[b]);
	 	  }
	 	  */
	 	
	 	  
	 	  
	 	  
	 	  // Mengecek apakah ada daerah tidak terkena banjir
	 	 for(b = 0; b < row; b++)
		 {
		 	for(c = 0; c < column; c++)
		 	  { 
		 	   if(bangunan[b][c] == '.')
		 	     {
		 	     	status = 1;
		 	     	break;
		 	     }
		 	  }
		}
		
		// Mencetak Output
		if(status == 0)
		  {
		  	printf("TIDAK\n");
		  }
		else
		  {
		    printf("YA\n");	
		  }  	  
	 } 
	return 0; 	  
  }
예제 #6
0
void StreamPower::Step()
{

	int i, j, t;
	double max, deltah;
	char fname[100];

	//perform landsliding
	for (j = 0; j < lattice_size_y; j++)
	{
		for (i = 0; i < lattice_size_x; i++)
		{
			topovec[j * lattice_size_x + i] = topo[i][j];
		}
	}
	topovecind = Indexx(topovec);



	// todo
	for (int t = 0; t < lattice_size_x * lattice_size_y; t++)
	{
		i = topovecind[t] % lattice_size_x;
		j = topovecind[t] / lattice_size_x;
		Avalanche(i, j);
	}

	for (j = 0; j < lattice_size_y; j++)
	{
		for (i = 0; i < lattice_size_x; i++)
		{
			topoold[i][j] = topo[i][j];
		}
	}

	Flood();

	for (j = 0; j < lattice_size_y; j++)
	{
		for (i = 0; i < lattice_size_x; i++)
		{
			flow[i][j] = 1;
			topovec[j * lattice_size_x + i] = topo[i][j];
		}
	}

	topovecind = Indexx(topovec);

	for (t = lattice_size_x * lattice_size_y - 1; t >= 0; t--)
	{
		i = topovecind[t] % lattice_size_x;
		j = topovecind[t] / lattice_size_x;
		MFDFlowRoute(i, j);
	}


	// perform uplift
	for (i = 1; i < lattice_size_x - 1; i++)
	{
		for (j = 1; j < lattice_size_y - 1; j++)
		{
			topo[i][j] += U[i][j] * timestep; // u(i,j)
			topoold[i][j] += U[i][j] * timestep;
		}
	}

	//perform upwind erosion
	max = 0;
	for (i = 1; i < lattice_size_x - 1; i++)
	{
		for (j = 1; j < lattice_size_y - 1; j++)
		{
			CalculateAlongChannelSlope(i, j);
			deltah = timestep * K * sqrt(flow[i][j]) * deltax * slope[i][j];

			//std::cout << i << ", " << j << ", time: " << time << ", dh: " << deltah << ", " << "ts: " << timestep << ", K:" << K << ", sqrtflow " << sqrt(flow[i][j]) << ", dx:" << deltax << ", slope: " << slope[i][j] << "\n";
			//exit(0);

			topo[i][j] -= deltah;

			if (topo[i][j] < 0)
			{
				topo[i][j] = 0;
			}
			if (K * sqrt(flow[i][j]) * deltax > max)
			{
				max = K * sqrt(flow[i][j]) * deltax;
			}
		}
	}



	time += timestep;
	if (max > 0.3 * deltax / timestep)
	{
		time -= timestep;
		timestep /= 2.0;
		//std::cout << "First time modification" << "\n";
		for (i = 1; i < lattice_size_x - 1; i++)
		{
			for (j = 1; j < lattice_size_y - 1; j++)
			{
				topo[i][j] = topoold[i][j] - U[i][j] * timestep;
			}
		}
	}
	else
	{
		if (max < 0.03 * deltax / timestep)
		{
			timestep *= 1.2;
			//std::cout << "Second time modification" << "\n";
		}
		for (j = 0; j < lattice_size_y; j++)
		{
			for (i = 0; i < lattice_size_x; i++)
			{
				topoold[i][j] = topo[i][j];
			}

		}

	}
	//if (time > printinterval)
	//{
	sprintf_s(fname, "erosion_%f.asc", time);
	PrintState(fname);
	//printinterval += printstep;
	//}
	std::cout << "Time: " << time << std::endl;
}
예제 #7
0
파일: Graphics.c 프로젝트: aosm/X11apps
static void 
FloodLoop(BitmapWidget BW, Position x, Position y, int value)
{
    Position save_x, save_y, x_left, x_right;
    
    if (QueryFlood(BW, x, y, value)) 
	Flood(BW, x, y, value)


    save_x = x;
    save_y = y;

    x++;
    while (QueryFlood(BW, x, y, value)) {
	Flood(BW, x, y, value);
	x++;
    }
    x_right = --x;

    x = save_x;
    x--;
    while (QueryFlood(BW, x, y, value)) {
	Flood(BW, x, y, value);
	x--;
    }
    x_left = ++x;


    x = x_left;
    y = save_y;
    y++;
    
    while (x <= x_right) {
	Boolean flag = False;
	Position x_enter;
	
	while (QueryFlood(BW, x, y, value) && (x <= x_right)) {
	    flag = True;
	    x++;
	}
	
	if (flag) {
	    if ((x == x_right) && QueryFlood(BW, x, y, value))
		FloodLoop(BW, x, y, value);
	    else
		FloodLoop(BW, x - 1, y, value);
	}
	
	x_enter = x;
	
	while (!QueryFlood(BW, x, y, value) && (x < x_right))
	    x++;
	
	if (x == x_enter) x++;
    }

    x = x_left;
    y = save_y;
    y--;

    while (x <= x_right) {
	Boolean flag = False;
	Position x_enter;
	
	while (QueryFlood(BW, x, y, value) && (x <= x_right)) {
	    flag = True;
	    x++;
	}
	
	if (flag) {
	    if ((x == x_right) && QueryFlood(BW, x, y, value))
		FloodLoop(BW, x, y, value);
	    else
		FloodLoop(BW, x - 1, y, value);
	}
	
	x_enter = x;
	
	while (!QueryFlood(BW, x, y, value) && (x < x_right))
	    x++;
	
	if (x == x_enter) x++;
    }
}