コード例 #1
0
ファイル: gif.c プロジェクト: AaronNGray/texlive-libs
int main(void)
{
	int i;
	FILE * out;

	gdImagePtr im;
	gdImagePtr prev =NULL;
	int black;

	im = gdImageCreate(100, 100);
	if (!im) {
		fprintf(stderr, "can't create image");
		return 1;
	}

	out = fopen("anim.gif", "wb");
	if (!out) {
		fprintf(stderr, "can't create file %s", "anim.gif");
		return 1;
	}

	gdImageColorAllocate(im, 255, 255, 255); /* allocate white as side effect */
	gdImageGifAnimBegin(im, out, 1, -1);

	for(i = 0; i < 20; i++) {
		int r,g,b;
		im = gdImageCreate(100, 100);
		r = rand() % 255;
		g = rand() % 255;
		b = rand() % 255;

		gdImageColorAllocate(im, 255, 255, 255);  /* allocate white as side effect */
		black = gdImageColorAllocate(im,  r, g, b);
		printf("(%i, %i, %i)\n",r, g, b);
		gdImageFilledRectangle(im, rand() % 100, rand() % 100, rand() % 100, rand() % 100, black);
		gdImageGifAnimAdd(im, out, 1, 0, 0, 10, 1, prev);

		if(prev) {
			gdImageDestroy(prev);
		}
		prev = im;
	}

	gdImageGifAnimEnd(out);
	fclose(out);

	return 0;
}
コード例 #2
0
/* main: executes simulation, creates one output file for each time
 * step */
int main(int argc,char *argv[]) {
  int iter;

  MPI_Init(&argc, &argv);
  assert(argc==2);
  init(argv[1]);
  write_frame(0);
  for (iter = 1; iter <= nsteps; iter++) {
    exchange_ghost_cells();
    update();
    if (iter%wstep==0) write_frame(iter);
  }
  MPI_Finalize();
  free(u);
  free(u_new);
  if (rank == 0) {
    gdImageDestroy(previm);
    gdImageGifAnimEnd(file);
    fclose(file);
    free(buf);
    free(colors);
  }
  return 0;
}
コード例 #3
0
ファイル: makegif.c プロジェクト: codeholic/bellman
void write_animated_gif(universe *u, const char *filename) {

        FILE *out = fopen(filename, "wb");
        gdImagePtr im;

        int l, r, t, b;
        int ll, rr, tt, bb;

        generation *g = u->first;
        generation_find_bounds(g, &l, &r, &t, &b);

        for(g = g->next; g; g = g->next) {
                generation_find_bounds(g, &ll, &rr, &tt, &bb);
                if(ll < l) l = ll;
                if(rr > r) r = rr;
                if(tt < t) t = tt;
                if(bb > b) b = bb;
        }

        int scale = 4;
	int delay = 10;

        im = gdImageCreate((r - l) * scale, (b - t) * scale);

        int background = gdImageColorAllocate(im, 230, 230, 255);
        gdImageRectangle(im, 0, 0, (r-l) * scale, (b-t) * scale, background);

        int tile_bg = gdImageColorAllocate(im, 255, 255, 255);
        int tile_frame = gdImageColorAllocate(im, 230, 230, 230);

        int on = gdImageColorAllocate(im, 0, 0, 0);
        int unknown = gdImageColorAllocate(im, 255, 255, 0);
        int unknown_stable = gdImageColorAllocate(im, 192, 255, 0);

	gdImageGifAnimBegin(im, out, 1, 0);

        for(g = u->first; g; g = g->next) {
                tile *tp;
                for(tp = g->all_first; tp; tp = tp->all_next) {
                        if(!(tp->flags & IS_LIVE)) {
                                continue;
                        }

                        gdImageFilledRectangle(im, GX(tp->xpos), GY(tp->ypos),
                                               GX(tp->xpos + TILE_WIDTH)-1, 
                                               GY(tp->ypos + TILE_HEIGHT)-1,
                                               tile_bg);

                        gdImageRectangle(im, GX(tp->xpos), GY(tp->ypos),
                                         GX(tp->xpos + TILE_WIDTH)-1, 
                                         GY(tp->ypos + TILE_HEIGHT)-1,
                                         tile_frame);
                        int xx, yy;
                        for(xx = 0; xx < TILE_WIDTH; xx++) {
                                for(yy = 0; yy < TILE_HEIGHT; yy++) {
                                        cellvalue cv = tile_get_cell(tp, xx, yy);
                                        int colour = -1;
                                        if(cv == ON) {
                                                colour = on;
                                        } else if(cv == UNKNOWN) {
                                                colour = unknown;
                                        } else if(cv == UNKNOWN_STABLE) {
                                                colour = unknown_stable;
                                        } 
                                        if(colour >= 0)
                                                gdImageFilledRectangle(im, 
                                                                       GX(tp->xpos + xx),
                                                                       GY(tp->ypos + yy),
                                                                       GX(tp->xpos + xx + 1) - 1,
                                                                       GY(tp->ypos + yy + 1) - 1,
                                                                       colour);
                                }
                        }
                }
		gdImageGifAnimAdd(im, out, 0, 0, 0,
				  delay, gdDisposalNone, NULL);
        }

	gdImageGifAnimEnd(out);

        fclose(out);
        gdImageDestroy(im);
}