Ejemplo n.º 1
0
ENTRYPOINT void 
init_voronoi (ModeInfo *mi)
{
  voronoi_configuration *vp;

  MI_INIT (mi, vps);

  vp = &vps[MI_SCREEN(mi)];

  vp->glx_context = init_GL(mi);

  vp->point_size = point_size;
  if (vp->point_size < 0) vp->point_size = 10;

  if (MI_WIDTH(mi) > 2560) vp->point_size *= 2;  /* Retina displays */

  vp->ncolors = 128;
  vp->colors = (XColor *) calloc (vp->ncolors, sizeof(XColor));
  make_smooth_colormap (0, 0, 0,
                        vp->colors, &vp->ncolors,
                        False, False, False);

  reshape_voronoi (mi, MI_WIDTH(mi), MI_HEIGHT(mi));

  vp->mode = MODE_ADDING;
  vp->adding = npoints * 2;
  vp->last_time = 0;
}
Ejemplo n.º 2
0
static void
new_knot (ModeInfo *mi)
{
  knot_configuration *bp = &bps[MI_SCREEN(mi)];
  int i;

  bp->clear_p = !!(random() % 15);

  bp->ncolors = 128;
  bp->colors = (XColor *) calloc(bp->ncolors, sizeof(XColor));
  make_smooth_colormap (0, 0, 0,
                        bp->colors, &bp->ncolors,
                        False, 0, False);

  for (i = 0; i < bp->ncolors; i++)
    {
      /* make colors twice as bright */
      bp->colors[i].red   = (bp->colors[i].red   >> 2) + 0x7FFF;
      bp->colors[i].green = (bp->colors[i].green >> 2) + 0x7FFF;
      bp->colors[i].blue  = (bp->colors[i].blue  >> 2) + 0x7FFF;
    }

  glNewList (bp->knot_list, GL_COMPILE);
  make_knot (mi);
  glEndList ();
}
Ejemplo n.º 3
0
ENTRYPOINT void 
init_voronoi (ModeInfo *mi)
{
  voronoi_configuration *vp;

  if (!vps) {
    vps = (voronoi_configuration *)
      calloc (MI_NUM_SCREENS(mi), sizeof (voronoi_configuration));
    if (!vps) {
      fprintf(stderr, "%s: out of memory\n", progname);
      exit(1);
    }

    vp = &vps[MI_SCREEN(mi)];
  }

  vp = &vps[MI_SCREEN(mi)];

  vp->glx_context = init_GL(mi);

  if (point_size < 0) point_size = 10;

  vp->ncolors = 128;
  vp->colors = (XColor *) calloc (vp->ncolors, sizeof(XColor));
  make_smooth_colormap (0, 0, 0,
                        vp->colors, &vp->ncolors,
                        False, False, False);

  reshape_voronoi (mi, MI_WIDTH(mi), MI_HEIGHT(mi));

  vp->mode = MODE_ADDING;
  vp->adding = npoints * 2;
  vp->last_time = 0;
}
Ejemplo n.º 4
0
ENTRYPOINT Bool
hexstrut_handle_event (ModeInfo *mi, XEvent *event)
{
  hexstrut_configuration *bp = &bps[MI_SCREEN(mi)];

  if (gltrackball_event_handler (event, bp->trackball,
                                 MI_WIDTH (mi), MI_HEIGHT (mi),
                                 &bp->button_down_p))
    return True;
  else if (event->xany.type == KeyPress)
    {
      KeySym keysym;
      char c = 0;
      XLookupString (&event->xkey, &c, 1, &keysym, 0);
      if (c == ' ' || c == '\t')
        {
          bp->ncolors = 64;
          make_smooth_colormap (0, 0, 0,
                                bp->colors, &bp->ncolors,
                                False, 0, False);
          return True;
        }
    }

  return False;
}
Ejemplo n.º 5
0
void
init_gasket(ModeInfo *mi)
{
  int           screen = MI_SCREEN(mi);
  gasketstruct *gp;

  if (gasket == NULL)
  {
    if ((gasket = (gasketstruct *) calloc(MI_NUM_SCREENS(mi),
					      sizeof (gasketstruct))) == NULL)
	return;
  }
  gp = &gasket[screen];

  gp->window = MI_WINDOW(mi);

  gp->rotx = FLOATRAND(1.0) * RANDSIGN();
  gp->roty = FLOATRAND(1.0) * RANDSIGN();
  gp->rotz = FLOATRAND(1.0) * RANDSIGN();

  /* bell curve from 0-1.5 degrees, avg 0.75 */
  gp->dx = (FLOATRAND(1) + FLOATRAND(1) + FLOATRAND(1)) / (360*2);
  gp->dy = (FLOATRAND(1) + FLOATRAND(1) + FLOATRAND(1)) / (360*2);
  gp->dz = (FLOATRAND(1) + FLOATRAND(1) + FLOATRAND(1)) / (360*2);

  gp->d_max = gp->dx * 2;

  gp->ddx = 0.00006 + FLOATRAND(0.00003);
  gp->ddy = 0.00006 + FLOATRAND(0.00003);
  gp->ddz = 0.00006 + FLOATRAND(0.00003);

  gp->ddx = 0.00001;
  gp->ddy = 0.00001;
  gp->ddz = 0.00001;

  intens_factor = intensity / 65536000.0;
  gp->ncolors = 255;
  gp->colors = (XColor *) calloc(gp->ncolors, sizeof(XColor));
  make_smooth_colormap (mi, None,
                        gp->colors, &gp->ncolors,
                        False, (Bool *) NULL);

  if ((gp->glx_context = init_GL(mi)) != NULL)
  {
    reshape_gasket(mi, MI_WIDTH(mi), MI_HEIGHT(mi));
    pinit(mi);
  }
  else
  {
    MI_CLEARWINDOW(mi);
  }
}
Ejemplo n.º 6
0
static void
reset_colors (ModeInfo *mi)
{
  cube_configuration *cc = &ccs[MI_SCREEN(mi)];
  make_smooth_colormap (0, 0, 0,
                        cc->colors, &cc->ncolors, 
                        False, 0, False);
  if (! MI_IS_WIREFRAME(mi))
    glClearColor (cc->colors[0].red   / 65536.0,
                  cc->colors[0].green / 65536.0,
                  cc->colors[0].blue  / 65536.0,
                  1);
}
Ejemplo n.º 7
0
static Bool
cwaves_event (Display *dpy, Window window, void *closure, XEvent *event)
{
  state *st = (state *) closure;
  if (screenhack_event_helper (dpy, window, event))
    {
      make_smooth_colormap (st->xgwa.screen, st->xgwa.visual,
                            st->xgwa.colormap,
                            st->colors, &st->ncolors,
                            True, 0, False);
      return True;
    }
  return False;
}
Ejemplo n.º 8
0
static void
new_cube_colors (ModeInfo *mi)
{
  cube_configuration *bp = &bps[MI_SCREEN(mi)];
  int i;
  bp->ncolors = 128;
  if (bp->colors) free (bp->colors);
  bp->colors = (XColor *) calloc(bp->ncolors, sizeof(XColor));
  make_smooth_colormap (0, 0, 0,
                        bp->colors, &bp->ncolors,
                        False, 0, False);
  for (i = 0; i < MI_COUNT(mi); i++)
    bp->subcubes[i].ccolor = random() % bp->ncolors;
}
Ejemplo n.º 9
0
ENTRYPOINT void
init_gasket(ModeInfo *mi)
{
  int           screen = MI_SCREEN(mi);
  gasketstruct *gp;

  if (gasket == NULL)
  {
    if ((gasket = (gasketstruct *) calloc(MI_NUM_SCREENS(mi),
					      sizeof (gasketstruct))) == NULL)
	return;
  }
  gp = &gasket[screen];

  gp->window = MI_WINDOW(mi);

  {
    double spin_speed   = 1.0;
    double wander_speed = 0.03;
    gp->rot = make_rotator (do_spin ? spin_speed : 0,
                            do_spin ? spin_speed : 0,
                            do_spin ? spin_speed : 0,
                            1.0,
                            do_wander ? wander_speed : 0,
                            True);
    gp->trackball = gltrackball_init ();
  }

  gp->ncolors = 255;
  gp->colors = (XColor *) calloc(gp->ncolors, sizeof(XColor));
  make_smooth_colormap (0, 0, 0,
                        gp->colors, &gp->ncolors,
                        False, 0, False);
  gp->ccolor0 = 0;
  gp->ccolor1 = gp->ncolors * 0.25;
  gp->ccolor2 = gp->ncolors * 0.5;
  gp->ccolor3 = gp->ncolors * 0.75;
  gp->tick = 999999;

  if ((gp->glx_context = init_GL(mi)) != NULL)
  {
    reshape_gasket(mi, MI_WIDTH(mi), MI_HEIGHT(mi));
    pinit(mi);
  }
  else
  {
    MI_CLEARWINDOW(mi);
  }
}
Ejemplo n.º 10
0
ENTRYPOINT void 
init_hexstrut (ModeInfo *mi)
{
  hexstrut_configuration *bp;

  MI_INIT (mi, bps, free_hexstrut);

  bp = &bps[MI_SCREEN(mi)];

  bp->glx_context = init_GL(mi);

  reshape_hexstrut (mi, MI_WIDTH(mi), MI_HEIGHT(mi));

  {
    double spin_speed   = 0.002;
    double wander_speed = 0.003;
    double spin_accel   = 1.0;

    bp->rot = make_rotator (do_spin ? spin_speed : 0,
                            do_spin ? spin_speed : 0,
                            do_spin ? spin_speed : 0,
                            spin_accel,
                            do_wander ? wander_speed : 0,
                            False);
    bp->trackball = gltrackball_init (True);
  }


  /* Let's tilt the scene a little. */
  gltrackball_reset (bp->trackball,
                     -0.4 + frand(0.8),
                     -0.4 + frand(0.8));

  if (thickness < 0.05) thickness = 0.05;
  if (thickness < 0.05) MI_IS_WIREFRAME(mi) = True;
  if (thickness > 1.7) thickness = 1.7;
  if (speed > 2) speed = 2;

  bp->ncolors = 64;
  bp->colors = (XColor *) calloc(bp->ncolors, sizeof(XColor));
  make_smooth_colormap (0, 0, 0,
                        bp->colors, &bp->ncolors,
                        False, 0, False);

  make_plane (mi);
}
Ejemplo n.º 11
0
/* Construct and return in COLORS and N_COLORS a new set of colors,
   depending on the resource settings.  */
static void
setup_colormap (struct state *st, XColor **colors, int *n_colors)
{
  Bool			writable;
  char const *		color_scheme;

  /* Make a colormap */
  *n_colors = get_integer_resource (st->dpy, "ncolors", "Integer");
  if (*n_colors < 3)
    *n_colors = 3;
  
  *colors = (XColor *) calloc (sizeof(XColor), *n_colors);
  if (!*colors)
    {
      fprintf (stderr, "%s:%d: can't allocate memory for colors\n",
	       __FILE__, __LINE__);
      return;
    }

  writable = False;
  color_scheme = get_string_resource (st->dpy, "colorscheme", "ColorScheme");
  
  if (!strcmp (color_scheme, "random"))
    {
      make_random_colormap (st->wattr.screen, st->wattr.visual,
			    st->wattr.colormap,
			    *colors, n_colors,
			    True, True, &writable, True);
    }
  else if (!strcmp (color_scheme, "smooth"))
    {
      make_smooth_colormap (st->wattr.screen, st->wattr.visual,
			    st->wattr.colormap,
			    *colors, n_colors,
			    True, &writable, True);
    }
  else 
    {
      make_uniform_colormap (st->wattr.screen, st->wattr.visual,
			     st->wattr.colormap,
			     *colors, n_colors, True,
			     &writable, True);
    }
}
Ejemplo n.º 12
0
static void
init_colors (ModeInfo *mi)
{
  spheremonics_configuration *cc = &ccs[MI_SCREEN(mi)];
  int i;
  cc->ncolors = cc->resolution;
  cc->colors = (XColor *) calloc(cc->ncolors, sizeof(XColor));
  make_smooth_colormap (0, 0, 0,
                        cc->colors, &cc->ncolors, 
                        False, 0, False);

  /* brighter colors, please... */
  for (i = 0; i < cc->ncolors; i++)
    {
      cc->colors[i].red   = (cc->colors[i].red   / 2) + 32767;
      cc->colors[i].green = (cc->colors[i].green / 2) + 32767;
      cc->colors[i].blue  = (cc->colors[i].blue  / 2) + 32767;
    }
}
Ejemplo n.º 13
0
static void *
cloudlife_init (Display *dpy, Window window)
{
  struct state *st = (struct state *) calloc (1, sizeof(*st));
    Bool tmp = True;

    st->dpy = dpy;
    st->window = window;
    st->field = init_field(st);

#ifdef TIME_ME
    st->start_time = time(NULL);
#endif

    st->cycle_delay = get_integer_resource(st->dpy, "cycleDelay", "Integer");
    st->cycle_colors = get_integer_resource(st->dpy, "cycleColors", "Integer");
    st->ncolors = get_integer_resource(st->dpy, "ncolors", "Integer");
    st->density = (get_integer_resource(st->dpy, "initialDensity", "Integer") 
                  % 100 * 256)/100;

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

    if (st->cycle_colors) {
        st->colors = (XColor *) xrealloc(st->colors, sizeof(XColor) * (st->ncolors+1));
        make_smooth_colormap (st->xgwa.screen, st->xgwa.visual,
                              st->xgwa.colormap, st->colors, &st->ncolors,
                              True, &tmp, True);
    }

    st->gcv.foreground = get_pixel_resource(st->dpy, st->xgwa.colormap,
                                        "foreground", "Foreground");
    st->fgc = XCreateGC(st->dpy, st->window, GCForeground, &st->gcv);

    st->gcv.foreground = get_pixel_resource(st->dpy, st->xgwa.colormap,
                                        "background", "Background");
    st->bgc = XCreateGC(st->dpy, st->window, GCForeground, &st->gcv);

    return st;
}
Ejemplo n.º 14
0
static void *
cwaves_init (Display *dpy, Window window)
{
  int i;
  XGCValues gcv;
  state *st = (state *) calloc (1, sizeof (*st));

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

  st->debug_p = get_boolean_resource (dpy, "debug", "Boolean");
  st->scale = get_integer_resource (dpy, "scale", "Integer");
  if (st->scale <= 0) st->scale = 1;
  st->ncolors = get_integer_resource (dpy, "ncolors", "Integer");
  if (st->ncolors < 4) st->ncolors = 4;
  st->colors = (XColor *) malloc (sizeof(*st->colors) * (st->ncolors+1));
  make_smooth_colormap (st->xgwa.screen, st->xgwa.visual, st->xgwa.colormap,
                        st->colors, &st->ncolors,
                        True, 0, False);

  st->gc = XCreateGC (st->dpy, st->window, 0, &gcv);
  st->delay = get_integer_resource (dpy, "delay", "Integer");

  st->nwaves  = get_integer_resource (dpy, "nwaves", "Integer");
  st->waves  = (wave *) calloc (st->nwaves,  sizeof(*st->waves));

  for (i = 0; i < st->nwaves; i++)
    {
      st->waves[i].scale  = frand(0.03) + 0.005;
      st->waves[i].offset = frand(M_PI);
      st->waves[i].delta  = (BELLRAND(2)-1) / 15.0;
    }

  return st;
}
Ejemplo n.º 15
0
void
init_toneclock(ModeInfo * mi)
{
	Display    *display = MI_DISPLAY(mi);
	Window      window = MI_WINDOW(mi);
	int         i, size_hour, istart;
	toneclockstruct *tclock;

/* initialize */
	if (toneclocks == NULL) {
		if ((toneclocks = (toneclockstruct *) calloc(MI_NUM_SCREENS(mi),
				sizeof (toneclockstruct))) == NULL)
			return;
	}
	tclock = &toneclocks[MI_SCREEN(mi)];
	tclock->mi = mi;

	if (tclock->gc == None) {
		if (MI_IS_INSTALL(mi) && MI_NPIXELS(mi) > 2) {
			XColor      color;

#ifndef STANDALONE
			tclock->fg = MI_FG_PIXEL(mi);
			tclock->bg = MI_BG_PIXEL(mi);
#endif
			tclock->blackpixel = MI_BLACK_PIXEL(mi);
			tclock->whitepixel = MI_WHITE_PIXEL(mi);
			if ((tclock->cmap = XCreateColormap(display, window,
					MI_VISUAL(mi), AllocNone)) == None) {
				free_toneclock(display, tclock);
				return;
			}
			XSetWindowColormap(display, window, tclock->cmap);
			(void) XParseColor(display, tclock->cmap, "black", &color);
			(void) XAllocColor(display, tclock->cmap, &color);
			MI_BLACK_PIXEL(mi) = color.pixel;
			(void) XParseColor(display, tclock->cmap, "white", &color);
			(void) XAllocColor(display, tclock->cmap, &color);
			MI_WHITE_PIXEL(mi) = color.pixel;
#ifndef STANDALONE
			(void) XParseColor(display, tclock->cmap, background, &color);
			(void) XAllocColor(display, tclock->cmap, &color);
			MI_BG_PIXEL(mi) = color.pixel;
			(void) XParseColor(display, tclock->cmap, foreground, &color);
			(void) XAllocColor(display, tclock->cmap, &color);
			MI_FG_PIXEL(mi) = color.pixel;
#endif
			tclock->colors = (XColor *) NULL;
			tclock->ncolors = 0;
		}
		if ((tclock->gc = XCreateGC(display, MI_WINDOW(mi),
			     (unsigned long) 0, (XGCValues *) NULL)) == None) {
			free_toneclock(display, tclock);
			return;
		}
	}
/* Clear Display */
	MI_CLEARWINDOW(mi);
	tclock->painted = False;
	XSetFunction(display, tclock->gc, GXxor);


/*Set up toneclock data */
	if (MI_IS_FULLRANDOM(mi)) {
	   if (NRAND(10))
	     tclock->original = False;
	   else
	     tclock->original = True;
	} else {
	   tclock->original = original;
	}
	tclock->direction = (LRAND() & 1) ? 1 : -1;
	tclock->win_width = MI_WIDTH(mi);
	tclock->win_height = MI_HEIGHT(mi);
	if (tclock->hour != NULL)
		free_hour(tclock);
	if ( tclock->original )
          {
	     tclock->num_hour = 12;
	  }
        else
          {
	     tclock->num_hour = MI_COUNT(mi);
	  }
        tclock->x0 = tclock->win_width / 2;
        tclock->y0 = tclock->win_height / 2;
	if (tclock->num_hour == 0) {
		tclock->num_hour = DEF_NUM_hour;
	} else if (tclock->num_hour < 0) {
		tclock->num_hour = NRAND(-tclock->num_hour) + 1;
	}
        if ( tclock->num_hour < 12 )
          istart = NRAND( 12 - tclock->num_hour );
        else
          istart = 0;
	if ((tclock->hour = (toneclockhour *) calloc(tclock->num_hour,
			sizeof (toneclockhour))) == NULL) {
		free_toneclock(display, tclock);
		return;
	}
	if (MI_IS_INSTALL(mi) && MI_NPIXELS(mi) > 2) {
/* Set up colour map */
		if (tclock->colors != NULL) {
			if (tclock->ncolors && !tclock->no_colors)
				free_colors(display, tclock->cmap, tclock->colors, tclock->ncolors);
			free(tclock->colors);
			tclock->colors = (XColor *) NULL;
		}
		tclock->ncolors = MI_NCOLORS(mi);
		if (tclock->ncolors < 2)
			tclock->ncolors = 2;
		if (tclock->ncolors <= 2)
			tclock->mono_p = True;
		else
			tclock->mono_p = False;

		if (tclock->mono_p)
			tclock->colors = (XColor *) NULL;
		else
			if ((tclock->colors = (XColor *) malloc(sizeof (*tclock->colors) *
					(tclock->ncolors + 1))) == NULL) {
				free_toneclock(display, tclock);
				return;
			}
		tclock->cycle_p = has_writable_cells(mi);
		if (tclock->cycle_p) {
			if (MI_IS_FULLRANDOM(mi)) {
				if (!NRAND(8))
					tclock->cycle_p = False;
				else
					tclock->cycle_p = True;
			} else {
				tclock->cycle_p = cycle_p;
			}
		}
		if (!tclock->mono_p) {
			if (!(LRAND() % 10))
				make_random_colormap(
#ifdef STANDALONE
						MI_DISPLAY(mi), MI_WINDOW(mi),
#else
            mi,
#endif
						tclock->cmap, tclock->colors, &tclock->ncolors,
						True, True, &tclock->cycle_p);
			else if (!(LRAND() % 2))
				make_uniform_colormap(
#ifdef STANDALONE
						MI_DISPLAY(mi), MI_WINDOW(mi),
#else
            mi,
#endif
                  tclock->cmap, tclock->colors, &tclock->ncolors,
						      True, &tclock->cycle_p);
			else
				make_smooth_colormap(
#ifdef STANDALONE
						MI_DISPLAY(mi), MI_WINDOW(mi),
#else
            mi,
#endif
                 tclock->cmap, tclock->colors, &tclock->ncolors,
						     True, &tclock->cycle_p);
		}
		XInstallColormap(display, tclock->cmap);
		if (tclock->ncolors < 2) {
			tclock->ncolors = 2;
			tclock->no_colors = True;
		} else
			tclock->no_colors = False;
		if (tclock->ncolors <= 2)
			tclock->mono_p = True;

		if (tclock->mono_p)
			tclock->cycle_p = False;

	}
#ifndef NO_DBUF
	if (tclock->dbuf != None)
		XFreePixmap(display, tclock->dbuf);
	tclock->dbuf = XCreatePixmap(display, window,
		tclock->win_width,
		tclock->win_height,
		MI_DEPTH(mi));
	/* Allocation checked */
	if (tclock->dbuf != None) {
		XGCValues   gcv;

		gcv.foreground = 0;
		gcv.background = 0;
		gcv.graphics_exposures = False;
		gcv.function = GXcopy;

		if (tclock->dbuf_gc != None)
			XFreeGC(display, tclock->dbuf_gc);
		if ((tclock->dbuf_gc = XCreateGC(display, (Drawable) tclock->dbuf,
			GCForeground | GCBackground | GCGraphicsExposures | GCFunction,
				&gcv)) == None) {
			XFreePixmap(display, tclock->dbuf);
			tclock->dbuf = None;
		} else {
			XFillRectangle(display, (Drawable) tclock->dbuf, tclock->dbuf_gc,
				0, 0, tclock->win_width, tclock->win_height);
			/*XSetBackground(display, MI_GC(mi), MI_BLACK_PIXEL(mi));
			XSetFunction(display, MI_GC(mi), GXcopy);*/
		}
	}
#endif
	tclock->angle = NRAND(360) * PI_RAD;
	tclock->velocity = (NRAND(7) - 3) * PI_RAD;
	size_hour = MIN( tclock->win_width , tclock->win_height) / 3;
   tclock->pulsating = False;
   tclock->moving = False;
   tclock->anglex = 0.0;
   tclock->angley = 0.0;
   tclock->fill = 0;
   tclock->radius = size_hour;
   tclock->max_radius =0.0;
   if ( ( !tclock->original && NRAND( 15 ) == 3 ) || tclock->num_hour > 12 )
     tclock->randomhour = True;
   else
     tclock->randomhour = False;
   if ( !tclock->original && tclock->win_width > 20 )
     {
	if ( abs( MI_SIZE(mi) ) > size_hour ) {
	   if ( MI_SIZE( mi ) < 0 )
	     {
		size_hour = -size_hour;
	     }
	}
	else
	  {
	     size_hour = MI_SIZE(mi);
          }
    	if ( size_hour < 0 )
          {
	     tclock->radius = MIN(NRAND( size_hour - 10) + 10,
		tclock->radius );
          }
        else
          {
  	     tclock->radius = MIN( size_hour , tclock->radius );
          }
	if ( MI_IS_FULLRANDOM( mi ) )
	  {
	     if ( NRAND(2) )
	       tclock->pulsating = True;
	     else
	       tclock->pulsating = False;
	     tclock->fill = NRAND( 101 );
	  }
	else
	  {
	     tclock->pulsating = pulsating;
	     tclock->fill = fill;
	  }
     }
   tclock->phase = 0.0;
   if ( tclock->pulsating )
	tclock->ph_vel = (NRAND(7) - 3) * PI_RAD;
   for (i = 0; i < tclock->num_hour; i++) {
		toneclockhour *hour0;

		hour0 = &tclock->hour[i];
		if (MI_IS_INSTALL(mi) && MI_NPIXELS(mi) > 2) {
			if (tclock->ncolors > 2)
				hour0->colour = NRAND(tclock->ncolors - 2) + 2;
			else
				hour0->colour = 1;	/* Just in case */
			XSetForeground(display, tclock->gc, tclock->colors[hour0->colour].pixel);
		} else {
			if (MI_NPIXELS(mi) > 2)
				hour0->colour = MI_PIXEL(mi, NRAND(MI_NPIXELS(mi)));
			else
				hour0->colour = 1;	/*Xor'red so WHITE may not be appropriate */
			XSetForeground(display, tclock->gc, hour0->colour);
		}
		hour0->angle = NRAND(360) * PI_RAD;
		hour0->velocity = (NRAND(7) - 3) * PI_RAD;
	        hour0->radius = tclock->radius / 5.0;
      		tclock->max_radius = MAX( tclock->max_radius , hour0->radius );
	        hour0->num_point = 12;
		hour0->num_point1 = 16;
                if ( tclock->randomhour )
	          {
		     int j;

		     hour0->point_numbers = tclock->hexadecimal_clock + i *
			     hour0->num_point1;
		     if ( NRAND( 14 ) == 4 )
		       {
			  for (j = 0; j < ( hour0->num_point1 / 4 ) - 1 ; j++)
			    {
			       hour0->point_numbers[ j * 4 ] = NRAND( 12 ) + 1;
			       hour0->point_numbers[ j * 4 + 1 ] = NRAND( 12 )
				 + 1;
			       hour0->point_numbers[ j * 4 + 2 ] = NRAND( 12 )
				 + 1;
			       hour0->point_numbers[ j * 4 + 3 ] = NRAND( 12 )
				 + 1;
			    }
			  hour0->point_numbers[ hour0->num_point1 / 4 ] = 1;
			  hour0->point_numbers[ 1 + hour0->num_point1 / 4 ] =
			    1;
			  hour0->point_numbers[ 2 + hour0->num_point1 / 4 ] =
			    1;
			  hour0->point_numbers[ 3 + hour0->num_point1 / 4 ] =
			    1;
		       }
		     else
		       {
			  for (j = 0; j < hour0->num_point1 / 4 ; j++)
			    {
			       hour0->point_numbers[ j * 4 ] = NRAND( 12 ) + 1;
			       hour0->point_numbers[ j * 4 + 1 ] =
				 hour0->point_numbers[ j * 4 ];
			       hour0->point_numbers[ j * 4 + 2 ] = NRAND( 12 )
				 + 1;
			       hour0->point_numbers[ j * 4 + 3 ] = NRAND( 12 )
				 + 1;
			    }
		       }
	          }
                else
	          hour0->point_numbers = original_clock[i+istart];
		if ( NRAND( 100 ) >= tclock->fill )
			hour0->draw = True;
		else
			hour0->draw = False;
#ifdef NO_DBUF
		{
		  int x0 , y0;

		  x0 = (int) (tclock->radius * sin( -tclock->angle - PI_RAD * i *
			360.0 / tclock->num_hour ) *
			0.5 * ( 1 + cos( tclock->phase ) ) + tclock->x0 +
			tclock->a_x * sin( tclock->anglex ) );
		  y0 = (int) (tclock->radius * cos( -tclock->angle - PI_RAD * i *
			360.0 / tclock->num_hour ) *
			0.5 * ( 1 + cos( tclock->phase ) ) + tclock->y0 +
			tclock->a_y * sin( tclock->angley ) );
	 	  toneclock_drawhour(mi , hour0 , x0 , y0 );
		}
#endif
	}
   tclock->a_x = 0;
   tclock->a_y = 0;
   if ( !tclock->original && tclock->win_width > 20 )
     {
	if ( tclock->radius < MIN( tclock->win_width , tclock->win_height) /
	     4 )
	  {
	     if ( MI_IS_FULLRANDOM( mi ) )
	       {
		  if ( NRAND(2) )
		    tclock->moving = True;
	       }
	     else
	       {
		    tclock->moving = move_clock;
	       }
	     if ( tclock->moving )
	       {
		  tclock->a_x = (int) floor( ( tclock->win_width / 2 ) - 1.05 *
					( tclock->radius + tclock->max_radius )
					);
		  tclock->a_y = (int) floor( ( tclock->win_height / 2 ) - 1.05 *
					( tclock->radius + tclock->max_radius )
					);
		  tclock->vx = (NRAND(15) - 7) * PI_RAD;
		  tclock->vy = (NRAND(15) - 7) * PI_RAD;
	       }
	  }
     }
	XFlush(display);
	XSetFunction(display, tclock->gc, GXcopy);
}
Ejemplo n.º 16
0
ENTRYPOINT void 
init_ball (ModeInfo *mi)
{
  ball_configuration *bp;
  int wire = MI_IS_WIREFRAME(mi);

  MI_INIT (mi, bps);
  bp = &bps[MI_SCREEN(mi)];

  bp->glx_context = init_GL(mi);

  reshape_ball (mi, MI_WIDTH(mi), MI_HEIGHT(mi));

  if (!wire)
    {
      GLfloat pos[4] = {1.0, 1.0, 1.0, 0.0};
      GLfloat amb[4] = {0.0, 0.0, 0.0, 1.0};
      GLfloat dif[4] = {1.0, 1.0, 1.0, 1.0};
      GLfloat spc[4] = {0.0, 1.0, 1.0, 1.0};

      glEnable(GL_LIGHTING);
      glEnable(GL_LIGHT0);
      glEnable(GL_DEPTH_TEST);
      glEnable(GL_CULL_FACE);

      glLightfv(GL_LIGHT0, GL_POSITION, pos);
      glLightfv(GL_LIGHT0, GL_AMBIENT,  amb);
      glLightfv(GL_LIGHT0, GL_DIFFUSE,  dif);
      glLightfv(GL_LIGHT0, GL_SPECULAR, spc);
    }

  {
    double spin_speed   = 10.0;
    double wander_speed = 0.12;
    double spin_accel   = 2.0;

    bp->rot = make_rotator (do_spin ? spin_speed : 0,
                            do_spin ? spin_speed : 0,
                            do_spin ? spin_speed : 0,
                            spin_accel,
                            do_wander ? wander_speed : 0,
                            True);
    bp->trackball = gltrackball_init (True);
  }

  bp->ncolors = 128;
  bp->colors = (XColor *) calloc(bp->ncolors, sizeof(XColor));
  make_smooth_colormap (0, 0, 0,
                        bp->colors, &bp->ncolors,
                        False, 0, False);

  bp->spikes = (int *) calloc(MI_COUNT(mi), sizeof(*bp->spikes) * 2);

  bp->ball_list = glGenLists (1);
  bp->spike_list = glGenLists (1);

  glNewList (bp->ball_list, GL_COMPILE);
  unit_sphere (SPHERE_STACKS, SPHERE_SLICES, wire);
  glEndList ();

  glNewList (bp->spike_list, GL_COMPILE);
  cone (0, 0, 0,
        0, 1, 0,
        1, 0, SPIKE_FACES, SMOOTH_SPIKES, False, wire);
  glEndList ();

  randomize_spikes (mi);
}
Ejemplo n.º 17
0
ENTRYPOINT void 
init_hypnowheel (ModeInfo *mi)
{
  hypnowheel_configuration *bp;
  int wire = MI_IS_WIREFRAME(mi);
  int i;

  if (!bps) {
    bps = (hypnowheel_configuration *)
      calloc (MI_NUM_SCREENS(mi), sizeof (hypnowheel_configuration));
    if (!bps) {
      fprintf(stderr, "%s: out of memory\n", progname);
      exit(1);
    }
  }

  bp = &bps[MI_SCREEN(mi)];

  bp->glx_context = init_GL(mi);

  reshape_hypnowheel (mi, MI_WIDTH(mi), MI_HEIGHT(mi));

  bp->rot = make_rotator (0, 0, 0, 0, speed * 0.0025, False);

  bp->ncolors = 1024;
  bp->colors = (XColor *) calloc(bp->ncolors, sizeof(XColor));
  make_smooth_colormap (0, 0, 0,
                        bp->colors, &bp->ncolors,
                        False, 0, False);

  if (MI_COUNT(mi) < 2) MI_COUNT(mi) = 2;
  if (nlayers < 1) nlayers = 1;
  bp->discs = (disc *) calloc (nlayers, sizeof (disc));

  for (i = 0; i < nlayers; i++)
    {
      double spin_speed   = speed * 0.2;
      double wander_speed = speed * 0.0012;
      double spin_accel   = 0.2;

      bp->discs[i].twist = 0;
      bp->discs[i].alpha = 1;
      bp->discs[i].color = i * bp->ncolors / nlayers;

      spin_speed   += frand (spin_speed   / 5);
      wander_speed += frand (wander_speed * 3);

      bp->discs[i].rot = make_rotator (spin_speed, spin_speed, spin_speed,
                                       spin_accel,
                                       (do_wander ? wander_speed : 0),
                                       True);
    }

  glDisable (GL_LIGHTING);
  glDisable (GL_DEPTH_TEST);
  glDepthMask (GL_FALSE);
  glDisable (GL_CULL_FACE);

  if (! wire)
    {
      glEnable (GL_BLEND);
      glBlendFunc (GL_ONE, GL_ONE);
    }
}
Ejemplo n.º 18
0
void
init_mandelbrot(ModeInfo * mi)
{
	Display    *display = MI_DISPLAY(mi);
	Window      window = MI_WINDOW(mi);
	mandelstruct *mp;

	if (mandels == NULL) {
		if ((mandels = (mandelstruct *) calloc(MI_NUM_SCREENS(mi),
					     sizeof (mandelstruct))) == NULL)
			return;
	}
	mp = &mandels[MI_SCREEN(mi)];
	mp->mi = mi;

	mp->screen_width = MI_WIDTH(mi);
	mp->screen_height = MI_HEIGHT(mi);
	mp->backwards = (Bool) (LRAND() & 1);
	if (mp->backwards)
		mp->column = mp->screen_width - 1;
	else
		mp->column = 0;
	mp->power = NRAND(3) + MINPOWER;
	mp->counter = 0;

	MI_CLEARWINDOW(mi);

	if (MI_IS_FULLRANDOM(mi)) {
		mp->binary = (Bool) (LRAND() & 1);
		mp->dem = (Bool) (LRAND() & 1);
		mp->interior = NRAND(interior_size);
#if 0
	/* too slow */
	  mp->pow = (NRAND(5) == 0);
	  mp->sin = (NRAND(5) == 0);
#endif
	} else {
	  mp->binary = binary_p;
	  mp->dem = dem_p;
	  if (index_p) {
		  mp->interior = INDEX;
	  } else if(alpha_p) {
		  mp->interior = ALPHA;
	  } else if(lyap_p) {
		  mp->interior = LYAPUNOV;
	  } else {
		  mp->interior = NONE;
	  }
	  mp->pow = pow_p;
	  mp->sin = sin_p;
	}

	mp->reptop = 300;

	/* these could be tuned a little closer, but the selection
	** process throws out the chaf anyway, it just takes slightly
	** longer
	*/
	mp->extreme_ul.real = -3.0;
	mp->extreme_ul.imag = -3.0;
	mp->extreme_lr.real = 3.0;
	mp->extreme_lr.imag = 3.0;

	if (!mp->gc) {
		if (MI_IS_INSTALL(mi) && MI_NPIXELS(mi) > 2) {
			XColor      color;

#ifndef STANDALONE
			mp->fg = MI_FG_PIXEL(mi);
			mp->bg = MI_BG_PIXEL(mi);
#endif
			mp->blackpixel = MI_BLACK_PIXEL(mi);
			mp->whitepixel = MI_WHITE_PIXEL(mi);
			if ((mp->cmap = XCreateColormap(display, window,
					MI_VISUAL(mi), AllocNone)) == None) {
				free_mandelbrot(display, mp);
				return;
			}
			XSetWindowColormap(display, window, mp->cmap);
			(void) XParseColor(display, mp->cmap, "black", &color);
			(void) XAllocColor(display, mp->cmap, &color);
			MI_BLACK_PIXEL(mi) = color.pixel;
			(void) XParseColor(display, mp->cmap, "white", &color);
			(void) XAllocColor(display, mp->cmap, &color);
			MI_WHITE_PIXEL(mi) = color.pixel;
#ifndef STANDALONE
			(void) XParseColor(display, mp->cmap, background, &color);
			(void) XAllocColor(display, mp->cmap, &color);
			MI_BG_PIXEL(mi) = color.pixel;
			(void) XParseColor(display, mp->cmap, foreground, &color);
			(void) XAllocColor(display, mp->cmap, &color);
			MI_FG_PIXEL(mi) = color.pixel;
#endif
			mp->colors = (XColor *) NULL;
			mp->ncolors = 0;
		}
		if ((mp->gc = XCreateGC(display, MI_WINDOW(mi),
			     (unsigned long) 0, (XGCValues *) NULL)) == None) {
			free_mandelbrot(display, mp);
			return;
		}
	}
	MI_CLEARWINDOW(mi);

  /* Set up colour map */
  mp->direction = (LRAND() & 1) ? 1 : -1;
  if (MI_IS_INSTALL(mi) && MI_NPIXELS(mi) > 2) {
    if (mp->colors != NULL) {
      if (mp->ncolors && !mp->no_colors)
        free_colors(display, mp->cmap, mp->colors, mp->ncolors);
      free(mp->colors);
      mp->colors = (XColor *) NULL;
    }
    mp->ncolors = MI_NCOLORS(mi);
    if (mp->ncolors < 2)
      mp->ncolors = 2;
    if (mp->ncolors <= 2)
      mp->mono_p = True;
    else
      mp->mono_p = False;

    if (mp->mono_p)
      mp->colors = (XColor *) NULL;
    else
      if ((mp->colors = (XColor *) malloc(sizeof (*mp->colors) *
          (mp->ncolors + 1))) == NULL) {
        free_mandelbrot(display, mp);
        return;
      }
    mp->cycle_p = has_writable_cells(mi);
    if (mp->cycle_p) {
      if (MI_IS_FULLRANDOM(mi)) {
        if (!NRAND(8))
          mp->cycle_p = False;
        else
          mp->cycle_p = True;
      } else {
        mp->cycle_p = cycle_p;
      }
    }
    if (!mp->mono_p) {
      if (!(LRAND() % 10))
        make_random_colormap(
#if STANDALONE
            display, MI_WINDOW(mi),
#else
            mi,
#endif
              mp->cmap, mp->colors, &mp->ncolors,
              True, True, &mp->cycle_p);
      else if (!(LRAND() % 2))
        make_uniform_colormap(
#if STANDALONE
            display, MI_WINDOW(mi),
#else
            mi,
#endif
                  mp->cmap, mp->colors, &mp->ncolors,
                  True, &mp->cycle_p);
      else
        make_smooth_colormap(
#if STANDALONE
            display, MI_WINDOW(mi),
#else
            mi,
#endif
                 mp->cmap, mp->colors, &mp->ncolors,
                 True, &mp->cycle_p);
    }
    XInstallColormap(display, mp->cmap);
    if (mp->ncolors < 2) {
      mp->ncolors = 2;
      mp->no_colors = True;
    } else
      mp->no_colors = False;
    if (mp->ncolors <= 2)
      mp->mono_p = True;

    if (mp->mono_p)
      mp->cycle_p = False;

  }
  if (MI_IS_INSTALL(mi) && MI_NPIXELS(mi) > 2) {
                if (mp->mono_p) {
			mp->cur_color = MI_BLACK_PIXEL(mi);
		}
  }
	Select(&mp->extreme_ul,&mp->extreme_lr,
		mp->screen_width,mp->screen_height,
		(int) mp->power,mp->reptop, mp->pow, mp->sin,
		&mp->ul,&mp->lr);
}
Ejemplo n.º 19
0
ENTRYPOINT void 
init_sponge (ModeInfo *mi)
{
  sponge_configuration *sp;
  int wire = MI_IS_WIREFRAME(mi);

  if (!sps) {
    sps = (sponge_configuration *)
      calloc (MI_NUM_SCREENS(mi), sizeof (sponge_configuration));
    if (!sps) {
      fprintf(stderr, "%s: out of memory\n", progname);
      exit(1);
    }
  }

  sp = &sps[MI_SCREEN(mi)];

  if ((sp->glx_context = init_GL(mi)) != NULL) {
    reshape_sponge (mi, MI_WIDTH(mi), MI_HEIGHT(mi));
  }

  if (!wire)
    {
      static const GLfloat pos0[4] = {-1.0, -1.0, 1.0, 0.1};
      static const GLfloat pos1[4] = { 1.0, -0.2, 0.2, 0.1};
      static const GLfloat dif0[4] = {1.0, 1.0, 1.0, 1.0};
      static const GLfloat dif1[4] = {1.0, 1.0, 1.0, 1.0};

      glLightfv(GL_LIGHT0, GL_POSITION, pos0);
      glLightfv(GL_LIGHT1, GL_POSITION, pos1);
      glLightfv(GL_LIGHT0, GL_DIFFUSE, dif0);
      glLightfv(GL_LIGHT1, GL_DIFFUSE, dif1);

      glEnable(GL_LIGHTING);
      glEnable(GL_LIGHT0);
      glEnable(GL_LIGHT1);

      glEnable(GL_DEPTH_TEST);
      glEnable(GL_NORMALIZE);

      glShadeModel(GL_SMOOTH);
    }

  {
    double spin_speed   = 1.0;
    double wander_speed = 0.03;
    sp->rot = make_rotator (do_spin ? spin_speed : 0,
                            do_spin ? spin_speed : 0,
                            do_spin ? spin_speed : 0,
                            1.0,
                            do_wander ? wander_speed : 0,
                            True);
    sp->trackball = gltrackball_init (True);
  }

  sp->ncolors = 128;
  sp->colors = (XColor *) calloc(sp->ncolors, sizeof(XColor));
  make_smooth_colormap (0, 0, 0,
                        sp->colors, &sp->ncolors,
                        False, 0, False);
  sp->ccolor0 = 0;
  sp->ccolor1 = sp->ncolors / 3;
  sp->ccolor2 = sp->ccolor1 * 2;

  sp->sponge_list0 = glGenLists (1);
  sp->sponge_list1 = glGenLists (1);
  sp->sponge_list2 = glGenLists (1);

  sp->draw_tick = 9999999;
}
Ejemplo n.º 20
0
BOOL InitPixelFormat(SCREENSAVER *ss)
{
    ModeInfo *mi;
    int i;

    ss->modeinfo.gc = XCreateGC(ss->hdc, 0, 0, NULL);
    assert(ss->modeinfo.gc != NULL);

    if (hack_ncolors <= 0)
        hack_ncolors = 64;
    else if (hack_ncolors > MAX_COLORCELLS)
        hack_ncolors = MAX_COLORCELLS;

    mi = &ss->modeinfo;

	mi->install_p = fChildPreview;

    mi->writable_p = True;

    mi->black_pixel = 0;
    mi->white_pixel = 255;
    mi->npixels = hack_ncolors;
    mi->colors = NULL;
    mi->pixels = NULL;

    mi->threed = False;
    mi->threed_delta = 1.5;
	mi->threed_right_color = load_color(NULL, 0, "red");
    mi->threed_left_color = load_color(NULL, 0, "blue");
    mi->threed_both_color = load_color(NULL, 0, "magenta");
    mi->threed_none_color = load_color(NULL, 0, "black");

    if (hack_ncolors_enabled)
    {
        mi->colors = (XColor *) calloc(mi->npixels, sizeof(*mi->colors));
        if (mi->colors == NULL)
            return FALSE;

        switch (hack_color_scheme)
        {
        case color_scheme_uniform:
            make_uniform_colormap(mi->xgwa.screen, mi->xgwa.visual,
                mi->xgwa.colormap,
                mi->colors, &mi->npixels,
                True, &mi->writable_p, True);
            break;

        case color_scheme_smooth:
            make_smooth_colormap(mi->xgwa.screen, mi->xgwa.visual,
                mi->xgwa.colormap,
                mi->colors, &mi->npixels,
                True, &mi->writable_p, True);
            break;

        case color_scheme_bright:
        case color_scheme_default:
            make_random_colormap(mi->xgwa.screen, mi->xgwa.visual,
                mi->xgwa.colormap,
                mi->colors, &mi->npixels,
                (hack_color_scheme == color_scheme_bright),
                True, &mi->writable_p, True);
            break;

        default:
            fprintf(stderr, "Bad color scheme\n");
            abort();
        }

        mi->pixels = (unsigned long *)calloc(mi->npixels, sizeof(*mi->pixels));
        if (mi->pixels == NULL)
        {
            free(mi->colors);
            return FALSE;
        }

        for (i = 0; i < mi->npixels; i++)
            mi->pixels[i] = mi->colors[i].pixel;
    }

    return TRUE;
}
Ejemplo n.º 21
0
ENTRYPOINT void 
init_quasicrystal (ModeInfo *mi)
{
  quasicrystal_configuration *bp;
  int wire = MI_IS_WIREFRAME(mi);
  unsigned char *tex_data = 0;
  int tex_width;
  int i;

  if (!bps) {
    bps = (quasicrystal_configuration *)
      calloc (MI_NUM_SCREENS(mi), sizeof (quasicrystal_configuration));
    if (!bps) {
      fprintf(stderr, "%s: out of memory\n", progname);
      exit(1);
    }
  }

  bp = &bps[MI_SCREEN(mi)];

  bp->glx_context = init_GL(mi);

  reshape_quasicrystal (mi, MI_WIDTH(mi), MI_HEIGHT(mi));

  glDisable (GL_DEPTH_TEST);
  glEnable (GL_CULL_FACE);

  bp->count = MI_COUNT(mi);
  if (bp->count < 1) bp->count = 1;

  if (! wire)
    {
      unsigned char *o;
      tex_width = 4096;
      tex_data = (unsigned char *) calloc (4, tex_width);
      o = tex_data;
      for (i = 0; i < tex_width; i++)
        {
          unsigned char y = 255 * (1 + sin (i * M_PI * 2 / tex_width)) / 2;
          *o++ = y;
          *o++ = y;
          *o++ = y;
          *o++ = 255;
        }
    }

  bp->symmetric_p =
    get_boolean_resource (MI_DISPLAY (mi), "symmetry", "Symmetry");

  bp->contrast = get_float_resource (MI_DISPLAY (mi), "contrast", "Contrast");
  if (bp->contrast < 0 || bp->contrast > 100) 
    {
      fprintf (stderr, "%s: contrast must be between 0 and 100%%.\n", progname);
      bp->contrast = 0;
    }

  {
    Bool spinp   = get_boolean_resource (MI_DISPLAY (mi), "spin", "Spin");
    Bool wanderp = get_boolean_resource (MI_DISPLAY (mi), "wander", "Wander");
    double spin_speed   = 0.01;
    double wander_speed = 0.0001;
    double spin_accel   = 10.0;
    double scale_speed  = 0.005;

    bp->planes = (plane *) calloc (sizeof (*bp->planes), bp->count);

    bp->ncolors = 256;  /* ncolors affects color-cycling speed */
    bp->colors = (XColor *) calloc (bp->ncolors, sizeof(XColor));
    make_smooth_colormap (0, 0, 0, bp->colors, &bp->ncolors,
                          False, 0, False);
    bp->ccolor = 0;

    for (i = 0;  i < bp->count; i++)
      {
        plane *p = &bp->planes[i];
        p->rot = make_rotator (0, 0,
                               spinp ? spin_speed : 0,
                               spin_accel,
                               wanderp ? wander_speed : 0,
                               True);
        p->rot2 = make_rotator (0, 0,
                                0, 0,
                               scale_speed,
                               True);
        if (! wire)
          {
            clear_gl_error();

            glGenTextures (1, &p->texid);
            glBindTexture (GL_TEXTURE_1D, p->texid);
            glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
            glTexImage1D (GL_TEXTURE_1D, 0, GL_RGBA,
                          tex_width, 0,
                          GL_RGBA,
                          /* GL_UNSIGNED_BYTE, */
                          GL_UNSIGNED_INT_8_8_8_8_REV,
                          tex_data);
            check_gl_error("texture");

            glTexParameterf(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_REPEAT);
            glTexParameterf(GL_TEXTURE_1D, GL_TEXTURE_WRAP_T, GL_REPEAT);

            glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
            glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

            glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
          }
      }
  }

  if (tex_data) free (tex_data);

  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}
Ejemplo n.º 22
0
static struct starfish *
reset_starfish (struct state *st)
{
  XGCValues gcv;
  unsigned int flags = 0;
  XWindowAttributes xgwa;
  XGetWindowAttributes (st->dpy, st->window, &xgwa);

  st->cmap = xgwa.colormap;

  if (st->done_once)
    {
      if (st->colors && st->ncolors)
	free_colors (xgwa.screen, st->cmap, st->colors, st->ncolors);
      if (st->colors)
	free (st->colors);
      st->colors = 0;
      XFreeGC (st->dpy, st->gc);
      st->gc = 0;
    }

  st->ncolors = get_integer_resource (st->dpy, "colors", "Colors");
  if (st->ncolors < 2) st->ncolors = 2;
  if (st->ncolors <= 2) mono_p = True;

  if (mono_p)
    st->colors = 0;
  else
    st->colors = (XColor *) malloc(sizeof(*st->colors) * (st->ncolors+1));

  if (mono_p)
    ;
  else if (random() % 3)
    make_smooth_colormap (xgwa.screen, xgwa.visual, st->cmap,
                          st->colors, &st->ncolors,
			  True, 0, True);
  else
    make_uniform_colormap (xgwa.screen, xgwa.visual, st->cmap,
                           st->colors, &st->ncolors,
			   True, 0, True);

  if (st->ncolors < 2) st->ncolors = 2;
  if (st->ncolors <= 2) mono_p = True;

  st->fg_index = 0;

  if (!mono_p && !st->blob_p)
    {
      flags |= GCForeground;
      gcv.foreground = st->colors[st->fg_index].pixel;
      XSetWindowBackground (st->dpy, st->window, gcv.foreground);
    }

  if (!st->done_once)
    {
      XClearWindow (st->dpy, st->window);
      st->done_once = 1;
    }

  flags |= GCFillRule;
  gcv.fill_rule = EvenOddRule;
  st->gc = XCreateGC (st->dpy, st->window, flags, &gcv);
#ifdef HAVE_JWXYZ
  if (!st->blob_p)
    jwxyz_XSetAntiAliasing (st->dpy, st->gc, False);
#endif

  return make_window_starfish (st);
}
Ejemplo n.º 23
0
ENTRYPOINT void init_soma (ModeInfo *mi)
{
    int loop;
    int colorincrement;
    GLfloat fogColor[4] = {0., 0., 0., 1.};
     GLfloat pos[4] = {0.0, 1.0, 1.0, 0.0};
      GLfloat amb[4] = {0.2, 0.2, 0.2, 1.0};
      GLfloat dif[4] = {1.0, 1.0, 1.0, 1.0};
      GLfloat spc[4] = {0.4, 0.4, 0.4, 1.0};
    GLfloat shininess[] = {75.};
    GLfloat specular[] = {1., 1., 1., 1.};
    soma_configuration *lp;

    if (!lps) {
      lps = (soma_configuration *)
        calloc (MI_NUM_SCREENS(mi), sizeof (soma_configuration));
      if (!lps) {
        fprintf(stderr, "%s: out of memory\n", progname);
        exit(1);
      }
      lp = &lps[MI_SCREEN(mi)];
    }

    lp = &lps[MI_SCREEN(mi)];
    lp->glx_context = init_GL(mi);

    lp->currentfigure = malloc (sizeof (figure));
    lp->basefigure = malloc (sizeof (figure));

    lp->fduration = ((duration > 0 && duration <= 5000) ? duration : 500);
    lp->cduration = ((colorchangerate > 0 && colorchangerate <= 1000) ? colorchangerate: 10);
    lp->tduration = ((changerate > 0 && changerate <= 500) ? changerate : 100);
    lp->viewangle = 0.;
     lp->vanglestep = ((spinrate >= -100 && spinrate <= 100) ? (spinrate / 500.0) : 0.02);
     if (do_clockwise) lp->vanglestep *= -1;
   lp->dstate = exploding;

     makedlists(lp->piecedlists);


     if(!MI_IS_MONO(mi))
      {
	lp->numcolors = ((ncolors > 0 && ncolors < 2049) ? 
                          ncolors : 256);
    lp->colors = calloc ( lp->numcolors,  sizeof (*lp->colors));
    make_smooth_colormap (MI_DISPLAY(mi),MI_VISUAL(mi), MI_COLORMAP(mi),
                            lp->colors, &lp->numcolors, False, 0, True);
     }
     if( (MI_IS_MONO(mi)) || (lp->numcolors < 1))
      {
/* 	GLfloat white[] = {1., 1., 1., 1.}; */
	lp->numcolors = 1;
        lp->colors = calloc (1, sizeof (*lp->colors));
        lp->colors[0].pixel = MI_WHITE_PIXEL(mi);
        XQueryColor( MI_DISPLAY(mi), MI_COLORMAP(mi), &lp->colors[0]);
/*          glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, white); */
     } 
    colorincrement = (int)lp->numcolors / 7;
    for (loop = 1; loop < 8; loop++)
      {
	if (do_multicolors && lp->numcolors > 6)
	  {
	    lp->colorindices[loop] = colorincrement * loop;
          }
	else
          {
	    lp->colorindices[loop] = 0;
          }
      }
    lp->ftimer = lp->ctimer = 1;
    if (lp->numcolors < 2) reset_color(lp, lp->currentfigure);

      glEnable(GL_FOG);
      glFogi(GL_FOG_MODE, GL_LINEAR);
      glFogf(GL_FOG_DENSITY, 0.50);
      glHint(GL_FOG_HINT, GL_NICEST);
      glFogf(GL_FOG_START, 15);
      glFogf(GL_FOG_END, 25);
      glFogfv(GL_FOG_COLOR, fogColor);
      glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);

    glShadeModel(GL_SMOOTH);
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_CULL_FACE); 
    glCullFace(GL_BACK);
    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    glClearDepth(1.0f);


      glLightfv(GL_LIGHT0, GL_POSITION, pos);
      glLightfv(GL_LIGHT0, GL_AMBIENT,  amb);
      glLightfv(GL_LIGHT0, GL_DIFFUSE,  dif);
      glLightfv(GL_LIGHT0, GL_SPECULAR, spc);
      glEnable(GL_LIGHTING);
      glEnable(GL_LIGHT0);
   glMaterialfv(GL_FRONT, GL_SPECULAR, specular);
   glMaterialfv(GL_FRONT, GL_SHININESS, shininess);

    handleGLerrors("init");
    reshape_soma(mi, MI_WIDTH(mi), MI_HEIGHT(mi));
    glFlush();
}
Ejemplo n.º 24
0
static void *
halftone_init (Display *dpy, Window window)
{
  int x, y, i;
  int count;
  int spacing;
  double factor;
  double min_mass;
  double max_mass;
  double min_speed;
  double max_speed;
  XGCValues gc_values;
  XWindowAttributes attrs;
  halftone_screen *halftone;

  halftone = (halftone_screen *) calloc (1, sizeof(halftone_screen));

  halftone->dpy = dpy;
  halftone->window = window;

  //halftone->delay = get_integer_resource (dpy, "delay", "Integer");
  //halftone->delay = (halftone->delay < 0 ? DEFAULT_DELAY : halftone->delay);
  halftone->delay = delay;
  halftone->delay = (halftone->delay < 0 ? DEFAULT_DELAY : halftone->delay);

  halftone->gc = XCreateGC (halftone->dpy, halftone->window, 0, &gc_values);

  halftone->buffer_width = -1;
  halftone->buffer_height = -1;
  halftone->dots = NULL;

  /* Read command line arguments and set all settings. */ 
  //count = get_integer_resource (dpy, "count", "Count");
  count = count_;
  halftone->gravity_point_count = count < 1 ? DEFAULT_COUNT : count; 

  //spacing = get_integer_resource (dpy, "spacing", "Integer");
  spacing = spacing_;
  halftone->spacing = spacing < 1 ? DEFAULT_SPACING : spacing; 

  //factor = get_float_resource (dpy, "sizeFactor", "Double");
  factor = sizeFactor;
  halftone->max_dot_size = 
    (factor < 0 ? DEFAULT_SIZE_FACTOR : factor) * halftone->spacing; 

  //min_mass = get_float_resource (dpy, "minMass", "Double");
  min_mass = minMass;
  min_mass = min_mass < 0 ? DEFAULT_MIN_MASS : min_mass;

  //max_mass = get_float_resource (dpy, "maxMass", "Double");
  max_mass = maxMass;
  max_mass = max_mass < 0 ? DEFAULT_MAX_MASS : max_mass;
  max_mass = max_mass < min_mass ? min_mass : max_mass;

  //min_speed = get_float_resource (dpy, "minSpeed", "Double");
  min_speed = minSpeed;
  min_speed = min_speed < 0 ? DEFAULT_MIN_SPEED : min_speed;

  //max_speed = get_float_resource (dpy, "maxSpeed", "Double");
  max_speed = maxSpeed;
  max_speed = max_speed < 0 ? DEFAULT_MAX_SPEED : max_speed;
  max_speed = max_speed < min_speed ? min_speed : max_speed;


  /* Set up the moving gravity points. */
  halftone->gravity_point_x = (double *) malloc(halftone->gravity_point_count * sizeof(double));
  halftone->gravity_point_y = (double *) malloc(halftone->gravity_point_count * sizeof(double));
  halftone->gravity_point_mass = (double *) malloc(halftone->gravity_point_count * sizeof(double));
  halftone->gravity_point_x_inc = (double *) malloc(halftone->gravity_point_count * sizeof(double));
  halftone->gravity_point_y_inc = (double *) malloc(halftone->gravity_point_count * sizeof(double));

  for (i = 0; i < halftone->gravity_point_count; i++)
  {
    halftone->gravity_point_x[i] = frand(1);
    halftone->gravity_point_y[i] = frand(1);
    halftone->gravity_point_mass[i] = min_mass + (max_mass - min_mass) * frand(1);
    halftone->gravity_point_x_inc[i] = min_speed + (max_speed - min_speed) * frand(1);
    halftone->gravity_point_y_inc[i] = min_speed + (max_speed - min_speed) * frand(1);
  }


  /* Set up the dots. */
  XGetWindowAttributes(halftone->dpy, halftone->window, &attrs);  

  //halftone->ncolors = get_integer_resource (dpy, "colors", "Colors");
  halftone->ncolors = colors;
  if (halftone->ncolors < 4) halftone->ncolors = 4;
  halftone->colors = (XColor *) calloc(halftone->ncolors, sizeof(XColor));
  make_smooth_colormap (attrs.screen, attrs.visual, attrs.colormap,
                        halftone->colors, &halftone->ncolors,
                        True, 0, False);
  halftone->color0 = 0;
  halftone->color1 = halftone->ncolors / 2;
  //halftone->cycle_speed = get_integer_resource (dpy, "cycleSpeed", "CycleSpeed");
  halftone->cycle_speed = cycleSpeed;
  halftone->color_tick = 0;

  update_buffer(halftone, &attrs);
  update_dot_attributes(halftone, &attrs);

  for (x = 0; x < halftone->dots_width; x++)
    for (y = 0; y < halftone->dots_height; y++)
    {
	halftone->dots[x + y * halftone->dots_width] = 0;
    }

  return halftone;
}
Ejemplo n.º 25
0
ENTRYPOINT void
draw_triangle (ModeInfo * mi)
{
    trianglestruct *tp = &triangles[MI_SCREEN(mi)];
    int         d, d2, i, j, delta;

    if (!tp->init_now) {
        draw_mesh(mi, tp, tp->d / 2, MAX_SIZE / tp->d);

        /* The init_now flag will pop up when the scene is complete.
         * Cycles specifies how long to wait, in 1/10 secs.
         TODO: This is wrong for multi-screens ***
         */
        if (tp->init_now) {
#ifndef STANDALONE
            MI_PAUSE(mi) = 2000000;
#else
            if (tp->stage == -1)
            {
                XClearWindow(MI_DISPLAY(mi), MI_WINDOW(mi));
                if (!mono_p)
                {
                    free_colors(mi->xgwa.screen, mi->xgwa.colormap, mi->colors,
                                mi->npixels);
                    mi->npixels =
                        get_integer_resource (mi->dpy, "ncolors", "Integer");
                    make_smooth_colormap (mi->xgwa.screen,
                                          mi->xgwa.visual, mi->xgwa.colormap,
                                          mi->colors, &mi->npixels,
                                          True, &mi->writable_p, True);
                }
            }
#endif
        }
        return;
    }
    if (tp->delta[0] > 0) {
        if (!(++tp->stage)) {
            tp->h[0][0] = (short int) MAX(0, DISPLACE(0, tp->delta[0]));
            tp->h[tp->size][0] = (short int) MAX(0, DISPLACE(0, tp->delta[0]));
            tp->h[0][tp->size] = (short int) MAX(0, DISPLACE(0, tp->delta[0]));
        } else {
            d = 2 << (tp->steps - tp->stage);
            d2 = d / 2;
            delta = tp->delta[tp->stage - 1];

            for (i = 0; i < tp->size; i += d) {
                for (j = 0; j < (tp->size - i); j += d) {
                    tp->h[i + d2][j] = (short int) DISPLACE(tp->h[i][j] +
                                                            tp->h[i + d][j], delta);
                    tp->h[i][j + d2] = (short int) DISPLACE(tp->h[i][j] +
                                                            tp->h[i][j + d], delta);
                    tp->h[i + d2][j + d2] = (short int) DISPLACE(tp->h[i + d][j] +
                                            tp->h[i][j + d], delta);
                }

                tp->init_now = 0;
                tp->i = 0;
                tp->j = 0;
                tp->d = d;
            }
        }
    }
    if (tp->stage == tp->steps) {
        tp->stage = -1;
    }
}
Ejemplo n.º 26
0
static void
init_map (struct state *st)
{
  XGCValues gcv;

  XGetWindowAttributes (st->dpy, st->window, &st->xgwa);
  st->cmap = st->xgwa.colormap;

  st->flip_x  = (random() % 2);
  st->flip_xy = (random() % 2);

  if (mono_p)
    st->flip_xy = 0;
  else if (st->colors) {
    free_colors (st->xgwa.screen, st->cmap, st->colors, st->ncolors);
    free (st->colors);
  }
  st->colors = 0;

  st->ncolors = get_integer_resource (st->dpy, "ncolors", "Integer");
  st->delay = get_integer_resource (st->dpy, "delay", "Integer");
  st->delay2 = get_integer_resource (st->dpy, "delay2", "Integer");
  st->iterations = get_integer_resource (st->dpy, "iterations", "Integer");
  if (st->iterations < 0) st->iterations = 0;
  else if (st->iterations > 7) st->iterations = 7;

  if (st->ncolors <= 2) st->ncolors = 0;
  if (st->ncolors == 0) mono_p = True;
  if (st->ncolors > 255) st->ncolors = 255;  /* too many look bad */

  if (!st->gc)  st->gc  = XCreateGC (st->dpy, st->window, 0, &gcv);
  if (!st->gc2) st->gc2 = XCreateGC (st->dpy, st->window, 0, &gcv);

  if (mono_p)
    st->extra_krinkly_p = !(random() % 15);
  else
    st->extra_krinkly_p = !(random() % 5);

  if (!mono_p)
    {
      if (st->ncolors < 1) st->ncolors = 1;
      if (st->colors) free (st->colors);
      st->colors = (XColor *) malloc (st->ncolors * sizeof(*st->colors));

      make_smooth_colormap (st->xgwa.screen, st->xgwa.visual, st->cmap,
                            st->colors, &st->ncolors,
                            True, 0, False);
      if (st->ncolors <= 2)
	mono_p = 1;
    }

  if (mono_p)
    {
      int i;
      unsigned long fg_pixel = 
        get_pixel_resource (st->dpy, st->xgwa.colormap, 
                            "foreground", "Foreground");
      unsigned long bg_pixel = 
        get_pixel_resource (st->dpy, st->xgwa.colormap, 
                            "background", "Background");
      if (!st->colors)
        {
          st->ncolors = 50;
          st->colors = (XColor *) calloc (st->ncolors, sizeof(*st->colors));
        }
      st->colors[0].pixel = fg_pixel;
      for (i = 1; i < st->ncolors; i++)
        st->colors[i].pixel = bg_pixel;
    }

  XSetForeground (st->dpy, st->gc, st->colors[1].pixel);
  XFillRectangle (st->dpy, st->window, st->gc, 0, 0, 
                  st->xgwa.width, st->xgwa.height);

  if (st->flip_xy)
    {
      st->xmax = st->xgwa.height;
      st->ymax = st->xgwa.width;
    }
  else
    {
      st->xmax = st->xgwa.width;
      st->ymax = st->xgwa.height;
    }

  if (st->cell) free (st->cell);
  st->cell = (signed char *) calloc (st->xmax * st->ymax, 1);

  CELL (0, 0) = 0;
  st->xstep = COUNT;
  st->ystep = COUNT;

  st->iteration = 0;
  st->cx = 0;
}
Ejemplo n.º 27
0
static void *
anemone_init (Display *disp, Window window)
{
  struct state *st = (struct state *) calloc (1, sizeof(*st));
  XWindowAttributes wa;

  st->dpy = disp;
  st->turn = 0.;
  
  st->width = get_integer_resource(st->dpy, "width", "Integer");
  st->arms = get_integer_resource(st->dpy, "arms", "Integer");
  st->finpoints = get_integer_resource(st->dpy, "finpoints", "Integer");
  st->delay = get_integer_resource(st->dpy, "delay", "Integer");
  st->withdraw = get_integer_resource(st->dpy, "withdraw", "Integer");
  st->turndelta = get_float_resource(st->dpy, "turnspeed", "float") / 100000;

  st->dbuf = TRUE;

# ifdef HAVE_JWXYZ	/* Don't second-guess Quartz's double-buffering */
  st->dbuf = False;
# endif

  st->b = st->ba = st->bb = 0;	/* double-buffer to reduce flicker */
#ifdef HAVE_DOUBLE_BUFFER_EXTENSION
  st->b = st->backb = xdbe_get_backbuffer (st->dpy, window, XdbeUndefined);
#endif /* HAVE_DOUBLE_BUFFER_EXTENSION */


  XGetWindowAttributes(st->dpy, window, &wa);
  st->scrWidth = wa.width;
  st->scrHeight = wa.height;
  st->cmap = wa.colormap;

  st->ncolors = get_integer_resource (st->dpy, "colors", "Colors");
  st->ncolors += 3;
  st->colors = (XColor *) malloc(sizeof(*st->colors) * (st->ncolors+1));
  make_smooth_colormap (wa.screen, wa.visual, st->cmap,
                        st->colors, &st->ncolors,
                        True, 0, True);

  st->gcDraw = XCreateGC(st->dpy, window, 0, &st->gcv);
  st->gcv.foreground = get_pixel_resource(st->dpy, st->cmap,
                                          "background", "Background");
  st->gcClear = XCreateGC(st->dpy, window, GCForeground, &st->gcv);

  if (st->dbuf) {
    if (!st->b)
      {
	st->ba = XCreatePixmap (st->dpy, window, st->scrWidth, st->scrHeight, wa.depth);
	st->bb = XCreatePixmap (st->dpy, window, st->scrWidth, st->scrHeight, wa.depth);
	st->b = st->ba;
      }
  }
  else
    {	
      st->b = window;
    }

  if (st->ba) XFillRectangle (st->dpy, st->ba, st->gcClear, 0, 0, st->scrWidth, st->scrHeight);
  if (st->bb) XFillRectangle (st->dpy, st->bb, st->gcClear, 0, 0, st->scrWidth, st->scrHeight);

  XClearWindow(st->dpy, window);
  XSetLineAttributes(st->dpy, st->gcDraw,  st->width, LineSolid, CapRound, JoinBevel);

  initAppendages(st);

  return st;
}
Ejemplo n.º 28
0
static void *
halo_init (Display *dpy, Window window)
{
  struct state *st = (struct state *) calloc (1, sizeof(*st));
  XGCValues gcv;
  XWindowAttributes xgwa;
  char *mode_str = 0;
  st->dpy = dpy;
  st->window = window;
  XGetWindowAttributes (st->dpy, st->window, &xgwa);
  st->cmap = xgwa.colormap;
  st->global_count = get_integer_resource (st->dpy, "count", "Integer");
  if (st->global_count < 0) st->global_count = 0;
  st->global_inc = get_integer_resource (st->dpy, "increment", "Integer");
  if (st->global_inc < 0) st->global_inc = 0;
  st->anim_p = get_boolean_resource (st->dpy, "animate", "Boolean");
  st->delay = get_integer_resource (st->dpy, "delay", "Integer");
  st->delay2 = get_integer_resource (st->dpy, "delay2", "Integer") * 1000000;
  mode_str = get_string_resource (st->dpy, "colorMode", "ColorMode");
  if (! mode_str) cmode = random_mode;
  else if (!strcmp (mode_str, "seuss"))  cmode = seuss_mode;
  else if (!strcmp (mode_str, "ramp"))   cmode = ramp_mode;
  else if (!strcmp (mode_str, "random")) cmode = random_mode;
  else {
    fprintf (stderr,
	     "%s: colorMode must be seuss, ramp, or random, not \"%s\"\n",
	     progname, mode_str);
    exit (1);
  }

  if (mono_p) cmode = seuss_mode;
  if (cmode == random_mode)
    cmode = ((random()&3) == 1) ? ramp_mode : seuss_mode;

  if (cmode == ramp_mode)
    st->anim_p = False;    /* This combo doesn't work right... */

  st->ncolors = get_integer_resource (st->dpy, "colors", "Colors");
  if (st->ncolors < 2) st->ncolors = 2;
  if (st->ncolors <= 2) mono_p = True;

  if (mono_p)
    st->colors  = 0;
  else
    st->colors = (XColor *) malloc(sizeof(*st->colors) * (st->ncolors+1));


  if (mono_p)
    ;
  else if (random() % (cmode == seuss_mode ? 2 : 10))
    make_uniform_colormap (xgwa.screen, xgwa.visual, st->cmap,
                           st->colors, &st->ncolors,
			   True, 0, True);
  else
    make_smooth_colormap (xgwa.screen, xgwa.visual, st->cmap,
                          st->colors, &st->ncolors,
			  True, 0, True);

  if (st->ncolors <= 2) mono_p = True;
  if (mono_p) cmode = seuss_mode;

  if (mono_p)
    {
      st->fg_pixel = get_pixel_resource (st->dpy, st->cmap, "foreground", "Foreground");
      st->bg_pixel = get_pixel_resource (st->dpy, st->cmap, "background", "Background");
    }
  else
    {
      st->fg_index = 0;
      st->bg_index = st->ncolors / 4;
      if (st->fg_index == st->bg_index) st->bg_index++;
      st->fg_pixel = st->colors[st->fg_index].pixel;
      st->bg_pixel = st->colors[st->bg_index].pixel;
    }

  st->width = max (50, xgwa.width);
  st->height = max (50, xgwa.height);

#ifdef DEBUG
  st->width/=2; st->height/=2;
#endif

  st->pixmap = XCreatePixmap (st->dpy, st->window, st->width, st->height, 1);
  if (cmode == seuss_mode)
    st->buffer = XCreatePixmap (st->dpy, st->window, st->width, st->height, 1);
  else
    st->buffer = 0;

  gcv.foreground = 1;
  gcv.background = 0;
  st->draw_gc = XCreateGC (st->dpy, st->pixmap, GCForeground | GCBackground, &gcv);
  gcv.foreground = 0;
  st->erase_gc = XCreateGC (st->dpy, st->pixmap, GCForeground, &gcv);
  gcv.foreground = st->fg_pixel;
  gcv.background = st->bg_pixel;
  st->copy_gc = XCreateGC (st->dpy, st->window, GCForeground | GCBackground, &gcv);

#ifdef HAVE_COCOA
  jwxyz_XSetAntiAliasing (dpy, st->draw_gc,  False);
  jwxyz_XSetAntiAliasing (dpy, st->erase_gc, False);
  jwxyz_XSetAntiAliasing (dpy, st->copy_gc,  False);
#endif

  if (cmode == seuss_mode)
    {
      gcv.foreground = 1;
      gcv.background = 0;
      gcv.function = GXxor;
      st->merge_gc = XCreateGC (st->dpy, st->pixmap,
			    GCForeground | GCBackground | GCFunction, &gcv);
    }
  else
    {
      gcv.foreground = st->fg_pixel;
      gcv.background = st->bg_pixel;
      gcv.function = GXcopy;
      st->merge_gc = XCreateGC (st->dpy, st->window,
			    GCForeground | GCBackground | GCFunction, &gcv);
    }

  init_circles_1 (st);
  XClearWindow (st->dpy, st->window);
  if (st->buffer) XFillRectangle (st->dpy, st->buffer, st->erase_gc, 0, 0, st->width, st->height);
  return st;
}
Ejemplo n.º 29
0
static void
hexadrop_init_1 (Display *dpy, Window window, state *st)
{
  XGCValues gcv;
  char *s1, *s2;

  st->dpy = dpy;
  st->window = window;
  st->delay = get_integer_resource (st->dpy, "delay", "Integer");
  st->ncolors = get_integer_resource (st->dpy, "ncolors", "Integer");
  st->speed = get_float_resource (st->dpy, "speed", "Speed");
  if (st->speed < 0) st->speed = 0;

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

  if (st->ncolors < 2) st->ncolors = 2;

  st->colors = (XColor *) calloc (sizeof(*st->colors), st->ncolors);

  if (st->ncolors < 10)
    make_random_colormap (st->xgwa.screen, st->xgwa.visual, st->xgwa.colormap,
                          st->colors, &st->ncolors, False, True, 0, True);
  else
    make_smooth_colormap (st->xgwa.screen, st->xgwa.visual, st->xgwa.colormap,
                          st->colors, &st->ncolors, True, 0, True);
  XSetWindowBackground (dpy, window, st->colors[0].pixel);

  s1 = get_string_resource (st->dpy, "uniform", "Uniform");
  s2 = get_string_resource (st->dpy, "lockstep", "Lockstep");

  if ((!s1 || !*s1 || !strcasecmp(s1, "maybe")) &&
      (!s2 || !*s2 || !strcasecmp(s2, "maybe")))
    {
      /* When being random, don't do both. */
      st->uniform_p = random() & 1;
      st->lockstep_p = st->uniform_p ? 0 : random() & 1;
    }
  else 
    {
      if (!s1 || !*s1 || !strcasecmp(s1, "maybe"))
        st->uniform_p = random() & 1;
      else
        st->uniform_p = get_boolean_resource (st->dpy, "uniform", "Uniform");

      if (!s2 || !*s2 || !strcasecmp(s2, "maybe"))
        st->lockstep_p = random() & 1;
      else
        st->lockstep_p = get_boolean_resource (st->dpy, "lockstep","Lockstep");
    }


  st->sides = get_integer_resource (st->dpy, "sides", "Sides");
  if (! (st->sides == 0 || st->sides == 3 || st->sides == 4 || 
         st->sides == 6 || st->sides == 8))
    {
      printf ("%s: invalid number of sides: %d\n", progname, st->sides);
      st->sides = 0;
    }

  if (! st->sides)
    {
      static int defs[] = { 3, 3, 3,
                            4,
                            6, 6, 6, 6,
                            8, 8, 8 };
      st->sides = defs[random() % countof(defs)];
    }

  make_cells (st);
  gcv.foreground = st->colors[0].pixel;
  st->gc = XCreateGC (dpy, window, GCForeground, &gcv);
}
Ejemplo n.º 30
0
void
init_tik_tak(ModeInfo * mi)
{
	Display    *display = MI_DISPLAY(mi);
	Window      window = MI_WINDOW(mi);
	int         i, max_objects, size_object;
	tik_takstruct *tiktak;

/* initialize */
	if (tik_taks == NULL) {
		if ((tik_taks = (tik_takstruct *) calloc(MI_NUM_SCREENS(mi),
				sizeof (tik_takstruct))) == NULL)
			return;
	}
	tiktak = &tik_taks[MI_SCREEN(mi)];
	tiktak->mi = mi;

	if (tiktak->gc == None) {
		if (MI_IS_INSTALL(mi) && MI_NPIXELS(mi) > 2) {
			XColor      color;

#ifndef STANDALONE
			tiktak->fg = MI_FG_PIXEL(mi);
			tiktak->bg = MI_BG_PIXEL(mi);
#endif
			tiktak->blackpixel = MI_BLACK_PIXEL(mi);
			tiktak->whitepixel = MI_WHITE_PIXEL(mi);
			if ((tiktak->cmap = XCreateColormap(display, window,
					MI_VISUAL(mi), AllocNone)) == None) {
				free_tik_tak(display, tiktak);
				return;
			}
			XSetWindowColormap(display, window, tiktak->cmap);
			(void) XParseColor(display, tiktak->cmap, "black", &color);
			(void) XAllocColor(display, tiktak->cmap, &color);
			MI_BLACK_PIXEL(mi) = color.pixel;
			(void) XParseColor(display, tiktak->cmap, "white", &color);
			(void) XAllocColor(display, tiktak->cmap, &color);
			MI_WHITE_PIXEL(mi) = color.pixel;
#ifndef STANDALONE
			(void) XParseColor(display, tiktak->cmap, background, &color);
			(void) XAllocColor(display, tiktak->cmap, &color);
			MI_BG_PIXEL(mi) = color.pixel;
			(void) XParseColor(display, tiktak->cmap, foreground, &color);
			(void) XAllocColor(display, tiktak->cmap, &color);
			MI_FG_PIXEL(mi) = color.pixel;
#endif
			tiktak->colors = (XColor *) NULL;
			tiktak->ncolors = 0;
		}
		if ((tiktak->gc = XCreateGC(display, MI_WINDOW(mi),
			     (unsigned long) 0, (XGCValues *) NULL)) == None) {
			free_tik_tak(display, tiktak);
			return;
		}
	}
/* Clear Display */
	MI_CLEARWINDOW(mi);
	tiktak->painted = False;
	XSetFunction(display, tiktak->gc, GXxor);


/*Set up tik_tak data */
	tiktak->direction = (LRAND() & 1) ? 1 : -1;
	tiktak->win_width = MI_WIDTH(mi);
	tiktak->win_height = MI_HEIGHT(mi);
	tiktak->num_object = MI_COUNT(mi);
        tiktak->x0 = tiktak->win_width / 2;
        tiktak->y0 = tiktak->win_height / 2;
	max_objects = MI_COUNT(mi);
	if (tiktak->num_object == 0) {
		tiktak->num_object = DEF_NUM_OBJECT;
		max_objects = DEF_NUM_OBJECT;
	} else if (tiktak->num_object < 0) {
		max_objects = -tiktak->num_object;
		tiktak->num_object = NRAND(-tiktak->num_object) + 1;
	}
	if (tiktak->object == NULL)
		if ((tiktak->object = (tik_takobject *) calloc(max_objects,
				sizeof (tik_takobject))) == NULL) {
			free_tik_tak(display, tiktak);
			return;
		}
	size_object = MIN( tiktak->win_width , tiktak->win_height) / 3;
	if ( abs( MI_SIZE(mi) ) > size_object) {
	   if ( MI_SIZE( mi ) < 0 )
	     {
		size_object = -size_object;
	     }
	}
   else
     {
	size_object = MI_SIZE(mi);
     }
	if (MI_IS_INSTALL(mi) && MI_NPIXELS(mi) > 2) {
/* Set up colour map */
		if (tiktak->colors != NULL) {
			if (tiktak->ncolors && !tiktak->no_colors)
				free_colors(display, tiktak->cmap, tiktak->colors, tiktak->ncolors);
			free(tiktak->colors);
			tiktak->colors = (XColor *) NULL;
		}
		tiktak->ncolors = MI_NCOLORS(mi);
		if (tiktak->ncolors < 2)
			tiktak->ncolors = 2;
		if (tiktak->ncolors <= 2)
			tiktak->mono_p = True;
		else
			tiktak->mono_p = False;

		if (tiktak->mono_p)
			tiktak->colors = (XColor *) NULL;
		else
			if ((tiktak->colors = (XColor *) malloc(sizeof (*tiktak->colors) *
					(tiktak->ncolors + 1))) == NULL) {
				free_tik_tak(display, tiktak);
				return;
			}
		tiktak->cycle_p = has_writable_cells(mi);
		if (tiktak->cycle_p) {
			if (MI_IS_FULLRANDOM(mi)) {
				if (!NRAND(8))
					tiktak->cycle_p = False;
				else
					tiktak->cycle_p = True;
			} else {
				tiktak->cycle_p = cycle_p;
			}
		}
		if (!tiktak->mono_p) {
			if (!(LRAND() % 10))
				make_random_colormap(
#ifdef STANDALONE
						MI_DISPLAY(mi), MI_WINDOW(mi),
#else
            mi,
#endif
						tiktak->cmap, tiktak->colors, &tiktak->ncolors,
						True, True, &tiktak->cycle_p);
			else if (!(LRAND() % 2))
				make_uniform_colormap(
#ifdef STANDALONE
						MI_DISPLAY(mi), MI_WINDOW(mi),
#else
            mi,
#endif
                  tiktak->cmap, tiktak->colors, &tiktak->ncolors,
						      True, &tiktak->cycle_p);
			else
				make_smooth_colormap(
#ifdef STANDALONE
						MI_DISPLAY(mi), MI_WINDOW(mi),
#else
            mi,
#endif
                 tiktak->cmap, tiktak->colors, &tiktak->ncolors,
						     True, &tiktak->cycle_p);
		}
		XInstallColormap(display, tiktak->cmap);
		if (tiktak->ncolors < 2) {
			tiktak->ncolors = 2;
			tiktak->no_colors = True;
		} else
			tiktak->no_colors = False;
		if (tiktak->ncolors <= 2)
			tiktak->mono_p = True;

		if (tiktak->mono_p)
			tiktak->cycle_p = False;

	}
	for (i = 0; i < tiktak->num_object; i++) {
		tik_takobject *object0;

		object0 = &tiktak->object[i];
		if (MI_IS_INSTALL(mi) && MI_NPIXELS(mi) > 2) {
			if (tiktak->ncolors > 2)
				object0->colour = NRAND(tiktak->ncolors - 2) + 2;
			else
				object0->colour = 1;	/* Just in case */
			XSetForeground(display, tiktak->gc, tiktak->colors[object0->colour].pixel);
		} else {
			if (MI_NPIXELS(mi) > 2)
				object0->colour = MI_PIXEL(mi, NRAND(MI_NPIXELS(mi)));
			else
				object0->colour = 1;	/*Xor'red so WHITE may not be appropriate */
			XSetForeground(display, tiktak->gc, object0->colour);
		}
		object0->angle = NRAND(90) * PI_RAD;
		object0->angle1 = NRAND(90) * PI_RAD;
		object0->velocity_a = (NRAND(7) - 3) * PI_RAD;
		object0->velocity_a1 = (NRAND(7) - 3) * PI_RAD;
		if (size_object == 0)
			object0->size_ob = 9;
		else if (size_object > 0)
			object0->size_ob = size_object;
		else
			object0->size_ob = NRAND(-size_object) + 1;
		object0->size_ob++;
		object0->num_point = NRAND(6)+3;
	   if (LRAND() & 1)
	     object0->size_mult = 1.0;
	   else
	     {
		object0->num_point *= 2;
		object0->size_mult = 1.0 - ( 1.0 / (float) ((LRAND() & 1) +
							    2 ) );
	     }
	   if (object0->xy != NULL)
			free(object0->xy);
	   if ((object0->xy = (XPoint *) malloc(sizeof( XPoint ) *
				(2 * object0->num_point + 2))) == NULL) {
			free_tik_tak(display, tiktak);
			return;
		}
	   if ((LRAND() & 1) || object0->size_ob < 10 )
	     {
		object0->inner = False;
		if ( object0->xy1 != NULL ) free( object0->xy1 );
		object0->xy1 = (XPoint *) NULL;
	     }
	   else
	     {
		object0->inner = True;
	        object0->size_ob1 = object0->size_ob -
		  NRAND( object0->size_ob / 5 ) - 1;
		object0->num_point1 = NRAND(6)+3;
		if (LRAND() & 1)
		  object0->size_mult1 = 1.0;
		else
		  {
		     object0->num_point1 *= 2;
		     object0->size_mult1 = 1.0 -
		        ( 1.0 / (float) ((LRAND() & 1) + 2 ) );
		  }
		if (object0->xy1 != NULL)
			free(object0->xy1);
		if ((object0->xy1 = (XPoint *) malloc(sizeof( XPoint ) *
				(2 * object0->num_point1 + 2))) == NULL) {
			free_tik_tak(display, tiktak);
			return;
		}
		object0->size_mult1 = 1.0;
	     }
		tik_tak_setupobject( mi , object0);
		tik_tak_reset_object( object0);
		tik_tak_drawobject(mi, object0 );
	}
	XFlush(display);
	XSetFunction(display, tiktak->gc, GXcopy);
}