Ejemplo n.º 1
0
static unsigned long
distort_draw (Display *dpy, Window window, void *closure)
{
  struct state *st = (struct state *) closure;
  int k;

  if (st->img_loader)   /* still loading */
    {
      st->img_loader = load_image_async_simple (st->img_loader, 0, 0, 0, 0, 0);
      if (! st->img_loader) {  /* just finished */
        distort_finish_loading (st);
      }
      return st->delay;
    }

  if (!st->img_loader &&
      st->start_time + st->duration < time ((time_t *) 0)) {
    if (st->pm) XFreePixmap (st->dpy, st->pm);
    st->pm = XCreatePixmap (st->dpy, st->window,
                            st->xgwa.width, st->xgwa.height, st->xgwa.depth);
    st->img_loader = load_image_async_simple (0, st->xgwa.screen, st->window,
                                              st->pm, 0, 0);
    return st->delay;
  }

  for (k = 0; k < st->number; k++) {
    st->effect(st,k);
    st->draw(st,k);
  }
  return st->delay;
}
Ejemplo n.º 2
0
static unsigned long
twang_draw (Display *dpy, Window window, void *closure)
{
  struct state *st = (struct state *) closure;

  if (st->img_loader)   /* still loading */
    {
      st->img_loader = load_image_async_simple (st->img_loader, 0, 0, 0, 0, 0);
      if (! st->img_loader) {  /* just finished */
        grabImage_done (st);
      }
      return st->delay;
    }

  if (!st->img_loader &&
      st->start_time + st->duration < time ((time_t *) 0)) {
    XWindowAttributes xgwa;
    XGetWindowAttributes (st->dpy, st->window, &xgwa);
    grabImage_start (st, &xgwa);
    return st->delay;
  }

  modelEvents (st);
  updateModel (st);
  renderFrame (st);
  return st->delay;
}
Ejemplo n.º 3
0
static void *
distort_init (Display *dpy, Window window)
{
  struct state *st = (struct state *) calloc (1, sizeof(*st));
	XGCValues gcv;
	long gcflags;

    st->dpy = dpy;
    st->window = window;

    distort_reset (st);

	st->black_pixel = BlackPixelOfScreen( st->xgwa.screen );

	gcv.function = GXcopy;
	gcv.subwindow_mode = IncludeInferiors;
	gcflags = GCFunction;
	if (use_subwindow_mode_p(st->xgwa.screen, st->window)) /* see grabscreen.c */
		gcflags |= GCSubwindowMode;
	st->gc = XCreateGC (st->dpy, st->window, gcflags, &gcv);

    /* On MacOS X11, XGetImage on a Window often gets an inexplicable BadMatch,
       possibly due to the window manager having occluded something?  It seems
       nondeterministic. Loading the image into a pixmap instead fixes it. */
    if (st->pm) XFreePixmap (st->dpy, st->pm);
    st->pm = XCreatePixmap (st->dpy, st->window,
                            st->xgwa.width, st->xgwa.height, st->xgwa.depth);

    st->img_loader = load_image_async_simple (0, st->xgwa.screen, st->window,
                                              st->pm, 0, 0);
    st->start_time = time ((time_t *) 0);
    return st;
}
Ejemplo n.º 4
0
static unsigned long
blitspin_draw (Display *dpy, Window window, void *closure)
{
  struct state *st = (struct state *) closure;
  int this_delay = st->delay;
  int qwad;

  if (st->img_loader)   /* still loading */
    {
      st->img_loader = load_image_async_simple (st->img_loader, 0, 0, 0, 0, 0);

      if (!st->img_loader) { /* just finished */
        st->first_time = 0;
        st->loaded_p = True;
        st->qwad = -1;
        st->start_time = time ((time_t) 0);
        blitspin_init_2 (st);
      }

      /* Rotate nothing if the very first image is not yet loaded */
      if (! st->loaded_p)
        return this_delay;
    }

  if (!st->img_loader &&
      st->load_ext_p &&
      st->start_time + st->duration < time ((time_t) 0)) {
    /* Start a new image loading, but keep rotating the old image 
       until the new one arrives. */
    st->img_loader = load_image_async_simple (0, st->xgwa.screen, st->window,
                                              st->bitmap, 0, 0);
  }

  if (st->qwad == -1) 
    {
      bitblt(st, st->mask, st->mask, clear,0,0, st->size,    st->size,    0,0);
      bitblt(st, st->mask, st->mask, set,  0,0, st->size>>1, st->size>>1, 0,0);
      st->qwad = st->size>>1;
    }
Ejemplo n.º 5
0
/* grab the source image */
static void
grabImage_start (struct state *st, XWindowAttributes *xwa)
{
    /* On MacOS X11, XGetImage on a Window often gets an inexplicable BadMatch,
       possibly due to the window manager having occluded something?  It seems
       nondeterministic. Loading the image into a pixmap instead fixes it. */
    if (st->pm) XFreePixmap (st->dpy, st->pm);
    st->pm = XCreatePixmap (st->dpy, st->window,
                            xwa->width, xwa->height, xwa->depth);

    st->start_time = time ((time_t *) 0);
    st->img_loader = load_image_async_simple (0, xwa->screen, st->window,
                                              st->pm, 0, 0);
}
Ejemplo n.º 6
0
static unsigned long
boxfit_draw (Display *dpy, Window window, void *closure)
{
  state *st = (state *) closure;
  int delay;

  if (st->img_loader)   /* still loading */
    {
      st->img_loader = load_image_async_simple (st->img_loader, 0, 0, 0, 0, 0);
      if (! st->img_loader)  /* just finished */
        {
          st->image = XGetImage (st->dpy,
                                 (st->loading_pixmap ? st->loading_pixmap :
                                  st->window),
                                 0, 0,
                                 st->xgwa.width, st->xgwa.height, ~0L, 
                                 ZPixmap);
          if (st->loading_pixmap) XFreePixmap (st->dpy, st->loading_pixmap);
          XSetWindowBackground (st->dpy, st->window, st->bg_color);
          if (st->loading_pixmap)
            XClearWindow (st->dpy, st->window);
          else
            st->countdown = 2000000;
          st->loading_pixmap = 0;
        }
      return st->delay;
    }

  if (st->countdown > 0)
    {
      st->countdown -= st->delay;
      if (st->countdown <= 0)
        {
          st->countdown = 0;
          XClearWindow (st->dpy, st->window);
        }
      return st->delay;
    }

  if (st->growing_p) {
    draw_boxes (st);
    delay = grow_boxes (st);
  } else {
    delay = shrink_boxes (st);
    draw_boxes (st);
  }
  return delay;
}
Ejemplo n.º 7
0
static void *
decayscreen_init (Display *dpy, Window window)
{
  struct state *st = (struct state *) calloc (1, sizeof(*st));
  XGCValues gcv;
  XWindowAttributes xgwa;
  long gcflags;
  unsigned long bg;
  char *s;

  st->dpy = dpy;
  st->window = window;

  s = get_string_resource(st->dpy, "mode", "Mode");
  if      (s && !strcmp(s, "shuffle")) st->mode = SHUFFLE;
  else if (s && !strcmp(s, "up")) st->mode = UP;
  else if (s && !strcmp(s, "left")) st->mode = LEFT;
  else if (s && !strcmp(s, "right")) st->mode = RIGHT;
  else if (s && !strcmp(s, "down")) st->mode = DOWN;
  else if (s && !strcmp(s, "upleft")) st->mode = UPLEFT;
  else if (s && !strcmp(s, "downleft")) st->mode = DOWNLEFT;
  else if (s && !strcmp(s, "upright")) st->mode = UPRIGHT;
  else if (s && !strcmp(s, "downright")) st->mode = DOWNRIGHT;
  else if (s && !strcmp(s, "in")) st->mode = IN;
  else if (s && !strcmp(s, "out")) st->mode = OUT;
  else if (s && !strcmp(s, "melt")) st->mode = MELT;
  else if (s && !strcmp(s, "stretch")) st->mode = STRETCH;
  else if (s && !strcmp(s, "fuzz")) st->mode = FUZZ;
  else {
    if (s && *s && !!strcmp(s, "random"))
      fprintf(stderr, "%s: unknown mode %s\n", progname, s);
    st->mode = random() % (FUZZ+1);
  }

  st->delay = get_integer_resource (st->dpy, "delay", "Integer");

  if (st->delay < 0) st->delay = 0;

  XGetWindowAttributes (st->dpy, st->window, &xgwa);

  gcv.function = GXcopy;
  gcv.subwindow_mode = IncludeInferiors;
  bg = get_pixel_resource (st->dpy, xgwa.colormap, "background", "Background");
  gcv.foreground = bg;

  gcflags = GCForeground | GCFunction;
  if (use_subwindow_mode_p(xgwa.screen, st->window)) /* see grabscreen.c */
    gcflags |= GCSubwindowMode;
  st->gc = XCreateGC (st->dpy, st->window, gcflags, &gcv);

  st->sizex = xgwa.width;
  st->sizey = xgwa.height;

  if (st->mode == MELT || st->mode == STRETCH)
    st->iterations = 1;    /* slow down for smoother melting */

  st->img_loader = load_image_async_simple (0, xgwa.screen, st->window,
                                            st->window, 0, 0);

  return st;
}
Ejemplo n.º 8
0
/*
 * perform one iteration of decay
 */
static unsigned long
decayscreen_draw (Display *dpy, Window window, void *closure)
{
    struct state *st = (struct state *) closure;
    int left, top, width, height, toleft, totop;

#define L 101
#define R 102
#define U 103
#define D 104
    static const int no_bias[]        = { L,L,L,L, R,R,R,R, U,U,U,U, D,D,D,D };
    static const int up_bias[]        = { L,L,L,L, R,R,R,R, U,U,U,U, U,U,D,D };
    static const int down_bias[]      = { L,L,L,L, R,R,R,R, U,U,D,D, D,D,D,D };
    static const int left_bias[]      = { L,L,L,L, L,L,R,R, U,U,U,U, D,D,D,D };
    static const int right_bias[]     = { L,L,R,R, R,R,R,R, U,U,U,U, D,D,D,D };

    static const int upleft_bias[]    = { L,L,L,L, L,R,R,R, U,U,U,U, U,D,D,D };
    static const int downleft_bias[]  = { L,L,L,L, L,R,R,R, U,U,U,D, D,D,D,D };
    static const int upright_bias[]   = { L,L,L,R, R,R,R,R, U,U,U,U, U,D,D,D };
    static const int downright_bias[] = { L,L,L,R, R,R,R,R, U,U,U,D, D,D,D,D };

    if (st->img_loader)   /* still loading */
      {
        st->img_loader = load_image_async_simple (st->img_loader, 
                                                  0, 0, 0, 0, 0);
        if (! st->img_loader) {  /* just finished */
          if (st->mode == MELT || st->mode == STRETCH)
            /* make sure screen eventually turns background color */
            XDrawLine (st->dpy, st->window, st->gc, 0, 0, st->sizex, 0); 
        }
      return st->delay;
    }

    switch (st->mode) {
      case SHUFFLE:	st->current_bias = no_bias; break;
      case UP:		st->current_bias = up_bias; break;
      case LEFT:	st->current_bias = left_bias; break;
      case RIGHT:	st->current_bias = right_bias; break;
      case DOWN:	st->current_bias = down_bias; break;
      case UPLEFT:	st->current_bias = upleft_bias; break;
      case DOWNLEFT:	st->current_bias = downleft_bias; break;
      case UPRIGHT:	st->current_bias = upright_bias; break;
      case DOWNRIGHT:	st->current_bias = downright_bias; break;
      case IN:		st->current_bias = no_bias; break;
      case OUT:		st->current_bias = no_bias; break;
      case MELT:	st->current_bias = no_bias; break;
      case STRETCH:	st->current_bias = no_bias; break;
      case FUZZ:	st->current_bias = no_bias; break;
     default: abort();
    }

#define nrnd(x) ((x) ? random() % (x) : x)

    if (st->mode == MELT || st->mode == STRETCH) {
      left = nrnd(st->sizex/2);
      top = nrnd(st->sizey);
      width = nrnd( st->sizex/2 ) + st->sizex/2 - left;
      height = nrnd(st->sizey - top);
      toleft = left;
      totop = top+1;

    } else if (st->mode == FUZZ) {  /* By Vince Levey <*****@*****.**>;
                                   inspired by the "melt" mode of the
                                   "scrhack" IrisGL program by Paul Haeberli
                                   circa 1991. */
      left = nrnd(st->sizex - 1);
      top  = nrnd(st->sizey - 1);
      st->fuzz_toggle = !st->fuzz_toggle;
      if (st->fuzz_toggle)
        {
          totop = top;
          height = 1;
          toleft = nrnd(st->sizex - 1);
          if (toleft > left)
            {
              width = toleft-left;
              toleft = left;
              left++;
            }
          else
            {
              width = left-toleft;
              left = toleft;
              toleft++;
            }
        }
      else
        {
          toleft = left;
          width = 1;
          totop  = nrnd(st->sizey - 1);
          if (totop > top)
            {
              height = totop-top;
              totop = top;
              top++;
            }
          else
            {
              height = top-totop;
              top = totop;
              totop++;
            }
        }

    } else {

      left = nrnd(st->sizex - 1);
      top = nrnd(st->sizey);
      width = nrnd(st->sizex - left);
      height = nrnd(st->sizey - top);
      
      toleft = left;
      totop = top;
      if (st->mode == IN || st->mode == OUT) {
	int x = left+(width/2);
	int y = top+(height/2);
	int cx = st->sizex/2;
	int cy = st->sizey/2;
	if (st->mode == IN) {
	  if      (x > cx && y > cy)   st->current_bias = upleft_bias;
	  else if (x < cx && y > cy)   st->current_bias = upright_bias;
	  else if (x < cx && y < cy)   st->current_bias = downright_bias;
	  else /* (x > cx && y < cy)*/ st->current_bias = downleft_bias;
	} else {
	  if      (x > cx && y > cy)   st->current_bias = downright_bias;
	  else if (x < cx && y > cy)   st->current_bias = downleft_bias;
	  else if (x < cx && y < cy)   st->current_bias = upleft_bias;
	  else /* (x > cx && y < cy)*/ st->current_bias = upright_bias;
	}
      }
      
      switch (st->current_bias[random() % (sizeof(no_bias)/sizeof(*no_bias))]) {
      case L: toleft = left-1; break;
      case R: toleft = left+1; break;
      case U: totop = top-1; break;
      case D: totop = top+1; break;
      default: abort(); break;
      }
    }
    
    if (st->mode == STRETCH) {
      XCopyArea (st->dpy, st->window, st->window, st->gc, 0, st->sizey-top-2, st->sizex, top+1, 
		 0, st->sizey-top-1); 
    } else {
      XCopyArea (st->dpy, st->window, st->window, st->gc, left, top, width, height,
		 toleft, totop);
    }

#undef nrnd

    return st->delay;
}
Ejemplo n.º 9
0
static void *
zoom_init (Display *dpy, Window window)
{
  struct state *st = (struct state *) calloc (1, sizeof(*st));
  XGCValues gcv;
  XWindowAttributes xgwa;
  Colormap cmap;
  unsigned long bg;
  long gcflags;
  int nblocksx, nblocksy;

  st->dpy = dpy;
  st->window = window;
  XGetWindowAttributes(st->dpy, st->window, &xgwa);
  st->screen = xgwa.screen;
  st->sizex = xgwa.width;
  st->sizey = xgwa.height;
  cmap = xgwa.colormap;
  bg = get_pixel_resource(st->dpy, cmap, "background", "Background");

  st->delay = get_integer_resource(st->dpy, "delay", "Integer");
  if (st->delay < 1)
    st->delay = 1;
  st->duration = get_integer_resource (st->dpy, "duration", "Seconds");
  if (st->duration < 1)
    st->duration = 1;
  st->pixwidth = get_integer_resource(st->dpy, "pixwidth", "Integer");
  if (st->pixwidth < 1)
    st->pixwidth = 1;
  st->pixheight = get_integer_resource(st->dpy, "pixheight", "Integer");
  if (st->pixheight < 1)
    st->pixheight = 1;
  st->pixspacex = get_integer_resource(st->dpy, "pixspacex", "Integer");
  if (st->pixspacex < 0)
    st->pixspacex = 0;
  st->pixspacey = get_integer_resource(st->dpy, "pixspacey", "Integer");
  if (st->pixspacey < 0)
    st->pixspacey = 0;
  st->lenses = get_boolean_resource(st->dpy, "lenses", "Boolean");
  st->lensoffsetx = get_integer_resource(st->dpy, "lensoffsetx", "Integer");
  st->lensoffsetx = MAX(0, MIN(st->pixwidth, st->lensoffsetx));
  st->lensoffsety = get_integer_resource(st->dpy, "lensoffsety", "Integer");
  st->lensoffsety = MAX(0, MIN(st->pixwidth, st->lensoffsety));

  gcv.function = GXcopy;
  gcv.subwindow_mode = IncludeInferiors;
  gcflags = GCForeground|GCFunction;
  gcv.foreground = bg;
  if (!st->lenses && use_subwindow_mode_p(xgwa.screen, st->window))       /* see grabscreen.c */
    gcflags |= GCSubwindowMode;
  st->window_gc = XCreateGC(st->dpy, st->window, gcflags, &gcv);


  st->orig_map = NULL;
  st->pm = XCreatePixmap(st->dpy, st->window, st->sizex, st->sizey, xgwa.depth);

  XFillRectangle(st->dpy, st->window, st->window_gc, 0, 0, st->sizex, st->sizey);
  XSetWindowBackground(st->dpy, st->window, bg);

  st->start_time = time ((time_t) 0);
  st->img_loader = load_image_async_simple (0, xgwa.screen, st->window,
                                            st->pm, 0, 0);

  /* We might have needed this to grab the image, but if we leave this set
     to GCSubwindowMode, then we'll *draw* right over subwindows too. */
  XSetSubwindowMode (st->dpy, st->window_gc, ClipByChildren);


  nblocksx = (int)ceil((double)st->sizex / (double)(st->pixwidth + st->pixspacex));
  nblocksy = (int)ceil((double)st->sizey / (double)(st->pixheight + st->pixspacey));
  if (st->lenses)
    st->s = MAX((nblocksx - 1) * st->lensoffsetx + st->pixwidth, 
	    (nblocksy - 1) * st->lensoffsety + st->pixheight) * 2;
  else
    st->s = MAX(nblocksx, nblocksy) * 2;

  st->sinusoid_offset = random();

  return st;
}
Ejemplo n.º 10
0
static unsigned long
zoom_draw (Display *dpy, Window window, void *closure)
{
  struct state *st = (struct state *) closure;
  unsigned x, y, i, j;

  long now;

  if (st->img_loader)   /* still loading */
    {
      st->img_loader = load_image_async_simple (st->img_loader, 0, 0, 0, 0, 0);
      if (! st->img_loader) {  /* just finished */
        XClearWindow (st->dpy, st->window);
        st->start_time = time ((time_t) 0);
        if (!st->lenses) {
          st->orig_map = XGetImage(st->dpy, st->pm, 0, 0, st->sizex, st->sizey, ~0L, ZPixmap);
/*          XFreePixmap(st->dpy, st->pm);
          st->pm = 0;*/
        }
      }
      return st->delay;
    }

  if (!st->img_loader &&
      st->start_time + st->duration < time ((time_t) 0)) {
    st->img_loader = load_image_async_simple (0, st->screen, st->window,
                                              st->pm, 0, 0);
    return st->delay;
  }

#define nrnd(x) (random() % (x))

  now = currentTimeInMs(st);
  now += st->sinusoid_offset;  /* don't run multiple screens in lock-step */

  /* find new x,y */
  st->tlx = ((1. + sin(((double)now) / X_PERIOD * 2. * M_PI))/2.0)
    * (st->sizex - st->s/2) /* -s/4 */ + MINX;
  st->tly = ((1. + sin(((double)now) / Y_PERIOD * 2. * M_PI))/2.0)
    * (st->sizey - st->s/2) /* -s/4 */ + MINY;

  if (st->lenses) {
    for (x = i = 0; x < st->sizex; x += (st->pixwidth + st->pixspacex), ++i)
      for (y = j = 0; y < st->sizey; y += (st->pixheight + st->pixspacey), ++j) {
	XCopyArea(st->dpy, st->pm /* src */, st->window /* dest */, st->window_gc,
		  st->tlx + i * st->lensoffsetx /* src_x */, 
		  st->tly + j * st->lensoffsety /* src_y */,
		  st->pixwidth, st->pixheight,
		  x /* dest_x */, y /* dest_y */);
      }
  } else {
    for (x = i = 0; x < st->sizex; x += (st->pixwidth + st->pixspacex), ++i)
      for (y = j = 0; y < st->sizey; y += (st->pixheight + st->pixspacey), ++j) {
	XSetForeground(st->dpy, st->window_gc, XGetPixel(st->orig_map, st->tlx+i, st->tly+j));
	XFillRectangle(st->dpy, st->window, st->window_gc, 
		       i * (st->pixwidth + st->pixspacex),
		       j * (st->pixheight + st->pixspacey), st->pixwidth, st->pixheight);
      }
  }

  return st->delay;
}
Ejemplo n.º 11
0
static void *
spotlight_init (Display *dpy, Window window)
{
  struct state *st = (struct state *) calloc (1, sizeof(*st));
  XGCValues gcv;
  XWindowAttributes xgwa;
  long gcflags;
  Colormap cmap;
  unsigned long fg, bg;
  GC clip_gc;
  Pixmap clip_pm;

  st->dpy = dpy;
  st->window = window;
  st->first_p = True;

  XGetWindowAttributes (st->dpy, st->window, &xgwa);
  st->sizex = xgwa.width;
  st->sizey = xgwa.height;
  cmap = xgwa.colormap;
  fg = get_pixel_resource (st->dpy, cmap, "foreground", "Foreground");
  bg = get_pixel_resource (st->dpy, cmap, "background", "Background");

  /* read parameters, keep em sane */
  st->delay = get_integer_resource (st->dpy, "delay", "Integer");
  if (st->delay < 1) st->delay = 1;
  st->radius = get_integer_resource (st->dpy, "radius", "Integer");
  if (st->radius < 0) st->radius = 125;

  /* Don't let the spotlight be bigger than the window */
  while (st->radius > xgwa.width * 0.45)
    st->radius /= 2;
  while (st->radius > xgwa.height * 0.45)
    st->radius /= 2;

  if (st->radius < 4)
    st->radius = 4;

  /* do the dance */
  gcv.function = GXcopy;
  gcv.subwindow_mode = IncludeInferiors;
  gcflags = GCForeground | GCFunction;
  gcv.foreground = bg;

#ifdef NOPE
  if (use_subwindow_mode_p(xgwa.screen, st->window)) /* see grabscreen.c */
    gcflags |= GCSubwindowMode;
#endif
  st->window_gc = XCreateGC(st->dpy, st->window, gcflags, &gcv);

  /* grab screen to pixmap */
  st->pm = XCreatePixmap(st->dpy, st->window, st->sizex, st->sizey, xgwa.depth);
  XClearWindow(st->dpy, st->window);

  /* create buffer to reduce flicker */
#ifdef HAVE_COCOA	/* Don't second-guess Quartz's double-buffering */
  st->buffer = 0;
#else
  st->buffer = XCreatePixmap(st->dpy, st->window, st->sizex, st->sizey, xgwa.depth);
#endif

  st->buffer_gc = XCreateGC(st->dpy, (st->buffer ? st->buffer : window), gcflags, &gcv);
  if (st->buffer)
    XFillRectangle(st->dpy, st->buffer, st->buffer_gc, 0, 0, st->sizex, st->sizey);

  /* blank out screen */
  XFillRectangle(st->dpy, st->window, st->window_gc, 0, 0, st->sizex, st->sizey);
  XSetWindowBackground (st->dpy, st->window, bg);

  /* create clip mask (so it's a circle, not a square) */
  clip_pm = XCreatePixmap(st->dpy, st->window, st->radius*4, st->radius*4, 1);
  st->img_loader = load_image_async_simple (0, xgwa.screen, st->window, st->pm,
                                            0, 0);

  gcv.foreground = 0L;
  clip_gc = XCreateGC(st->dpy, clip_pm, gcflags, &gcv);
  XFillRectangle(st->dpy, clip_pm, clip_gc, 0, 0, st->radius*4, st->radius*4);

  XSetForeground(st->dpy, clip_gc, 1L);
  XFillArc(st->dpy, clip_pm, clip_gc, st->radius , st->radius,
	   st->radius*2, st->radius*2, 0, 360*64);

  /* set buffer's clip mask to the one we just made */
  XSetClipMask(st->dpy, st->buffer_gc, clip_pm);

  /* free everything */
  XFreeGC(st->dpy, clip_gc);
  XFreePixmap(st->dpy, clip_pm);

  /* avoid remants */
  st->max_x_speed = st->max_y_speed = st->radius;
  
  st->off = random();

#ifdef DEBUG
  /* create GC with white fg */
  gcv.foreground = fg;
  st->white_gc = XCreateGC(st->dpy, st->window, gcflags, &gcv);
#endif
  return st;
}
Ejemplo n.º 12
0
/*
 * perform one iteration
 */
static void
onestep (struct state *st, Bool first_p)
{
  long now;

  if (st->img_loader)   /* still loading */
    {
      st->img_loader = load_image_async_simple (st->img_loader, 0, 0, 0, 0, 0);
      return;
    }

#define nrnd(x) (random() % (x))

  st->oldx = st->x;
  st->oldy = st->y;

  st->s = st->radius *4 ;   /* s = width of buffer */

  now = currentTimeInMs(st) + st->off;

  /* find new x,y */
  st->x = ((1 + sin(((double)now) / X_PERIOD * 2. * M_PI))/2.0) 
    * (st->sizex - st->s/2) -st->s/4  + MINX;
  st->y = ((1 + sin(((double)now) / Y_PERIOD * 2. * M_PI))/2.0) 
    * (st->sizey - st->s/2) -st->s/4  + MINY;
    
  if (!st->first_p)
    {
      /* limit change in x and y to buffer width */
      if ( st->x < (st->oldx - st->max_x_speed) ) st->x = st->oldx - st->max_x_speed;
      if ( st->x > (st->oldx + st->max_x_speed) ) st->x = st->oldx + st->max_x_speed;
      if ( st->y < (st->oldy - st->max_y_speed) ) st->y = st->oldy - st->max_y_speed;
      if ( st->y > (st->oldy + st->max_y_speed) ) st->y = st->oldy + st->max_y_speed;
    }

  if (! st->buffer)
    {
      XClearWindow (st->dpy, st->window);
      XSetClipOrigin(st->dpy, st->buffer_gc, st->x,st->y);
      XCopyArea(st->dpy, st->pm, st->window, st->buffer_gc, st->x, st->y, st->s, st->s, st->x, st->y);
    }
  else
    {
      /* clear buffer */
      XFillRectangle(st->dpy, st->buffer, st->buffer_gc, st->x, st->y, st->s, st->s);

      /* copy area of screen image (pm) to buffer
         Clip to a circle */
      XSetClipOrigin(st->dpy, st->buffer_gc, st->x,st->y);
      XCopyArea(st->dpy, st->pm, st->buffer, st->buffer_gc, st->x, st->y, st->s, st->s, st->x, st->y);

      /* copy buffer to screen (window) */
      XCopyArea(st->dpy, st->buffer, st->window, st->window_gc, st->x , st->y, st->s, st->s, st->x, st->y);
    }

#ifdef DEBUG
  /* draw a box around the buffer */
  XDrawRectangle(st->dpy, st->window, st->white_gc, st->x , st->y, st->s, st->s);
#endif

}
Ejemplo n.º 13
0
static void
reset_boxes (state *st)
{
  st->nboxes = 0;
  st->growing_p = True;
  st->color_horiz_p = random() & 1;

  if (st->done_once && st->colors)
    free_colors (st->xgwa.screen, st->xgwa.colormap, st->colors, st->ncolors);

  if (!st->done_once)
    {
      char *s = get_string_resource (st->dpy, "mode", "Mode");
      if (!s || !*s || !strcasecmp (s, "random"))
        st->mode = -1;
      else if (!strcasecmp (s, "squares") || !strcasecmp (s, "square"))
        st->mode = 0;
      else if (!strcasecmp (s, "circles") || !strcasecmp (s, "circle"))
        st->mode = 1;
      else
        {
          fprintf (stderr,
                   "%s: mode must be random, squares, or circles, not '%s'\n",
                   progname, s);
          exit (1);
        }
    }

  if (st->mode == -1)
    st->circles_p = random() & 1;
  else
    st->circles_p = (st->mode == 1);

  st->done_once = True;

  if (st->image || get_boolean_resource (st->dpy, "grab", "Boolean"))
    {
      if (st->image) XDestroyImage (st->image);
      st->image = 0;

      if (st->loading_pixmap) abort();
      if (st->img_loader) abort();
      if (!get_boolean_resource (st->dpy, "peek", "Boolean"))
        st->loading_pixmap = XCreatePixmap (st->dpy, st->window,
                                            st->xgwa.width, st->xgwa.height,
                                            st->xgwa.depth);

      XClearWindow (st->dpy, st->window);
      st->img_loader = load_image_async_simple (0, st->xgwa.screen, 
                                                st->window,
                                                (st->loading_pixmap
                                                 ? st->loading_pixmap
                                                 : st->window), 
                                                0, 0);
    }
  else
    {
      st->ncolors = get_integer_resource (st->dpy, "colors", "Colors");  /* re-get */
      if (st->ncolors < 1) st->ncolors = 1;
      make_smooth_colormap (st->xgwa.screen, st->xgwa.visual, st->xgwa.colormap,
                            st->colors, &st->ncolors, True, 0, False);
      if (st->ncolors < 1) abort();
      XClearWindow (st->dpy, st->window);
    }
}