예제 #1
0
파일: lissie.c 프로젝트: sev-/xscreensaver
static void
drawlissie(ModeInfo * mi, lissiestruct * lissie)
{
	Display    *display = MI_DISPLAY(mi);
	GC          gc = MI_GC(mi);
	lissstruct *lp = &lisses[MI_SCREEN(mi)];
	int         p = (++lissie->pos) % MAXLISSIELEN;
	int         oldp = (lissie->pos - lissie->len + MAXLISSIELEN) % MAXLISSIELEN;

	/* Let time go by ... */
	lissie->tx += lissie->dtx;
	lissie->ty += lissie->dty;
	if (lissie->tx > 2 * M_PI)
		lissie->tx -= 2 * M_PI;
	if (lissie->ty > 2 * M_PI)
		lissie->ty -= 2 * M_PI;

	/* vary both (x/y) speeds by max. 1% */
	lissie->dtx *= FLOATRAND(0.99, 1.01);
	lissie->dty *= FLOATRAND(0.99, 1.01);
	if (lissie->dtx < MINDT)
		lissie->dtx = MINDT;
	else if (lissie->dtx > MAXDT)
		lissie->dtx = MAXDT;
	if (lissie->dty < MINDT)
		lissie->dty = MINDT;
	else if (lissie->dty > MAXDT)
		lissie->dty = MAXDT;

	lissie->loc[p].x = lissie->xi + (int) (sin(lissie->tx) * lissie->rx);
	lissie->loc[p].y = lissie->yi + (int) (sin(lissie->ty) * lissie->ry);

	/* Mask */
	XSetForeground(display, gc, MI_BLACK_PIXEL(mi));
	Lissie(oldp);

	/* Redraw */
	if (MI_NPIXELS(mi) > 2) {
		XSetForeground(display, gc, MI_PIXEL(mi, lissie->color));
		if (++lissie->color >= (unsigned) MI_NPIXELS(mi))
			lissie->color = 0;
	} else
		XSetForeground(display, gc, MI_WHITE_PIXEL(mi));
	Lissie(p);
	if (lissie->redrawing) {
		int         i;

		lissie->redrawpos++;
		/* This compensates for the changed p
		   since the last callback. */

		for (i = 0; i < REDRAWSTEP; i++) {
			Lissie((p - lissie->redrawpos + MAXLISSIELEN) % MAXLISSIELEN);
			if (++(lissie->redrawpos) >= lissie->len) {
				lissie->redrawing = 0;
				break;
			}
		}
	}
}
예제 #2
0
파일: lissie.c 프로젝트: sev-/xscreensaver
static void
initlissie(ModeInfo * mi, lissiestruct * lissie)
{
	lissstruct *lp = &lisses[MI_SCREEN(mi)];
	int         size = MI_SIZE(mi);
	int         i;

	if (MI_NPIXELS(mi) > 2)
		lissie->color = NRAND(MI_NPIXELS(mi));
	else
		lissie->color = MI_WHITE_PIXEL(mi);
	/* Initialize parameters */
	if (size < -MINSIZE)
		lissie->ri = NRAND(MIN(-size, MAX(MINSIZE,
		   MIN(lp->width, lp->height) / 4)) - MINSIZE + 1) + MINSIZE;
	else if (size < MINSIZE) {
		if (!size)
			lissie->ri = MAX(MINSIZE, MIN(lp->width, lp->height) / 4);
		else
			lissie->ri = MINSIZE;
	} else
		lissie->ri = MIN(size, MAX(MINSIZE, MIN(lp->width, lp->height) / 4));
	lissie->xi = INTRAND(lp->width / 4 + lissie->ri,
			     lp->width * 3 / 4 - lissie->ri);
	lissie->yi = INTRAND(lp->height / 4 + lissie->ri,
			     lp->height * 3 / 4 - lissie->ri);
	lissie->rx = INTRAND(lp->width / 4,
		   MIN(lp->width - lissie->xi, lissie->xi)) - 2 * lissie->ri;
	lissie->ry = INTRAND(lp->height / 4,
		  MIN(lp->height - lissie->yi, lissie->yi)) - 2 * lissie->ri;
	lissie->len = INTRAND(MINLISSIELEN, MAXLISSIELEN - 1);
	lissie->pos = 0;

	lissie->redrawing = 0;

	lissie->tx = FLOATRAND(0, 2 * M_PI);
	lissie->ty = FLOATRAND(0, 2 * M_PI);
	lissie->dtx = FLOATRAND(MINDT, MAXDT);
	lissie->dty = FLOATRAND(MINDT, MAXDT);

	for (i = 0; i < MAXLISSIELEN; i++)
		lissie->loc[i].x = lissie->loc[i].y = 0;
	/* Draw lissie */
	drawlissie(mi, lissie);
}
예제 #3
0
static void
init_planet(ModeInfo * mi, planetstruct * planet)
{
	gravstruct *gp = &gravs[MI_SCREEN(mi)];

# ifdef HAVE_JWXYZ
    jwxyz_XSetAntiAliasing (MI_DISPLAY(mi), MI_GC(mi), False);
# endif

	if (MI_NPIXELS(mi) > 2)
		planet->colors = MI_PIXEL(mi, NRAND(MI_NPIXELS(mi)));
	else
		planet->colors = MI_WHITE_PIXEL(mi);
	/* Initialize positions */
	POS(X) = FLOATRAND(-XR, XR);
	POS(Y) = FLOATRAND(-YR, YR);
	POS(Z) = FLOATRAND(-ZR, ZR);

	if (POS(Z) > -ALMOST) {
		planet->xi = (int)
			((double) gp->width * (HALF + POS(X) / (POS(Z) + DIST)));
		planet->yi = (int)
			((double) gp->height * (HALF + POS(Y) / (POS(Z) + DIST)));
	} else
		planet->xi = planet->yi = -1;
	planet->ri = RADIUS;

	/* Initialize velocities */
	VEL(X) = FLOATRAND(-VR, VR);
	VEL(Y) = FLOATRAND(-VR, VR);
	VEL(Z) = FLOATRAND(-VR, VR);
}
예제 #4
0
void init_planet(planetstruct *planet)
{
	gravstruct *gp = &gravs;

	planet->colors = rand() % (PALSIZE-21);

	// init positions
	POS(X) = FLOATRAND(-XR, XR);
	POS(Y) = FLOATRAND(-YR, YR);							 
	POS(Z) = FLOATRAND(-ZR, ZR);

	if (POS(Z) > -ALMOST) {
		planet->xi = (unsigned int)
			((double)gp->width * (HALF+POS(X) / (POS(Z) + DIST)));
		planet->yi = (unsigned int)
			((double)gp->height * (HALF+POS(Y) / (POS(Z) + DIST)));
	}
	else
		planet->xi = planet->yi = -1;

	planet->ri = RADIUS;

	// init velocities
	VEL(X) = FLOATRAND(-VR, VR);
	VEL(Y) = FLOATRAND(-VR, VR);
	VEL(Z) = FLOATRAND(-VR, VR);

}
예제 #5
0
static void
init_planet(ModeInfo * mi, planetstruct * planet)
{
	Display    *display = MI_DISPLAY(mi);
	Window      window = MI_WINDOW(mi);
	GC          gc = MI_GC(mi);
	gravstruct *gp = &gravs[MI_SCREEN(mi)];

	if (MI_NPIXELS(mi) > 2)
		planet->colors = MI_PIXEL(mi, NRAND(MI_NPIXELS(mi)));
	else
		planet->colors = MI_WHITE_PIXEL(mi);
	/* Initialize positions */
	POS(X) = FLOATRAND(-XR, XR);
	POS(Y) = FLOATRAND(-YR, YR);
	POS(Z) = FLOATRAND(-ZR, ZR);

	if (POS(Z) > -ALMOST) {
		planet->xi = (int)
			((double) gp->width * (HALF + POS(X) / (POS(Z) + DIST)));
		planet->yi = (int)
			((double) gp->height * (HALF + POS(Y) / (POS(Z) + DIST)));
	} else
		planet->xi = planet->yi = -1;
	planet->ri = RADIUS;

	/* Initialize velocities */
	VEL(X) = FLOATRAND(-VR, VR);
	VEL(Y) = FLOATRAND(-VR, VR);
	VEL(Z) = FLOATRAND(-VR, VR);

	/* Draw planets */
	Planet(planet->xi, planet->yi);
}
예제 #6
0
/* Returns a rotator object, which encapsulates rotation and motion state.

   spin_[xyz]_speed indicates the relative speed of rotation.
   Specify 0 if you don't want any rotation around that axis.

   spin_accel specifies a scaling factor for the acceleration that is
   randomly applied to spin: if you want the speed to change faster,
   make this > 1.

   wander_speed indicates the relative speed through space.

   If randomize_initial_state_p is true, then the initial position and
   rotation will be randomized (even if the spin speeds are 0.)  If it
   is false, then all values will be initially zeroed.
 */
rotator *
make_rotator (double spin_x_speed,
              double spin_y_speed,
              double spin_z_speed,
              double spin_accel,
              double wander_speed,
              int randomize_initial_state_p)
{
  rotator *r = (rotator *) calloc (1, sizeof(*r));
  double d, dd;

  if (!r) return 0;

  if (spin_x_speed < 0 || spin_y_speed < 0 || spin_z_speed < 0 ||
      wander_speed < 0)
    abort();

  r->spin_x_speed = spin_x_speed;
  r->spin_y_speed = spin_y_speed;
  r->spin_z_speed = spin_z_speed;
  r->wander_speed = wander_speed;

  if (randomize_initial_state_p)
    {
      r->rotx = FLOATRAND(1.0) * RANDSIGN();
      r->roty = FLOATRAND(1.0) * RANDSIGN();
      r->rotz = FLOATRAND(1.0) * RANDSIGN();

      r->wander_frame = LRAND() % 0xFFFF;
    }
  else
    {
      r->rotx = r->roty = r->rotz = 0;
      r->wander_frame = 0;
    }

  d  = 0.006;
  dd = 0.00006;

  r->dx = BELLRAND(d * r->spin_x_speed);
  r->dy = BELLRAND(d * r->spin_y_speed);
  r->dz = BELLRAND(d * r->spin_z_speed);

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

  r->ddx = (dd + FLOATRAND(dd+dd)) * r->spin_x_speed * spin_accel;
  r->ddy = (dd + FLOATRAND(dd+dd)) * r->spin_y_speed * spin_accel;
  r->ddz = (dd + FLOATRAND(dd+dd)) * r->spin_z_speed * spin_accel;

# if 0
  fprintf (stderr, "rotator:\n");
  fprintf (stderr, "   wander: %3d %6.2f\n", r->wander_frame, r->wander_speed);
  fprintf (stderr, "    speed: %6.2f %6.2f %6.2f\n",
           r->spin_x_speed, r->spin_y_speed, r->spin_z_speed);
  fprintf (stderr, "      rot: %6.2f %6.2f %6.2f\n",
           r->rotx, r->roty, r->rotz);
  fprintf (stderr, "        d: %6.2f %6.2f %6.2f, %6.2f\n",
           r->dx, r->dy, r->dz,
           r->d_max);
  fprintf (stderr, "       dd: %6.2f %6.2f %6.2f\n",
           r->ddx, r->ddy, r->ddz);
# endif

  return r;
}
예제 #7
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);
  }
}
예제 #8
0
static void
Select(/* input variables first */
  complex *extreme_ul, complex *extreme_lr,
  int width, int height, int power, int top,
  Bool zpow, Bool zsin,
  /* output variables follow */
  complex *selected_ul,complex *selected_lr)
{
	double precision;
	double s2;
	int inside;
	int uninteresting;
	int found;
	int tries;
	found = 0;
	while (!found) {
		/* select a precision - be careful with this */
		precision = pow(2.0,FLOATRAND(-9.0,-18.0));
		/* (void) printf("precision is %f\n",precision); */
		for (tries=0;tries<10000&&!found;tries++) {
			/* it eventually turned out that this inner loop doesn't always
			** terminate - so we just try 10000 times, and if we don't get
			** anything interesting, we pick a new precision
			*/
			complex temp;
			int sample_step = 4;
			int row,column;
			inside = 0;
			uninteresting = 0;
			/* pick a random point in the allowable range */
			temp.real = FLOATRAND(extreme_ul->real,extreme_lr->real);
			temp.imag = FLOATRAND(extreme_ul->imag,extreme_lr->imag);
			/* find upper left and lower right points */
			selected_ul->real = temp.real - precision * width / 2;
			selected_lr->real = temp.real + precision * width / 2;
			selected_ul->imag = temp.imag - precision * height / 2;
			selected_lr->imag = temp.imag + precision * height / 2;
			/* sample the results we'd get from this choice, accept or reject
			** accordingly
			*/
			for (row=0; row<sample_step; row++) {
				for (column=0; column<sample_step; column++) {
					int r;
					temp.imag = selected_ul->imag +
						(selected_ul->imag - selected_lr->imag) *
						(((double)row)/sample_step);
					temp.real = selected_ul->real +
						(selected_ul->real - selected_lr->real) *
						(((double)column)/sample_step);
					r = reps(temp,(double) power,top,0,0,0.0, zpow, zsin);
					/* Here, we just want to see if the point is in the set,
					** not if we can make something pretty
					*/
					if (r == top) {
						inside++;
					}
					if (r < 2) {
						uninteresting++;
					}
				}
			}
			s2 = sample_step*sample_step;
			/* more than 10 percent, but less than 60 percent inside the set */
			if (inside >= ceil(s2/10.0) && inside <= s2*6.0/10.0 &&
				uninteresting <= s2/10.0) {
				/* this one looks interesting */
				found = 1;
			}
			/* else
			*** this does not look like a real good combination, so back
			*** up to the top of the loop to try another possibility
			 */
		}
	}
}
예제 #9
0
void
init_molecule (ModeInfo *mi)
{
  molecule_configuration *mc;
  int wire;

#ifndef STANDALONE
  timeout = MI_CYCLES(mi);
#endif
  if (!mcs) {
    mcs = (molecule_configuration *)
      calloc (MI_NUM_SCREENS(mi), sizeof (molecule_configuration));
    if (!mcs) {
       return;
    }
  }

  mc = &mcs[MI_SCREEN(mi)];
  if (mc->glx_context) {
	/* Free font stuff */
	free_fonts (mi);
  }

  if ((mc->glx_context = init_GL(mi)) != NULL) {
    glDrawBuffer(GL_BACK);
    gl_init();
    last = 0;
    reshape_molecule (mi, MI_WIDTH(mi), MI_HEIGHT(mi));
  }

  if (!load_fonts (mi)) {
	release_molecule(mi);
	return;
  }
  if (firstcall)
  startup_blurb (mi);
  cur_wire = MI_IS_WIREFRAME(mi);
  wire = cur_wire;

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

  /* bell curve from 0-6 degrees, avg 3 */
  mc->dx = (FLOATRAND(0.1) + FLOATRAND(0.1) + FLOATRAND(0.1)) / (360/2);
  mc->dy = (FLOATRAND(0.1) + FLOATRAND(0.1) + FLOATRAND(0.1)) / (360/2);
  mc->dz = (FLOATRAND(0.1) + FLOATRAND(0.1) + FLOATRAND(0.1)) / (360/2);

  mc->d_max = mc->dx * 8;

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

  {
    char *s = do_spin;
    while (*s)
      {
        if      (*s == 'x' || *s == 'X') mc->spin_x = 1;
        else if (*s == 'y' || *s == 'Y') mc->spin_y = 1;
        else if (*s == 'z' || *s == 'Z') mc->spin_z = 1;
        else
          {
            (void) fprintf (stderr,
         "molecule: spin must contain only the characters X, Y, or Z (not \"%s\")\n",
                     do_spin);
            /* exit (1); */
          }
        s++;
      }
  }

  mc->molecule_dlist = glGenLists(1);

  load_molecules (mi);
  mc->which =  NRAND(mc->nmolecules);

#ifdef STANDALONE
  mc->no_label_threshold = get_float_resource ("noLabelThreshold",
                                               "NoLabelThreshold");
  mc->wireframe_threshold = get_float_resource ("wireframeThreshold",
                                                "WireframeThreshold");
#else
  mc->no_label_threshold = 30;
  mc->wireframe_threshold = 150;
#endif

  if (wire)
    do_bonds = 1;
}
예제 #10
0
LONG IFS( struct Screen *scr, SHORT width, SHORT height, PrefObject *Prefs )
{
  LONG flg_end = OK;
  int colors = (1L << scr->BitMap.Depth);
    double x,y,			/* the coordinate which gets computed */
           prob;		/* probability for continuing withot Clscr */
    int num,			/* total number of fctns for the current IFS */
        thef;			/* the currently applied function */
    int i,j,k;			/* multi-purpose counters, array indices */
    int wx,wy;			/* window coordinate of current point */
    int tx,ty;			/* # pixels to transpose the Origin (x,y) */

    double aa[FNUM][4],		/* For each f: a 2x2 matrix and */
           vv[FNUM][2],		/*             a transposition vector */
           comp[FNUM],		/* the compression of each function (1/comp[n]
                                 * is the compression of the function) */
           totcomp;		/* sum of all the size factors. The larger this
                                 * is, the longer we should compute */
    double CONTINUEPROBABILITY,CONTPROBDECREASE;
    bool TRANSPOSE,USEPROBABILITY,oncedone;
    int LENGTH,FUNCTIONS;

    struct RastPort *rp = &( scr->RastPort );

    CONTINUEPROBABILITY = ((double)Prefs[PREF_CONTPROB].po_Level)/100.0;
    CONTPROBDECREASE    = ((double)Prefs[PREF_DECREASE].po_Level)/100.0;
    USEPROBABILITY      = !(Prefs[PREF_AREA].po_Level);
    TRANSPOSE           = !(Prefs[PREF_TRANSPOSE].po_Level);
    LENGTH              = Prefs[PREF_ITERATIONS].po_Level;
    FUNCTIONS           = Prefs[PREF_FUNCTIONS].po_Level;
    
    while (1)
      { Move(rp,0,0);
        SetRast(rp,0);
        SetAPen(rp,1);
        ScreenToFront( scr );

        prob = CONTINUEPROBABILITY;
        oncedone = FALSE;
        while (((double)RangeRand(1000))/1000 < prob || !oncedone) {
        oncedone = TRUE;
        prob = prob - CONTPROBDECREASE;
        num = RangeRand(FUNCTIONS-2)+2;
        
        /* Compute the iterated function */
        totcomp = 0;
        { int moverand = RangeRand(4);

          /* select a move factor with the appropriate probability */
          double MOVEFACTOR;
          switch(moverand)
            { case 0: MOVEFACTOR = MOVEFACTORA; break;
              case 1: 
              case 2: MOVEFACTOR = MOVEFACTORB; break;
              case 3: MOVEFACTOR = MOVEFACTORC; break;
              default: MOVEFACTOR = MOVEFACTORB; break; /* should never happen */
            }

          /* compute the functions and their compression */
          for (k=0; k<num; k++)
              { for (i=0; i<2; i++)
                    { vv[k][i] = (FLOATRAND() - 0.5) * MOVEFACTOR;
                    }
                for (i=0; i<4; i++)
                    { aa[k][i] = (FLOATRAND() - 0.5) * SIZEFACTOR;
                    }
                comp[k] = abs(aa[k][0]*aa[k][2]-aa[k][1]*aa[k][3]);
                totcomp = totcomp + comp[k];
              }
        }

        /* and a probability distribution, eg. 
         * 2,3,1,4 -> 0.2, 0.3, 0.1, 0.4 -> 0.2, 0.5, 0.6, 1.0 */
        for (k=0; k<num; k++)
            { comp[k] = comp[k]/totcomp;
              if (k>0)
                 { comp[k] = comp[k]+comp[k-1];
                 }
            }

        comp[num-1] = 1.1; /* just to be safe of numerical errors, we increment
                            * the final probability a bit */

        /* Initialize the transpositions of the origin */
        if (TRANSPOSE)
          {
            tx = (int)(RangeRand(width/2))-width/4;
            ty = (int)(RangeRand(height/2))-height/4;
          }
        else
          { tx = ty = 0;
          }


        /* set the color for the function */
        SetAPen(rp,(int)(RangeRand(colors-1)+1));

        /* and now: compute the IFS. We do this using several iterations
         * instead of just one big step. This gives a picture which looks
         * a bit more structured. */
        for (i=0; i<(int)(LENGTH*totcomp); i++)
            { x=y=0;
              for (j=0; j<ITER; j++)
                  { double xx;

                    /* Find a function to use */
                    if (USEPROBABILITY)
                       { double p;
                         p = FLOATRAND();
                         thef = 0;
                         while (comp[thef] < p)
                           { thef++;
                           }
                       }
                    else
                       { thef = RangeRand(num);
                       }

                    /* compute (x,y) = (x,y)*aa + vv */
                    xx = (x*aa[thef][0]+y*aa[thef][1])+vv[thef][0];
                    y = (x*aa[thef][2]+y*aa[thef][3])+vv[thef][1];
                    x = xx;
                    
                    /* Convert it to a window coordinate and plot it */
                    wx = WINCO(x,width);
                    wy = WINCO(y,height);
                   
                    /* And transpose it, if necessary */
		    wx = wx + tx;
		    wy = wy + ty;
		    
		    if (wx > 0 && wx < width && wy > 0 && wy < height)
                       WritePixel(rp,wx,wy);
                  }
              ScreenToFront( scr );
              flg_end = ContinueBlanking();
              if (flg_end != OK)
		{ return flg_end;
		}
            }
        }
      }
    return flg_end;
}