Beispiel #1
0
int main()
{
      unsigned d = 0, c = 0, color = 0, lines[473][2];

      srand(*((unsigned*)0x46c));
      setmode(0x13);    /* set to color graphics mode, clearing screen  */
      bresenham_circle(160, 100, 75, 15);
      for (d = 0; d < 64000l; d++)
      {
            if(*((char far*)0xa0000000l + d) == 15)
                  lines[c][1] = d / 320, lines[c++][0] = d % 320;
      }
      while (*((char far*)0x41a) == *((char far*)0x41c))
      {
            bresenham_circle(160, 100,
                  (++color & 127) + 80, (color / 5 ) & 255);
            d = rand() % 465 + 4;
            c = (d + 3) % 472;
            bresenham_line(lines[d][0], lines[d][1],
                  lines[c][0], lines[c][1], color & 255);
      }
      setmode(0x03);    /* set to color text mode, clearing screen      */
      getch();
      return 0;
}
Beispiel #2
0
void getDist(vertx p1, vertx p2)//Finding the start point
{
    int i,j,index=0,a=0,k,l;
    vertx *cvA, *cvB;
    int cntA=0,cntB=0;
    vertx vprev;int prev=0;

    cvA=(vertx *)malloc((vcount/2)*sizeof(vertx));
    cvB=(vertx *)malloc((vcount/2)*sizeof(vertx));

    for(i=0;i<row;i++)
    {
        for(j=0;j<col;j++)
       {
       if(i==p1.i && j==p1.j)
           {
           ep=findPath(cvA,cvB,&cntA,&cntB,i,j,p2);
           }
       }
    }
    if(ep==-1)
		printf("error\n");
    omega+=ep*beta;                 //Radial dist. threshold Omega
    
    printf("Parameters Omega: %f\tEpsilon:%f\n",omega,ep);
    aidp(cvA,0,cntA);
    cvA[cntA-1].yes=1;
    
    aidp(cvB,0,cntB);
    cvB[cntB-1].yes=1;

    for(k=0;k<cntA;k++)
    {
    for(l=0;l<mark;l++)
	if(v[l].i==cvA[k].i && v[l].j==cvA[k].j && cvA[k].yes==1)
		{prev++;v[l].yes=1;
		if(prev>1)
		bresenham_line(vprev.i,vprev.j,cvA[k].i,cvA[k].j,col);
		else
		bresenham_line(p1.i,p1.j,cvA[k].i,cvA[k].j,col);
		vprev=cvA[k];}
    }

bresenham_line(p2.i,p2.j,vprev.i,vprev.j,col);

prev=0;
    for(k=0;k<cntB;k++)
    {
     for(l=0;l<mark;l++)
	if(v[l].i==cvB[k].i && v[l].j==cvB[k].j && cvB[k].yes==1)
		{prev++;v[l].yes=1;
		if(prev>1)
		bresenham_line(vprev.i,vprev.j,cvB[k].i,cvB[k].j,col);
		else
		bresenham_line(p1.i,p1.j,cvB[k].i,cvB[k].j,col);
		vprev=cvB[k];}
    }
bresenham_line(p2.i,p2.j,vprev.i,vprev.j,col);

}
Beispiel #3
0
void curve(int start, int end)
{
vertx st,en,vprev;
vertx *c;
int i,j,k,l,cnt=0,prev=0;
float avg;

st=v[start];
en=v[end];

c=(vertx *)malloc(vcount*sizeof(vertx));

findn(c,&cnt,st.i,st.j,en);

if(cnt)
   {if(cnt!=1)
	   avg=(totvd/(cnt-1));                                //Get the Avg. Vertical Dist.
   else avg=totvd;
if(cnt<10)
	{
	for(i=0;i<cnt;i++)
		{c[i].yes=1;}	
	}

   for(i=0;i<vdcount;i++)                           //Calculate the mean deviation
      vdev+=abs(vd[i]-avg);
   printf("vdev before division=%f and vdcount=%d\n",vdev,vdcount);
   if(cnt!=1) vdev/=(cnt-1);

   ep = avg + alpha*vdev;                           //Vertical dist. threshold Epsilon for A
   omega=(totrd/cnt)+beta*vdev;                             
   printf("cnt=%d\tavg=%f\nvdev=%f\tep=%f\ntotvd=%f\ttotrd=%f\n",cnt,avg,vdev,ep,totvd,totrd);
   }
else
   {ep=0;omega=0;}

aidp(c,0,cnt);
c[cnt-1].yes=1;

    for(k=0;k<cnt;k++)
    {
    for(l=0;l<mark;l++)
	if(v[l].i==c[k].i && v[l].j==c[k].j && c[k].yes==1)
		{prev++;v[l].yes=1;
		if(prev>1)
		bresenham_line(vprev.i,vprev.j,c[k].i,c[k].j,col);
		vprev=c[k];}
    }

free(c);
}
void main(void)
{
      int i=0;

      randomize();
      setmode(0x13);
      while(!kbhit())
      {
            bresenham_line(random(SCREEN_WIDTH), random(SCREEN_HEIGTH),
                  random(SCREEN_WIDTH), random(SCREEN_HEIGTH), i = ++i % 64);
            bresenham_circle(random(SCREEN_WIDTH), random(SCREEN_HEIGTH),
                  random(50), i = ++i % 64);
      }
      getch();
      setmode(0x03);  /* set to color text mode, clearing screen */
}
Beispiel #5
0
bool target_mode(entity *player) {
	if (!LOADED) {
		TARGET_X = player->x;
		TARGET_Y = player->y;
		LOADED = true;
	}

	draw();

	for (int x = player->x - BOUND - 1; x <= player->x + BOUND + 1; ++x) {
		draw_tile(BORDER, 0, x, player->y - BOUND - 1, player->x, player->y);
		draw_tile(BORDER, 0, x, player->y + BOUND + 1, player->x, player->y);
	}
	for (int y = player->y - BOUND - 1; y <= player->y + BOUND + 1; ++y) {
		draw_tile(BORDER, 0, player->x - BOUND - 1, y, player->x, player->y);
		draw_tile(BORDER, 0, player->x + BOUND + 1, y, player->x, player->y);
	}

	bresenham_line(player->x, player->y, TARGET_X, TARGET_Y, __target_cb, player);
	draw_tile(RETICLE, 0, TARGET_X, TARGET_Y, player->x, player->y);

	update_panels();
	doupdate();

	int input = getch();
	switch (input) {
	case 'h':
	case 'l':
	case 'k':
	case 'j':
	case 'y':
	case 'u':
	case 'b':
	case 'n': {
		int tx = 0, ty = 0;
		if (determine_offsets(input, &tx, &ty) && abs(TARGET_X + tx - player->x) <= BOUND && abs(TARGET_Y + ty - player->y) <= BOUND) {
			TARGET_X += tx;
			TARGET_Y += ty;
		}
	} break;
	case 27:
	case '\n':
		LOADED = false;
		break;
	}
	return true;
}
Beispiel #6
0
/* TODO: Color */
static int screen_draw_line(lua_State *L) {
  Screen *screen;
  int x0, y0, x1, y1;
  int args_count = lua_gettop(L);
  assert(args_count == 3);
  screen = check_screen(L, 1);
  lua_getfield(L, 2, "y");
  y0 = lua_tointeger(L, -1) - 1;
  lua_getfield(L, 2, "x");
  x0 = lua_tointeger(L, -1) - 1;
  lua_getfield(L, 3, "y");
  y1 = lua_tointeger(L, -1) - 1;
  lua_getfield(L, 3, "x");
  x1 = lua_tointeger(L, -1) - 1;
  bresenham_line(screen->screen, x0, y0, x1, y1,
      screen->colors.white);
  return 0;
}
int no_obstacle_in_path(int x0,int y0,int x1,int y1, list_type **obs)
{
  
  int *line[2] = {NULL, NULL};
  int n, i, x, y;
  
  n = bresenham_line(x0, y0, x1, y1, line);
  
  for(i = 0; i < n; i++)
  {
    x = line[0][i];
    y = line[1][i];
    if((y >= 0) && (y < rows) && (x >= 0) && (x < columns))
    {
      if(obs[y][x] == closed)
        return 0;
    }
  }
  
  free(line[0]);
  free(line[1]);
  return 1;
  
}
Beispiel #8
0
void poly(int r,int c)
{
int i=r,j=c,k,chng,vc,ni,nj;
int start1=0,dir,pol=0;
mark=0;
FILE *ft=fopen("taken.dat","w");
//cv=(vertx *)malloc(row*col*sizeof(vertx));

v[mark].i=i;
v[mark].j=j;
v[mark].yes=0;
mark++;
fprintf(ft,"%d\t%d\n",i,j);
do
	{
	
	//cv[vcount].i=i;
	//cv[vcount].j=j;
	//cv[vcount].yes=0;

	chng=0;
	*(taken+i*col+j)=1;  //fprintf(ft,"%d\t%d\n",i,j);
	//printf("poly:: ver: row=%d col=%d\t",i,j);
	ni=i; nj=j;

	if(j>0 && *(mat+i*col+j-1)==0 && *(taken+i*col+j-1)==0){nj=j-1; chng++; dir=4;}
   
	if(*(mat+i*col+j+1)==0 && *(taken+i*col+j+1)==0){nj=j+1; chng++; dir=0;}

	if(i>0 && *(mat+(i-1)*col+j+1)==0 && *(taken+(i-1)*col+j+1)==0){ni=i-1; nj=j+1; chng++; dir=1;}

	if(i>0 && j>0 && *(mat+(i-1)*col+j-1)==0 && *(taken+(i-1)*col+j-1)==0){ni=i-1; nj=j-1; chng++; dir=3;}

	if(i>0 && *(mat+(i-1)*col+j)==0 && *(taken+(i-1)*col+j)==0){ni=i-1; chng++; dir=2;}

	if(j>0 && *(mat+(i+1)*col+j-1)==0 && *(taken+(i+1)*col+j-1)==0){ni=i+1; nj=j-1; chng++; dir=5;}

	if(*(mat+(i+1)*col+j)==0 && *(taken+(i+1)*col+j)==0){ni=i+1; chng++; dir=6;}

	if(*(mat+(i+1)*col+j+1)==0 && *(taken+(i+1)*col+j+1)==0){ni=i+1; nj=j+1; chng++; dir=7;}

	printf("chng=%d\n",chng);
	if(chng>1 && vcount>0) break;
	i=ni; j=nj;

	*(direc+vcount)=dir;
	vcount++;
	
	k=checkR1R2(start1,vcount);
	if(k)
		{start1=vcount;
		v[mark].i=i; v[mark].j=j; v[mark].yes=0; mark++;
		fprintf(ft,"%d\t%d\n",i,j);}

	if(!chng) {printf("Breaking..\n");break;}

	}while((i!=r || j!=c) && i<row && j<col);

if((i<=r+1 && i>=r-1) && (j<=c+1 && j>=c-1) && vcount>2) pol=1;

if(chng>1) pol=0;

if(!k && (chng==1 || (!chng && !pol))){v[mark].i=i; v[mark].j=j; v[mark].yes=0; mark++; fprintf(ft,"%d\t%d\n",i,j);}
fclose(ft);
printf("vcount= %d mark=%d\n",vcount,mark);

if(mark==1)
	{v[mark-1].yes=1;pol=2; bresenham_line(i,j,v[mark-1].i,v[mark-1].j,col);}
else if(mark==2)
	{v[mark-2].yes=v[mark-1].yes=1;
	bresenham_line(v[mark-2].i,v[mark-2].j,v[mark-1].i,v[mark-1].j,col);
	pol=2;}

	vc=vcount;
	vcount>>1;

	vd=(int *)malloc(vcount*(sizeof(int)));
	rd=(int *)malloc(vcount*(sizeof(int)));
	vcount=vc;

//	printf("------------------------Vertices------\n");
//	for(vc=0;vc<mark;vc++)
//		printf("Taken = i: %d  j: %d\n",v[vc].i,v[vc].j);

if(pol==1)
        start(0,mark); 
else if(!pol)
	curve(0,mark);

	for(vc=0;vc<mark;vc++)
	{
		if(v[vc].yes==1)
		{//fprintf(ft,"%d\t%d\n",v[vc].i,v[vc].j);
		*(cdata+(v[vc].i)*col+(v[vc].j))=30;
		}
	}  //fclose(ft);

//	free(v);
//	free(cv);
	free(vd);
	free(rd);

}
Beispiel #9
0
/** \brief Calculate the Line-Of-Synchrony of a Cross-Recurrence-Plot, following
	 the algorithm in Marwan et al.

	 Reference:

	 Marwan et al. Cross recurrence plot based synchronization
	 of time series. Nonlinear Processes in Geophysics (2002)
	 vol. 9 (3-4) pp. 325-331.

	 \todo REPAIR THIS ALGORITHM!

	 Algorithm:
	 \code
	 Input: Recurrence Plot R, Parameters dx, dy

	 \endcode

	 \param R the recurrence plot
	 \return a warp-path (2 x M UINT array giving corresponding points of the LOS)
 */
Array* recplot_los_marwan( const Array *R, int dx, int dy ){
	 bool ismat;
	 matrix_CHECK( ismat, R );
	 if( !ismat ) return NULL;

	 Array *los=array_new2( UINT, 2, 2, R->size[0]+R->size[1] );

	 /* find first point on LOS (step [1]) */
	 int ii, ij, i, j;
	 int pidx=0; /* index in LOS */
	 for( ii=0; ii<R->size[0]; ii++ ){
		  if( mat_IDX(R, ii, 0)>0 )
				break;
	 }
	 for( ij=0; ij<R->size[1]; ij++ ){
		  if( mat_IDX(R, 0, ij)>0 )
				break;
	 }		  
	 if( ii<ij ){
		  for( i=0; i<=ii; i++ ){
				array_INDEX2( los, uint, 0, pidx )=0;
				array_INDEX2( los, uint, 1, pidx )=i;
				pidx++;
		  }
	 } else {
		  for( i=0; i<=ij; i++ ){
				array_INDEX2( los, uint, 0, pidx)=i;
				array_INDEX2( los, uint, 1, pidx)=0;
				pidx++;
		  }
	 }

	 int iip, ijp; /* previous points */
	 iip = array_INDEX2( los, uint, 0, pidx-1 );
	 ijp = array_INDEX2( los, uint, 1, pidx-1 );
	 ii=-1; ij=-1;

	 /* next recurrence point (step [2])*/
	 int w;
	 int sx, sy, kx, ky;
	 int cur[2],prev[2]; /* for bresenham */
	 Array *bres;

	 /* set the next recurrence point to (ii,ij) */
	 do {
		  w=2; ii=-1; ij=-1;
		  while( ii<0 || ij<0 ){
				for( i=w-1; i>=0; i-- ){
					 if( mat_IDX( R, iip+w-1, ijp+i )>0 ){
						  ii=iip+w-1;
						  ij=ijp+i;
						  break;
					 }
				}
				w++;
		  }
		  dprintf("(iip,ijp)->(ii,ij)=(%i,%i)->(%i,%i)\n", iip,ijp,ii, ij);

		  /* centre of mass from this recurrence point */
		  local_centre_of_mass( R, ii, ij, dx, dy, &sx, &sy );

		  ky=sy; kx=sx;
		  for( i=0; i<sy; i++ )
				if( mat_IDX( R, ii+i, ij )<=0 ) /* non-rec point */
					 ky=i;
		  for( j=0; j<sx; j++ )
				if( mat_IDX( R, ii, ij+j )<=0 ) /* non-rec point */
					 kx=j;

		  ii+=kx/2;
		  ij+=ky/2;

		  /* (iip,ijp) is the previous LOSpoint, (ii,ij) the current one */
		  /* linear interpolation between (iip,ijp)->(ii,ij) */
		  prev[0]=iip; prev[1]=ijp; cur[0]=ii; cur[1]=ij;
		  bres=bresenham_line( prev, cur );
		  for( i=0; i<bres->size[1]; i++ ){
				array_INDEX2( los, uint, 0, pidx ) =
						  array_INDEX2( bres, uint, 0, i );
				array_INDEX2( los, uint, 1, pidx ) =
						  array_INDEX2( bres, uint, 1, i );
				pidx++;
		  }

		  iip=ii; ijp=ij;
		  array_free( bres );
		  dprintf("pidx=%i, (%i,%i)\n", pidx, ii, ij);
	 }	 while( ii<R->size[0]-1 && ij<R->size[1]-1 );


	 return los;
}
Beispiel #10
0
BOOL draw_line(s32 start_x, s32 start_y, s32 end_x, s32 end_y, rgb_t color)
{
	return bresenham_line(start_x, start_y, end_x, end_y, color);
}