Example #1
0
void NoiseGen::drawPixelTerrain(sf::RenderTarget *target, int x, int y, int shade, int scale)
{
    sf::RectangleShape newshape( sf::Vector2f(scale,scale));

    newshape.setPosition(sf::Vector2f(x*scale, y*scale));


        for(int i = 0; i < int(terrainsegs.size()); i++)
        {
            if( shade < terrainsegs[i].value)
            {
                sf::Color tcolor;
                tcolor.r = terrainsegs[i].red;
                tcolor.g = terrainsegs[i].green;
                tcolor.b = terrainsegs[i].blue;

                newshape.setFillColor(tcolor);
                break;
            }
        }


   target->draw(newshape);


}
Example #2
0
void hold(void) {
  if (g_canswap && g_movbuf.shape != -1) {
    if (g_hold != -1) {
      int shp = g_movbuf.shape;
      g_movbuf.shape = -1;
      newshape(g_hold);
      g_hold = shp;
    } else {
      g_hold = g_movbuf.shape;
      g_movbuf.shape = -1;
      newshape(shiftqueue());
    }
    automovedown();
    g_canswap = 0;
  }
}
Example #3
0
void steadyall(void) {
  int i, j, x, y;
  if (checkmovbuf() != 0) {
    return;
  }

  for (i = 0; i != MOV_BUFSIZE; ++i) {
    for (j = 0; j != MOV_BUFSIZE; ++j) {
      if (g_movbuf.pixbuf[j][i]) {
        x = i + g_movbuf.x;
        y = j + g_movbuf.y;
        bmap[y*g_cols+x].is_occupied = 1;
        bmap[y*g_cols+x].shape = g_movbuf.shape;
        bmap[y*g_cols+x].flags = FLAG_STEADY;
      }
    }
  }

  /* after steady, create a new shape */
  checklines();
  newshape(shiftqueue());

  g_movbuf.shape = -1;

  updateghost();

  g_canswap = 1;

  return;
}
Example #4
0
void NoiseGen::drawPixel(sf::RenderTarget *target, int x, int y, int shade, int scale)
{

    sf::RectangleShape newshape( sf::Vector2f(scale,scale));

    newshape.setPosition(sf::Vector2f(x*scale, y*scale));

    newshape.setFillColor( sf::Color(shade,shade,shade));

    target->draw(newshape);
}
Example #5
0
void resetbmap(void) {
  int i;
  bzero(bmap, g_cols * g_lines * sizeof(struct block_t));
  for (i = 0; i != QUEUE_SIZE; ++i) {
    g_queue[i] = myrand() % NUM_SHAPES ;
  }
  g_canswap = 1;
  g_hold = -1;
  newshape(shiftqueue());
  automovedown();
}
Example #6
0
static Shape Shape77As20( // return an approximated BioID 20 point shape
    const Shape& shape)   // in: Stasm 77 point shape
{
    CV_Assert(shape.rows == 77);

    Shape newshape(20, 2);

    CopyPoint(newshape, shape,  0, 38);
    CopyPoint(newshape, shape,  1, 39);
    CopyPoint(newshape, shape,  2, 59);
    CopyPoint(newshape, shape,  3, 65);
    CopyPoint(newshape, shape,  4, 18);
    CopyPoint(newshape, shape,  5, 21);
    CopyPoint(newshape, shape,  6, 22);
    CopyPoint(newshape, shape,  7, 25);
    CopyPoint(newshape, shape,  8, 0);
    CopyPoint(newshape, shape,  9, 34);
    CopyPoint(newshape, shape, 10, 30);
    CopyPoint(newshape, shape, 11, 40);
    CopyPoint(newshape, shape, 12, 44);
    CopyPoint(newshape, shape, 13, 12);
    CopyPoint(newshape, shape, 14, 52);
    CopyPoint(newshape, shape, 15, 51);
    CopyPoint(newshape, shape, 16, 53);
    CopyPoint(newshape, shape, 17, 62);
    CopyPoint(newshape, shape, 18, 74);
    CopyPoint(newshape, shape, 19, 6);

#if MOD_A1 || MOD_A || MOD_A_EMU
    const double eyemouth = EyeMouthDist(shape);
    newshape(15, IY) += MAX(1, .02 * eyemouth); // move down, into nostril
    newshape(16, IY) += MAX(1, .02 * eyemouth); // move down, into nostril
#endif

    return newshape;
}
Example #7
0
int main(int argc, char **argv){
	//timer start
	timer = time(NULL);

	//For random movement of objects
	srand(time(NULL));
	//create object array
	objectarray.init();
	
	//SDL window and context management
    SDL_Window *window;
	SDL_EventState(SDL_MOUSEMOTION, SDL_IGNORE); 
	
    if(SDL_Init(SDL_INIT_VIDEO)<0){//initilizes the SDL video subsystem
	fprintf(stderr,"Unable to create window: %s\n", SDL_GetError());
	SDL_Quit();
	exit(1);//die on error
    }

	//create window
    window = SDL_CreateWindow(
	"Space Flyer", //Window title
	SDL_WINDOWPOS_UNDEFINED, //initial x position
	SDL_WINDOWPOS_UNDEFINED, //initial y position
	800,							//width, in pixels
	500,							//height, in pixels
	SDL_WINDOW_OPENGL	//flags to be had
    );
	
	//check window creation
    if(window==NULL){
	fprintf(stderr,"Unable to create window: %s\n",SDL_GetError());
    }
	
	//creates opengl context associated with the window
	SDL_GLContext glcontext=SDL_GL_CreateContext(window);
	
	//initializes glew
  glewExperimental=GL_TRUE;
  if(glewInit()){
    fprintf(stderr, "Unable to initalize GLEW");
    exit(EXIT_FAILURE);
  }
  
    init();
    int prevsecond=0;
    while(true){
    	//shape creation
    	if(objectarray.size<500){ //make sure it won't overflow the buffer
    	if((int)difftime(time(NULL), timer)!=prevsecond){ //check to make sure it's the next second
    		if(objectarray.size<6){ //for the first 6 shapes
    			if((int)difftime(time(NULL), timer)%1==0) //make a new one every 5 seconds
    				newshape();
    		}
    		else{
    			if((int)difftime(time(NULL), timer)%15==0) //else, make one every 15
    				newshape();
    		}
    	}
    }
    prevsecond = (int)difftime(time(NULL), timer); //set the second to compare next iteration
    
	input(window);//keyboard controls
	display(window);//displaying
    }

    SDL_GL_DeleteContext(glcontext);
    SDL_DestroyWindow(window);
    SDL_Quit();

    return 0;
}
Example #8
0
static Shape Shape77AsXm2vts68( // return an approximated XM2VTS 68 point shape
    const Shape& shape)         // in: Stasm 77 point shape
{
    CV_Assert(shape.rows == 77);

    Shape newshape(68, 2);

    CopyPoint(newshape,  shape,  0,  0);
    InterPoint(newshape, shape,  1, .6667, 1, 2);
    InterPoint(newshape, shape,  2, .5,    2, 3);
    CopyPoint(newshape,  shape,  3,  3);
    InterPoint(newshape, shape,  4, .3333, 3, 4);
    InterPoint(newshape, shape,  5, .6667, 4, 5);
    CopyPoint(newshape,  shape,  6,  5);
    CopyPoint(newshape,  shape,  7,  6);
    CopyPoint(newshape,  shape,  8,  7);
    InterPoint(newshape, shape,  9, .3333, 7, 8);
    InterPoint(newshape, shape, 10, .6667, 8, 9);
    CopyPoint(newshape,  shape, 11,  9);
    InterPoint(newshape, shape, 12, .5,    9, 10);
    InterPoint(newshape, shape, 13, .3333, 10, 11);
    CopyPoint(newshape,  shape, 14, 12);
    CopyPoint(newshape,  shape, 15, 25);
    CopyPoint(newshape,  shape, 16, 24);
    CopyPoint(newshape,  shape, 17, 23);
    CopyPoint(newshape,  shape, 18, 22);
    CopyPoint(newshape,  shape, 19, 27);
    CopyPoint(newshape,  shape, 20, 26);
    CopyPoint(newshape,  shape, 21, 18);
    CopyPoint(newshape,  shape, 22, 17);
    CopyPoint(newshape,  shape, 23, 16);
    CopyPoint(newshape,  shape, 24, 21);
    CopyPoint(newshape,  shape, 25, 20);
    CopyPoint(newshape,  shape, 26, 19);
    CopyPoint(newshape,  shape, 27, 34);
    CopyPoint(newshape,  shape, 28, 32);
    CopyPoint(newshape,  shape, 29, 30);
    CopyPoint(newshape,  shape, 30, 36);
    CopyPoint(newshape,  shape, 31, 38);
    CopyPoint(newshape,  shape, 32, 44);
    CopyPoint(newshape,  shape, 33, 42);
    CopyPoint(newshape,  shape, 34, 40);
    CopyPoint(newshape,  shape, 35, 46);
    CopyPoint(newshape,  shape, 36, 39);
    InterPoint(newshape, shape, 37, .6667, 30, 40);
    newshape(37, IX) = shape(50, IX);
    CopyPoint(newshape,  shape, 38, 50);
    CopyPoint(newshape,  shape, 39, 58);
    CopyPoint(newshape,  shape, 40, 57);
    CopyPoint(newshape,  shape, 41, 56);
    CopyPoint(newshape,  shape, 42, 55);
    CopyPoint(newshape,  shape, 43, 54);
    CopyPoint(newshape,  shape, 44, 48);
    InterPoint(newshape, shape, 45, .3333, 30, 40);
    newshape(45, IX) = shape(48, IX);
    CopyPoint(newshape,  shape, 46, 51);
    CopyPoint(newshape,  shape, 47, 53);
    CopyPoint(newshape,  shape, 48, 59);
    CopyPoint(newshape,  shape, 49, 60);
    CopyPoint(newshape,  shape, 50, 61);
    CopyPoint(newshape,  shape, 51, 62);
    CopyPoint(newshape,  shape, 52, 63);
    CopyPoint(newshape,  shape, 53, 64);
    CopyPoint(newshape,  shape, 54, 65);
    CopyPoint(newshape,  shape, 55, 72);
    CopyPoint(newshape,  shape, 56, 73);
    CopyPoint(newshape,  shape, 57, 74);
    CopyPoint(newshape,  shape, 58, 75);
    CopyPoint(newshape,  shape, 59, 76);
    CopyPoint(newshape,  shape, 60, 69);
    CopyPoint(newshape,  shape, 61, 70);
    CopyPoint(newshape,  shape, 62, 71);
    CopyPoint(newshape,  shape, 63, 66);
    CopyPoint(newshape,  shape, 64, 67);
    CopyPoint(newshape,  shape, 65, 68);
    InterPoint(newshape, shape, 66, .5, 67, 70);
    CopyPoint(newshape,  shape, 67, 52);

#if MOD_A1 || MOD_A || MOD_A_EMU
    const double eyemouth = EyeMouthDist(shape);
    newshape(38, IY) += MAX(1, .05 * eyemouth); // move side of nose down
    newshape(44, IY) += MAX(1, .05 * eyemouth); // move side of nose down
    newshape(46, IY) += MAX(1, .02 * eyemouth); // move down, into nostril
    newshape(47, IY) += MAX(1, .02 * eyemouth); // move down, into nostril
#endif

    return newshape;
}
Example #9
0
static void game(void) {
    char c;
    int counter = sspeed, rs, a, blocks = 0, paused = 0;

    gamescreen();
    clearboard();

    nexts = rnd()%28;
    nextc = rnd()%7 + 1;
    newshape();
    score = view = 0;
    if (view) drawview(nexts, nextc);
    level = 1;
    speed = sspeed;
    printscore();
    printlevel();

    for(;;) {
        if (paused) {
            gametick();
            c = tgetchar();
            switch(c) {
            case 'q':
                goto stopgame;
            case 'p':
                paused = 0;
                moveto(68,5); setbg(black);
                printf("           ");
                normal();
                flush();
            default:
                break;
            }
            continue;
        }

        if (counter <= 0) {
            counter = 14 - speed;
            if (shapefits(current.s, current.x, current.y+1)) {
                drawshape(current.s, 0, 40-WIDTH-8+current.x*2, current.y-3);
                current.y++;
                drawshape(current.s, current.color, 40-WIDTH-8+current.x*2,
                                                                current.y-3);
            } else {
                markboard(current.s, current.color, current.x, current.y);
                checkboard(current.y);
                incrscore(1);
                newshape();
                if (!shapefits(current.s, current.x, current.y)) goto stopgame;
                blocks++;
                if (blocks == blocksperlevel) {
                    blocks = 0;
                    incrlevel(1);
                }
                if (view) drawview(nexts, nextc);
            }
        }
        counter--;

        moveto(1,24);
        flush();
        gametick();
        c = tgetchar();
        switch(c) {
        case 'q':
            goto stopgame;
        case 'j':
            if (shapefits(current.s, current.x-1, current.y)) {
                drawshape(current.s, 0, 40-WIDTH-8+current.x*2, current.y-3);
                current.x--;
                drawshape(current.s, current.color, 40-WIDTH-8+current.x*2,
                                                              current.y-3);
            }
            break;
        case 'l':
            if (shapefits(current.s, current.x+1, current.y)) {
                drawshape(current.s, 0, 40-WIDTH-8+current.x*2, current.y-3);
                current.x++;
                drawshape(current.s, current.color, 40-WIDTH-8+current.x*2,
                                                              current.y-3);
            }
            break;
        case 'k':
            rs = (current.s & ~0x03) | ((current.s + 1) & 0x03);
            if (shapefits(rs, current.x, current.y)) {
                drawshape(current.s, 0, 40-WIDTH-8+current.x*2, current.y-3);
                current.s = rs;
                drawshape(current.s, current.color, 40-WIDTH-8+current.x*2,
                                                              current.y-3);
            }
            break;
        case ' ':
            for (a=1; ; a++) {
                if (!shapefits(current.s, current.x, current.y+a))
                    break;
            }
            if (shapefits(current.s, current.x, current.y+a-1)) {
                drawshape(current.s, 0, 40-WIDTH-8+current.x*2, current.y-3);
                current.y += a-1;
                drawshape(current.s, current.color, 40-WIDTH-8+current.x*2,
                                                              current.y-3);
            }
            incrscore(view ? (a-1) * 3 / 4 : a-1);
            break;
        case 'n':
            view ^= 1;
            if (view) drawview(nexts, nextc);
            else clearview();
            break;
        case 'p':
            paused = 1;
            moveto(68,5); setfg(white); setbg(blue);
            printf(" PAUSED!!! ");
            moveto(1,24);
            flush();
        default:
            break;
        }
    }

stopgame:
    setbg(white);
    rect(20,8,60,12);
    setbg(red);
    frect(21,9,59,11);
    setfg(white);
    bold();
    moveto(30,10);
    printf(" G A M E    O V E R ");
    moveto(1,24);
    flush();

    for(;;) {
        c = tgetchar();
        if (c > 0) return;
    }
}
Example #10
0
int
get_new_coord(double *new_coord[DIM],
	      double *x,
	      const Exo_DB *exo )
{
  int p,i,j;
  int dim = exo->num_dim;
  int num_nodes = exo->num_nodes;
  int displacement_somewhere = FALSE;
  int ln;
  int *moved;
  int e_start = exo->eb_ptr[0];
  int e_end   = exo->eb_ptr[exo->num_elem_blocks];
  int ielem;
  int gnn;
  int var;
  double phi[MDE];

  for(p = 0; p < dim; p++)
    {
      new_coord[p] = (double *) calloc(num_nodes, sizeof(double));
      dcopy1( num_nodes, Coor[p], new_coord[p] );
    }

  for(p = 0; p < upd->Num_Mat; p++)
    displacement_somewhere |= ( pd_glob[p]->e[R_MESH1] );

  if ( displacement_somewhere == FALSE ) return (FALSE );

  moved = (int *) calloc( num_nodes, sizeof(int) );


  /*
   * Loop through nodes, find displacement, and add it into 
   * the coordinate
   */


  for(ielem = e_start; ielem < e_end; ielem++)
    {
      double displacement[DIM];

      load_elem_dofptr(ielem, exo, x, x, x, x, x, 1);

      for(ln = 0; ln < ei->num_local_nodes; ln++)
	{
	  double xi[3] = {0.0, 0.0, 0.0};
	  
	  find_nodal_stu(ln, ei->ielem_type, xi, xi+1, xi+2);

	  gnn = exo->elem_node_list[ exo->elem_node_pntr[ielem] + ln ] ;

	  memset(displacement, 0, sizeof(double)*DIM);
	  
	  if( moved[gnn] != 1 )
	    {
	      for(p = 0; p < DIM; p++)
		{
		  var = MESH_DISPLACEMENT1 + p;
		  
		  for(i = 0; i < ei->dof[var]; i++)
		    {
		      phi[i] = newshape(xi, 
					ei->ielem_type, 
					PSI, 
					ei->dof_list[var][i], 
					ei->ielem_shape,
					pd->i[var],
					i);
		    }

		  if( pd->v[var] )
		    {
		      for(j = 0; j < ei->dof[var]; j++)
			{
			  displacement[p] += *esp->d[p][j] * phi[j];
			}
		      moved[gnn] = 1;
		    }
		  else
		    displacement[p] = 0.0;
		}
	    }

	  for(p = 0; p < dim; p++)
	    new_coord[p][gnn] += displacement[p];
	}
    }

  safer_free((void **) &moved);
  
  return( TRUE );
}
Example #11
0
static void TraceShape(  // write an image file showing current shape on the image
    const Shape& shape,  // in: current search shape
    const Image& pyrimg, // in: image scaled to this pyramid level
    int          ilev,   // in: pyramid level (0 is full size)
    int          iter,   // in: model iteration (-1 if start shape)
    const char*  suffix) // in
{
#if TRACE_IMAGES // will be 0 unless debugging (defined in stasm.h)

    static int index; // number images so they appear in order in the directory
    // start at index 30 because lower indices have already used for facedet etc.
    if (strcmp(suffix, "start") == 0)
        index = 30;
    Image img; // pyrimg rescaled back to full size image (after rescaling by eyemouth)
    const double RESOLUTION = 2; // 1 for no extra resolution, 2 for double resolution
    const double rescale = RESOLUTION / GetPyrScale(ilev);
    cv::resize(pyrimg, img, cv::Size(), rescale, rescale, cv::INTER_NEAREST);
    CImage cimg; cvtColor(img, cimg, CV_GRAY2BGR); // color image
    DesaturateImg(cimg);
    Shape shape1(RoundMat(shape));
    shape1 += .4; // put shape points in center of rescaled pixels
    shape1 *= rescale;
    DrawShape(cimg, shape1, C_YELLOW, false, 1);
    char path[SLEN];
    if (iter < 0) // start shape?
        sprintf(path, "%s_%2.2d_%s.bmp", Base(imgpath_g), index, suffix);
    else
        sprintf(path, "%s_%2.2d_lev%d_iter%d_%s.bmp",
                Base(imgpath_g), index, ilev, iter, suffix);
    ImgPrintf(cimg, 10 * RESOLUTION, 20 * RESOLUTION, C_YELLOW, 2, path);
    if (iter >= 0)
    {
        // draw 1D patch boundary at one point (patch is drawn
        // horizontal, not rotated to shape boundary as it should be)
        // [Thanks to Satish Lokkoju for RoundMat fix]

        Shape shape2(RoundMat(shape));
        int ipoint = 0;
        int proflen = 9; // TASM_1D_PROFLEN
        int x1 = cvRound(shape2(ipoint, IX)) - proflen / 2;
        int x2 = x1 + proflen;
        int y1 = cvRound(shape2(ipoint, IY));
        int y2 = y1 + 1;
        rectangle(cimg,
                  cv::Point(cvRound(rescale * x1), cvRound(rescale * y1)),
                  cv::Point(cvRound(rescale * x2), cvRound(rescale * y2)),
                  CV_RGB(255,0,0), 1);

        // draw 2D patch boundary at one point

        if (ilev <= HAT_START_LEV) // we use HATs only at upper pyr levs
        {
            // get position of left eye pupil by first converting to a shape17
            ipoint = 0; // assume we can't get position of left eye pupil
            Shape newshape(Shape17OrEmpty(shape2));
            if (newshape.rows) // successfully converted to a shape17?
                ipoint = L17_LPupil;
            else
                newshape = shape2;
            #define round2(x) 2 * cvRound((x) / 2)
            int patchwidth = HAT_PATCH_WIDTH + round2(ilev * HAT_PATCH_WIDTH_ADJ);
            x1 = cvRound(newshape(ipoint, IX)) - patchwidth / 2;
            x2 = x1 + patchwidth;
            y1 = cvRound(newshape(ipoint, IY)) - patchwidth / 2;
            y2 = y1 + patchwidth;
            rectangle(cimg,
                      cv::Point(cvRound(rescale * x1), cvRound(rescale * y1)),
                      cv::Point(cvRound(rescale * x2), cvRound(rescale * y2)),
                      CV_RGB(255,0,0), 1);
        }
    }
    lprintf("%s\n", path);
    if (!cv::imwrite(path, cimg))
        Err("Cannot write %s", path);
    index++;

#endif // TRACE_IMAGES
}