コード例 #1
0
ファイル: nose.c プロジェクト: Gelma/xlockmore-for-13.04
static int
look(ModeInfo * mi)
{
	Display    *display = MI_DISPLAY(mi);
	Window      window = MI_WINDOW(mi);

	/*GC          gc = MI_GC(mi); */
	nosestruct *np = &noses[MI_SCREEN(mi)];
	int         i;

	if (NRAND(3)) {
		i = (LRAND() & 1) ? D : F;
		XCopyArea(display, np->position[i], window, np->noseGC[i],
			  0, 0, PIXMAP_SIZE, PIXMAP_SIZE, np->x, np->y);
		return 3;
	}
	if (!NRAND(5))
		return 0;
	if (NRAND(3)) {
		i = (LRAND() & 1) ? LF : RF;
		XCopyArea(display, np->position[i], window, np->noseGC[i],
			  0, 0, PIXMAP_SIZE, PIXMAP_SIZE, np->x, np->y);
		return 3;
	}
	if (!NRAND(5))
		return 0;
	i = (LRAND() & 1) ? L : R;
	XCopyArea(display, np->position[i], window, np->noseGC[i],
		  0, 0, PIXMAP_SIZE, PIXMAP_SIZE, np->x, np->y);
	return 3;
}
コード例 #2
0
ファイル: rock.cpp プロジェクト: kthxbyte/KDE1-Linaro
void
drawrock(Window win)
{
  static int current_delta = 0;	/* observer Z rotation */
  static int window_tick = 50;
  static int new_delta = 0;
  static int dchange_tick = 0;

  if (window_tick++ == 50)
    window_tick = 0;
  if (current_delta != new_delta) {
    if (dchange_tick++ == 5) {
      dchange_tick = 0;
      if (current_delta < new_delta)
        current_delta++;
      else
        current_delta--;
    }
  } else {
    if ((LRAND() % 50) == 0) {
      new_delta = ((LRAND() % 11) - 5);
      if ((LRAND() % 10) == 0)
	new_delta *= 5;
    }
  }
  tick_rocks (win, current_delta);
}
コード例 #3
0
ファイル: glforestfire.c プロジェクト: RazZziel/pongclock
ENTRYPOINT void change_fire(ModeInfo * mi)
{
    firestruct *fs = &fire[MI_SCREEN(mi)];

    if (!fs->glx_context)
	return;

    glXMakeCurrent(MI_DISPLAY(mi), MI_WINDOW(mi), *(fs->glx_context));

    /* if available, randomly change some values */
    if (do_fog)
	fs->fog = LRAND() & 1;
    if (do_shadows)
	fs->shadows = LRAND() & 1;
    /* reset observer position */
    frame = 0;
    vinit(fs->obs, DEF_OBS[0], DEF_OBS[1], DEF_OBS[2]);
    fs->v = 0.0;
    /* particle randomisation */
    fs->eject_r = 0.1 + NRAND(10) * 0.03;
    fs->ridtri = 0.1 + NRAND(10) * 0.005;

    if (MI_IS_DEBUG(mi)) {
	(void) fprintf(stderr,
		       "%s:\n\tnum_part=%d\n\ttrees=%d\n\tfog=%s\n\tshadows=%s\n\teject_r=%.3f\n\tridtri=%.3f\n",
		       MI_NAME(mi),
		       fs->np,
		       fs->num_trees,
		       fs->fog ? "on" : "off",
		       fs->shadows ? "on" : "off",
		       fs->eject_r, fs->ridtri);
    }
}
コード例 #4
0
ファイル: thornbird.c プロジェクト: RazZziel/pongclock
ENTRYPOINT void
init_thornbird (ModeInfo * mi)
{
	thornbirdstruct *hp;

	if (thornbirds == NULL) {
		if ((thornbirds =
		     (thornbirdstruct *) calloc(MI_NUM_SCREENS(mi),
					  sizeof (thornbirdstruct))) == NULL)
			return;
	}
	hp = &thornbirds[MI_SCREEN(mi)];


	hp->maxx = MI_WIDTH(mi);
	hp->maxy = MI_HEIGHT(mi);

	hp->b = 0.1;
	hp->i = hp->j = 0.1;

	hp->pix = 0;
	hp->inc = 0;

	hp->nbuffers = MI_CYCLES(mi);

	if (hp->pointBuffer == NULL)
		if ((hp->pointBuffer = (XPoint **) calloc(MI_CYCLES(mi),
				sizeof (XPoint *))) == NULL) {
			free_thornbird(hp);
			return;
		}

	if (hp->pointBuffer[0] == NULL)
		if ((hp->pointBuffer[0] = (XPoint *) malloc(MI_COUNT(mi) *
				sizeof (XPoint))) == NULL) {
			free_thornbird(hp);
			return;
		}

	/* select frequencies for parameter variation */
	hp->liss.f1 = LRAND() % 5000;
	hp->liss.f2 = LRAND() % 2000;

	/* choose random 3D tumbling */
	hp->tumble.theta = 0;
	hp->tumble.phi = 0;
	hp->tumble.dtheta = balance_rand(0.001);
	hp->tumble.dphi = balance_rand(0.005);

	/* Clear the background. */
	MI_CLEARWINDOW(mi);

	hp->count = 0;
}
コード例 #5
0
ファイル: nose.c プロジェクト: Gelma/xlockmore-for-13.04
static int
think(ModeInfo * mi)
{
	nosestruct *np = &noses[MI_SCREEN(mi)];

	if (LRAND() & 1)
		walk(mi, FRONT);
	if (LRAND() & 1) {
		np->words = getWords(MI_SCREEN(mi), MI_NUM_SCREENS(mi));
		return 1;
	}
	return 0;
}
コード例 #6
0
ファイル: rock.cpp プロジェクト: kthxbyte/KDE1-Linaro
static void
rock_reset( Window win, arock *arocks)
{
  arocks->real_size = MAX_WIDTH;
  arocks->r = (int)((RESOLUTION * 0.7) + (LRAND() % (30 * RESOLUTION)));
  arocks->theta = LRAND() % RESOLUTION;
  arocks->depth = MAX_DEPTH * DEPTH_SCALE;
  if (!mono && Scr[screen].npixels > 2)
    arocks->color = Scr[screen].pixels[LRAND() % Scr[screen].npixels];
  else
    arocks->color = WhitePixel(dsp, screen);
  rock_compute(arocks);
  rock_draw(win, arocks, True);
}
コード例 #7
0
ファイル: goop.c プロジェクト: Bluerise/bitrig-xenocara
static void
move_blob(blob * b, int maxx, int maxy)
{
	maxx *= SCALE;
	maxy *= SCALE;

	b->x += b->dx;
	b->y += b->dy;

	/* If we've reached the edge of the box, reverse direction. */
	if ((b->x > maxx && b->dx >= 0) ||
	    (b->x < 0 && b->dx < 0)) {
		b->dx = -b->dx;
	}
	if ((b->y > maxy && b->dy >= 0) ||
	    (b->y < 0 && b->dy < 0)) {
		b->dy = -b->dy;
	}
	/* Alter velocity randomly. */
	if (!(LRAND() % 10)) {
		b->dx += (NRAND(b->max_velocity / 2) * RANDSIGN());
		b->dy += (NRAND(b->max_velocity / 2) * RANDSIGN());

		/* Throttle velocity */
		if (b->dx > b->max_velocity || b->dx < -b->max_velocity)
			b->dx /= 2;
		if (b->dy > b->max_velocity || b->dy < -b->max_velocity)
			b->dy /= 2;
	} {
		double      th = b->th;
		double      d = (b->torque == 0 ? 0 : (b->torque) * LRAND() / MAXRAND);

		if (th < 0)
			th = -(th + d);
		else
			th += d;

		if (th > (M_PI + M_PI))
			th -= (M_PI + M_PI);
		else if (th < 0)
			th += (M_PI + M_PI);

		b->th = (b->th > 0 ? th : -th);
	}

	/* Alter direction of rotation randomly. */
	if (!(LRAND() % 100))
		b->th *= -1;
}
コード例 #8
0
ファイル: gds.c プロジェクト: yiqinyang2/SOAPpop
void pick2(int n, int *k1, int *k2) 
{
 long l1 , l2 ;
 /* pick 2 distinct integers < n  */ ;
 if (n<2) fatalx("bad pick2 call\n") ;
 for (;;) {
  l1 = LRAND() ;
  l2 = LRAND() ;
  l1 = l1%n ;
  l2 = l2%n ;
  if (l1 != l2) break ;
 }
 *k1 = l1 ;
 *k2 = l2 ;
}
コード例 #9
0
ファイル: sierpinski.c プロジェクト: RazZziel/pongclock
ENTRYPOINT void
init_sierpinski(ModeInfo * mi)
{
	int         i;
	sierpinskistruct *sp;

	if (tris == NULL) {
		if ((tris = (sierpinskistruct *) calloc(MI_NUM_SCREENS(mi),
					 sizeof (sierpinskistruct))) == NULL)
			return;
	}
	sp = &tris[MI_SCREEN(mi)];

	sp->width = MI_WIDTH(mi);
	sp->height = MI_HEIGHT(mi);

	sp->total_npoints = MI_COUNT(mi);
	if (sp->total_npoints < 1)
		sp->total_npoints = 1;
	sp->corners = MI_SIZE(mi);
	if (sp->corners < 3 || sp->corners > 4) {
		sp->corners = (int) (LRAND() & 1) + 3;
	}
	for (i = 0; i < sp->corners; i++) {
		if (!sp->pointBuffer[i])
			if ((sp->pointBuffer[i] = (XPoint *) malloc(sp->total_npoints *
					sizeof (XPoint))) == NULL) {
				free_sierpinski(sp);
				return;
			}
	}
	startover(mi);
}
コード例 #10
0
ファイル: goop.c プロジェクト: Bluerise/bitrig-xenocara
static Bool
make_layer(ModeInfo * mi, layer * l, int nblobs)
{
	int         i;
	int         blob_min, blob_max;
	XGCValues   gcv;
	int         width = MI_WIDTH(mi), height = MI_HEIGHT(mi);

	l->nblobs = nblobs;

	if ((l->blobs = (blob *) calloc(l->nblobs, sizeof (blob))) == NULL)
		return False;

	blob_max = (width < height ? width : height) / 2;
	blob_min = (blob_max * 2) / 3;
	for (i = 0; i < l->nblobs; i++)
		if (!make_blob(&(l->blobs[i]), width, height, (int) (LRAND() %
				(blob_max - blob_min + 1)) + blob_min))
			return False;

	if ((l->pixmap = XCreatePixmap(MI_DISPLAY(mi), MI_WINDOW(mi),
			width, height, 1)) == None)
		return False;
	if ((l->gc = XCreateGC(MI_DISPLAY(mi), l->pixmap, 0, &gcv)) == None)
		return False;
	return True;
}
コード例 #11
0
ファイル: goop.c プロジェクト: Bluerise/bitrig-xenocara
static void
throb_blob(blob * b)
{
	int         i;
	double      frac = ((M_PI + M_PI) / b->npoints);

	for (i = 0; i < b->npoints; i++) {
		long        r = b->r[i];
		long        ra = (r > 0 ? r : -r);
		double      th = (b->th > 0 ? b->th : -b->th);
		long        x, y;

		/* place control points evenly around perimiter, shifted by theta */
		x = b->x + (long) (ra * cos(i * frac + th));
		y = b->y + (long) (ra * sin(i * frac + th));

		b->splines->control_x[i] = x / SCALE;
		b->splines->control_y[i] = y / SCALE;

		/* alter the radius by a random amount, in the direction in which
		   it had been going (the sign of the radius indicates direction.) */
		ra += (NRAND(b->elasticity) * (r > 0 ? 1 : -1));
		r = ra * (r >= 0 ? 1 : -1);

		/* If we've reached the end (too long or too short) reverse direction. */
		if ((ra > b->max_r && r >= 0) ||
		    (ra < b->min_r && r < 0))
			r = -r;
		/* And reverse direction in mid-course once every 50 times. */
		else if (!(LRAND() % 50))
			r = -r;

		b->r[i] = r;
	}
}
コード例 #12
0
ファイル: swarm.cpp プロジェクト: kthxbyte/KDE1-Linaro
void
initswarm(Window win)
{
	swarmstruct *sp = &swarms[screen];
	int         b;
	XWindowAttributes xwa;

	sp->beecount = batchcount;
	(void) XGetWindowAttributes(dsp, win, &xwa);
	sp->width = xwa.width;
	sp->height = xwa.height;

	sp->border = (sp->width + sp->height) / 50;

	/* Clear the background. */
	XSetForeground(dsp, Scr[screen].gc, BlackPixel(dsp, screen));
	XFillRectangle(dsp, win, Scr[screen].gc, 0, 0, sp->width, sp->height);

	/*  Now static data structures. epirker */
	//if (!sp->segs) {
	//sp->segs = (XSegment *) malloc(sizeof (XSegment) * sp->beecount);
	//sp->old_segs = (XSegment *) malloc(sizeof (XSegment) * sp->beecount);
	//sp->x = (short *) malloc(sizeof (short) * sp->beecount * TIMES);
	//sp->y = (short *) malloc(sizeof (short) * sp->beecount * TIMES);
	//sp->xv = (short *) malloc(sizeof (short) * sp->beecount);
	//sp->yv = (short *) malloc(sizeof (short) * sp->beecount);
	//}
	/* Initialize point positions, velocities, etc. */

	/* wasp */
	sp->wx[0] = sp->border + LRAND() % (sp->width - 2 * sp->border);
	sp->wy[0] = sp->border + LRAND() % (sp->height - 2 * sp->border);
	sp->wx[1] = sp->wx[0];
	sp->wy[1] = sp->wy[0];
	sp->wxv = 0;
	sp->wyv = 0;

	/* bees */
	for (b = 0; b < sp->beecount; b++) {
		X(0, b) = LRAND() % sp->width;
		X(1, b) = X(0, b);
		Y(0, b) = LRAND() % sp->height;
		Y(1, b) = Y(0, b);
		sp->xv[b] = balance_rand(7);
		sp->yv[b] = balance_rand(7);
	}
}
コード例 #13
0
ファイル: rock.cpp プロジェクト: kthxbyte/KDE1-Linaro
static int
compute_move(int axe)
//  int axe; /* 0 for x, 1 for y */
{
  static int current_dep[2] = {0,0};
  static int speed[2]       = {0,0};
  static short direction[2] = {0,0};
  static int limit[2]       = {0,0};
  rockstruct *rp = &rocks[screen];
  int change = 0;
  
  limit[0] = rp->midx;
  limit[1] = rp->midy;

  current_dep[axe] += speed[axe]; /* We adjust the displacement */

  if (current_dep[axe] > (int)(limit[axe] * MAX_DEP)) {
    if (current_dep[axe] > limit[axe]) current_dep[axe] = limit[axe];
    direction[axe] = -1;
  }/* This is when we reach the upper screen limit */
  if (current_dep[axe] < (int)(-limit[axe] * MAX_DEP)) {
    if (current_dep[axe] < -limit[axe]) current_dep[axe] = -limit[axe];
    direction[axe] = 1;
  }/* This is when we reach the lower screen limit */

  if (direction[axe] == 1)/* We adjust the speed */
    speed[axe] += 1;
  else if (direction[axe] == -1)
    speed[axe] -= 1;

  if (speed[axe] > maxDepSpeed)
    speed[axe] = maxDepSpeed;
  else if (speed[axe] < -maxDepSpeed)
    speed[axe] = -maxDepSpeed;

  if((LRAND() % DIRECTION_CHANGE_RATE) == 0){
    /* We change direction */
    change = LRAND() & 1;
    if (change != 1)
      if (direction[axe] == 0)
	direction[axe] = change - 1; /* 0 becomes either 1 or -1 */
      else
	direction[axe] = 0; /* -1 or 1 become 0 */
  }
  return(current_dep[axe]);
}
コード例 #14
0
ファイル: blot.c プロジェクト: Bluerise/bitrig-xenocara
void
init_blot(ModeInfo * mi)
{
	Display    *display = MI_DISPLAY(mi);
	blotstruct *bp;

	if (blots == NULL) {
		if ((blots = (blotstruct *) calloc(MI_NUM_SCREENS(mi),
					       sizeof (blotstruct))) == NULL)
			return;
	}
	bp = &blots[MI_SCREEN(mi)];

	bp->width = MI_WIDTH(mi);
	bp->height = MI_HEIGHT(mi);
	bp->xmid = bp->width / 2;
	bp->ymid = bp->height / 2;

	bp->offset = 4;
	bp->ysym = (int) LRAND() & 1;
	bp->xsym = (bp->ysym) ? (int) LRAND() & 1 : 1;
	if (MI_NPIXELS(mi) > 2)
		bp->pix = NRAND(MI_NPIXELS(mi));
	if (bp->offset <= 0)
		bp->offset = 3;
	if (MI_COUNT(mi) < 0)
		bp->size = NRAND(-MI_COUNT(mi) + 1);
	else
		bp->size = MI_COUNT(mi);

	/* Fudge the size so it takes up the whole screen */
	bp->size *= (bp->width / 32 + 1) * (bp->height / 32 + 1);
	if (!bp->pointBuffer || bp->pointBufferSize < bp->size * sizeof (XPoint)) {
		if (bp->pointBuffer != NULL)
			free(bp->pointBuffer);
		bp->pointBufferSize = bp->size * sizeof (XPoint);
		if ((bp->pointBuffer = (XPoint *) malloc(bp->pointBufferSize)) ==
				NULL) {
			return;
		}
	}
	MI_CLEARWINDOW(mi);
	XSetForeground(display, MI_GC(mi), MI_WHITE_PIXEL(mi));
	bp->count = 0;
}
コード例 #15
0
ファイル: gds.c プロジェクト: yiqinyang2/SOAPpop
int ranmod(int n) 
/* random number 0,...n-1 */
{

  long r, big ;
  big = (2 << 29) - 1 ; 
  r = LRAND() ;
  r %= big ;
  return (r % n) ;

}
コード例 #16
0
ファイル: strange.c プロジェクト: RazZziel/pongclock
static      DBL
Gauss_Rand(DBL c, DBL A, DBL S)
{
	DBL         y;

	y = (DBL) LRAND() / MAXRAND;
	y = A * (1.0 - exp(-y * y * S)) / (1.0 - exp(-S));
	if (NRAND(2))
		return (c + y);
	else
		return (c - y);
}
コード例 #17
0
ファイル: galaxy.c プロジェクト: Gelma/xlockmore-for-13.04
void
init_galaxy(ModeInfo * mi)
{
	Display *display = MI_DISPLAY(mi);
	unistruct  *gp;

	if (universes == NULL) {
		if ((universes = (unistruct *) calloc(MI_NUM_SCREENS(mi),
						sizeof (unistruct))) == NULL)
			return;
	}
	gp = &universes[MI_SCREEN(mi)];

	gp->f_hititerations = MI_CYCLES(mi);

	gp->clip.left = 0;
	gp->clip.top = 0;
	gp->clip.right = MI_WIDTH(mi);
	gp->clip.bottom = MI_HEIGHT(mi);

	gp->scale = (double) (gp->clip.right + gp->clip.bottom) / 8.0;
	gp->midx = gp->clip.right / 2;
	gp->midy = gp->clip.bottom / 2;

	if (MI_IS_FULLRANDOM(mi)) {
		gp->fisheye = !(NRAND(3));
		if (!gp->fisheye)
			gp->tracks = (Bool) (LRAND() & 1);
	} else {
		gp->fisheye = fisheye;
		gp->tracks = tracks;
	}

	if (!startover(mi))
		return;
	if (gp->fisheye) {
		if (gp->pixmap != None)
			XFreePixmap(display, gp->pixmap);
		if ((gp->pixmap = XCreatePixmap(display, MI_WINDOW(mi),
				MI_WIDTH(mi), MI_HEIGHT(mi),
				MI_DEPTH(mi))) == None) {
			gp->fisheye = False;
		}
	}
	if (gp->fisheye) {
	        XSetGraphicsExposures(display, MI_GC(mi), False);
		gp->scale *= Z_OFFSET;
		gp->star_scale_Z = (gp->scale  * .005);
		 /* don't want any exposure events from XCopyPlane */
	}

}
コード例 #18
0
ファイル: flow.c プロジェクト: david-sackmary/distro-mods
/* Note this generates a pair of gaussian variables, so it saves one
   to give out next time it's called */
static double
Gauss_Rand(double A)
{
	static double d;
	static Bool ready = 0;
	if(ready) {
		ready = 0;
		return A/3 * d;
	} else {
		double x, y, w;		
		do {
			x = 2.0 * (double)LRAND() / MAXRAND - 1.0;
			y = 2.0 * (double)LRAND() / MAXRAND - 1.0;
			w = x*x + y*y;
		} while(w >= 1.0);

		w = sqrt((-2 * log(w))/w);
		ready = 1;		
		d =          x * w;
		return A/3 * y * w;
	}
}
コード例 #19
0
ファイル: color.c プロジェクト: Bluerise/bitrig-xenocara
void
make_uniform_colormap(ModeInfo * mi, Colormap cmap,
		      XColor * colors, int *ncolorsP,
		      Bool allocate_p,
		      Bool * writable_pP)
{
	int         ncolors = *ncolorsP;
	Bool        wanted_writable = (allocate_p && writable_pP && *writable_pP);

	double      S = ((double) (LRAND() % 34) + 66) / 100.0;		/* range 66%-100% */
	double      V = ((double) (LRAND() % 34) + 66) / 100.0;		/* range 66%-100% */

	if (*ncolorsP <= 0)
		return;

	/* If this visual doesn't support writable cells, don't bother trying. */
	if (wanted_writable && !has_writable_cells(mi))
		*writable_pP = False;

      RETRY_NON_WRITABLE:
	make_color_ramp(MI_DISPLAY(mi), cmap,
			0, S, V,
			359, S, V,
			colors, &ncolors,
			False, True, wanted_writable);

	/* If we tried for writable cells and got none, try for non-writable. */
	if (allocate_p && *ncolorsP == 0 && writable_pP && *writable_pP) {
		ncolors = *ncolorsP;
		*writable_pP = False;
		goto RETRY_NON_WRITABLE;
	}
	if (MI_IS_VERBOSE(mi) || MI_IS_DEBUG(mi))
		complain(*ncolorsP, ncolors, wanted_writable,
			 wanted_writable && *writable_pP);

	*ncolorsP = ncolors;
}
コード例 #20
0
ファイル: gds.c プロジェクト: b1234561/AdmixTools
int ranmod(int n) 
/* random number 0,...n-1 */
{

  long r, big ;

  if (n==0) fatalx("ranmod(0) called\n") ;
  if (n==1) return 0 ;
  big = (2 << 29) - 1 ; 
  r = LRAND() ;
  r %= big ;
  return (r % n) ;

}
コード例 #21
0
ファイル: goop.c プロジェクト: Bluerise/bitrig-xenocara
static Bool
make_blob(blob * b, int maxx, int maxy, int size)
{
	int         i;
	long        mid;

	maxx *= SCALE;
	maxy *= SCALE;
	size *= SCALE;

	b->max_r = size / 2;
	b->min_r = size / 10;

	if (b->min_r < (5 * SCALE))
		b->min_r = (5 * SCALE);
	mid = ((b->min_r + b->max_r) / 2);

	b->torque = 0.0075;	/* torque init */
	b->elasticity = (long) (SCALE * 1.8);	/* elasticity init */
	b->max_velocity = (long) (SCALE * 1.2);		/* max_velocity init */

	b->x = NRAND(maxx);
	b->y = NRAND(maxy);

	b->dx = NRAND(b->max_velocity) * RANDSIGN();
	b->dy = NRAND(b->max_velocity) * RANDSIGN();
	b->th = (2.0 * M_PI) * LRAND() / MAXRAND * RANDSIGN();
	b->npoints = (int) (LRAND() % 5) + 5;

	b->splines = make_spline(b->npoints);
	if ((b->r = (long *) malloc(sizeof (*b->r) * b->npoints)) == NULL)
		return False;
	for (i = 0; i < b->npoints; i++)
		b->r[i] = ((LRAND() % mid) + (mid / 2)) * RANDSIGN();
	return True;
}
コード例 #22
0
ファイル: gds.c プロジェクト: yiqinyang2/SOAPpop
void ranperm (int *a, int n) 
/** 
 a must be initialized say by idperm 
*/
{
  int l,k,tmp  ;
  long r ;
  for (l=n; l>1 ; l--)  {

   r = LRAND() ;
   k = r % l ;
/* now swap k and l-1 */ 
   tmp = a[l-1] ;  a[l-1]=a[k] ;  a[k] = tmp ;

  }
}
コード例 #23
0
static void
RandomSoup(ModeInfo * mi)
{
	demonstruct *dp = &demons[MI_SCREEN(mi)];
	int         row, col, mrow = 0;

	for (row = 0; row < dp->nrows; ++row) {
		for (col = 0; col < dp->ncols; ++col) {
			dp->oldcell[col + mrow] =
				(unsigned char) LRAND() % ((unsigned char) dp->states);
			if (!addtolist(mi, col, row, dp->oldcell[col + mrow]))
				return; /* sparse soup */
		}
		mrow += dp->ncols;
	}
}
コード例 #24
0
ファイル: tik_tak.c プロジェクト: Bluerise/bitrig-xenocara
void
draw_tik_tak(ModeInfo * mi)
{
	Display    *display = MI_DISPLAY(mi);
	int         i;
	tik_takstruct *tiktak;

	if (tik_taks == NULL)
		return;
	tiktak = &tik_taks[MI_SCREEN(mi)];
	if (tiktak->object == NULL)
		return;

	if (tiktak->no_colors) {
		free_tik_tak(display, tiktak);
		init_tik_tak(mi);
		return;
	}
	tiktak->painted = True;
	MI_IS_DRAWN(mi) = True;
	XSetFunction(display, tiktak->gc, GXxor);

/* Rotate colours */
	if (tiktak->cycle_p) {
		rotate_colors(display, tiktak->cmap, tiktak->colors, tiktak->ncolors,
			      tiktak->direction);
		if (!(LRAND() % 1000))
			tiktak->direction = -tiktak->direction;
	}
	for (i = 0; i < tiktak->num_object; i++) {
		tik_takobject *object0;

		object0 = &tiktak->object[i];
		if (MI_IS_INSTALL(mi) && MI_NPIXELS(mi) > 2) {
			XSetForeground(display, tiktak->gc, tiktak->colors[object0->colour].pixel);
		} else {
			XSetForeground(display, tiktak->gc, object0->colour);
		}
		object0->velocity_a += ((float) NRAND(1001) - 500.0) / 200000.0;
		object0->angle += object0->velocity_a;
		object0->velocity_a1 += ((float) NRAND(1001) - 500.0) / 200000.0;
		object0->angle1 += object0->velocity_a1;
		tik_tak_setupobject( mi , object0);
		tik_tak_drawobject(mi, object0 );
	}
	XSetFunction(display, tiktak->gc, GXcopy);
}
コード例 #25
0
ファイル: petal.c プロジェクト: Bluerise/bitrig-xenocara
void
init_petal(ModeInfo * mi)
{
	petalstruct *pp;

	if (petals == NULL) {
		if ((petals = (petalstruct *) calloc(MI_NUM_SCREENS(mi),
					      sizeof (petalstruct))) == NULL)
			return;
	}
	pp = &petals[MI_SCREEN(mi)];

	pp->lines = MI_COUNT(mi);
	if (pp->lines > MAXLINES)
		pp->lines = MAXLINES;
	else if (pp->lines < -MINLINES) {
		if (pp->points) {
			free(pp->points);
			pp->points = (XPoint *) NULL;
		}
		pp->lines = NRAND(-pp->lines - MINLINES + 1) + MINLINES;
	} else if (pp->lines < MINLINES)
		pp->lines = MINLINES;
	if (!pp->points)
		if ((pp->points = (XPoint *) malloc((pp->lines + 1) *
				sizeof (XPoint))) == NULL) {
			return;
		}
	pp->width = MI_WIDTH(mi);
	pp->height = MI_HEIGHT(mi);

	pp->time = 0;
	if (MI_IS_FULLRANDOM(mi))
		pp->wireframe = (Bool) (LRAND() & 1);
	else
		pp->wireframe = MI_IS_WIREFRAME(mi);

	MI_CLEARWINDOW(mi);
	pp->painted = False;

	random_petal(mi);
}
コード例 #26
0
ファイル: coral.c プロジェクト: sofuture/bitrig-xenocara
/*-
 * returns 2 bits of randomness (conserving calls to LRAND()).
 * This speeds things up a little, but not a lot (5-10% or so.)
 */
static int
rand_2(void)
{
    static int  i = 0;
    static int  r = 0;

    if (i) {
        i--;
    } else {
        i = 15;
        r = (int) LRAND();
    }

    {
        register int j = (r & 3);

        r = r >> 2;
        return j;
    }
}
コード例 #27
0
ファイル: rock.cpp プロジェクト: kthxbyte/KDE1-Linaro
static void
rock_tick ( Window win, arock *arocks, int d)
{
  rockstruct *rp = &rocks[screen];

  if (arocks->depth > 0) {
    rock_draw(win, arocks, False);
    arocks->depth -= rp->speed;
    if (rp->rotate_p)
      arocks->theta = (arocks->theta + d) % RESOLUTION;
    while (arocks->theta < 0)
      arocks->theta += RESOLUTION;
      if (arocks->depth < (MIN_DEPTH * DEPTH_SCALE))
	arocks->depth = 0;
      else {
	rock_compute(arocks);
	rock_draw(win, arocks, True);
      }
  } else if ((LRAND() % 40) == 0)
    rock_reset(win, arocks);
}
コード例 #28
0
ファイル: atlantis.c プロジェクト: mmarseglia/xscreensaver
static void
InitFishs(atlantisstruct * ap)
{
	int         i;

	for (i = 0; i < ap->num_sharks; i++) {
		ap->sharks[i].x = 70000.0 + NRAND(ap->sharksize);
		ap->sharks[i].y = NRAND(ap->sharksize);
		ap->sharks[i].z = NRAND(ap->sharksize);
		ap->sharks[i].psi = NRAND(360) - 180.0;
		ap->sharks[i].v = 1.0;
	}

	/* Random whale direction */
	ap->whaledir = LRAND() & 1;

	ap->dolph.x = 30000.0;
	ap->dolph.y = 0.0;
	ap->dolph.z = (float) (ap->sharksize);
	ap->dolph.psi = (ap->whaledir) ? 90.0 : -90.0;
	ap->dolph.theta = 0.0;
	ap->dolph.v = 6.0;

	ap->momWhale.x = 70000.0;
	ap->momWhale.y = 0.0;
	ap->momWhale.z = 0.0;
	ap->momWhale.psi = (ap->whaledir) ? 90.0 : -90.0;
	ap->momWhale.theta = 0.0;
	ap->momWhale.v = 3.0;

	ap->babyWhale.x = 60000.0;
	ap->babyWhale.y = -2000.0;
	ap->babyWhale.z = -2000.0;
	ap->babyWhale.psi = (ap->whaledir) ? 90.0 : -90.0;
	ap->babyWhale.theta = 0.0;
	ap->babyWhale.v = 3.0;
}
コード例 #29
0
ファイル: braid.c プロジェクト: HorseloverFat/xscreensaver
ENTRYPOINT void
init_braid(ModeInfo * mi)
{
	braidtype  *braid;
	int         used[MAXSTRANDS];
	int         i, count, comp, c;
	float       min_length;

	if (braids == NULL) {
		if ((braids = (braidtype *) calloc(MI_NUM_SCREENS(mi),
						sizeof (braidtype))) == NULL)
			return;
	}
	braid = &braids[MI_SCREEN(mi)];

	braid->center_x = MI_WIDTH(mi) / 2;
	braid->center_y = MI_HEIGHT(mi) / 2;
	braid->age = 0;

	/* jwz: go in the other direction sometimes. */
	braid->color_direction = ((LRAND() & 1) ? 1 : -1);

#ifndef STANDALONE
	MI_CLEARWINDOW(mi);
#endif

	min_length = (braid->center_x > braid->center_y) ?
		braid->center_y : braid->center_x;
	braid->min_radius = min_length * 0.30;
	braid->max_radius = min_length * 0.90;

	if (MI_COUNT(mi) < MINSTRANDS)
		braid->nstrands = MINSTRANDS;
	else
		braid->nstrands = INTRAND(MINSTRANDS,
				       MAX(MIN(MIN(MAXSTRANDS, MI_COUNT(mi)),
					       (int) ((braid->max_radius - braid->min_radius) / 5.0)), MINSTRANDS));
	braid->braidlength = INTRAND(MINLENGTH, MIN(MAXLENGTH, braid->nstrands * 6));

	for (i = 0; i < braid->braidlength; i++) {
		braid->braidword[i] =
			INTRAND(1, braid->nstrands - 1) * (INTRAND(1, 2) * 2 - 3);
		if (i > 0)
			while (braid->braidword[i] == -braid->braidword[i - 1])
				braid->braidword[i] = INTRAND(1, braid->nstrands - 1) * (INTRAND(1, 2) * 2 - 3);
	}

	while (braid->braidword[0] == -braid->braidword[braid->braidlength - 1])
		braid->braidword[braid->braidlength - 1] =
			INTRAND(1, braid->nstrands - 1) * (INTRAND(1, 2) * 2 - 3);

	do {
		(void) memset((char *) used, 0, sizeof (used));
		count = 0;
		for (i = 0; i < braid->braidlength; i++)
			used[ABS(braid->braidword[i])]++;
		for (i = 0; i < braid->nstrands; i++)
			count += (used[i] > 0) ? 1 : 0;
		if (count < braid->nstrands - 1) {
			braid->braidword[braid->braidlength] =
				INTRAND(1, braid->nstrands - 1) * (INTRAND(1, 2) * 2 - 3);
			while (braid->braidword[braid->braidlength] ==
			       -braid->braidword[braid->braidlength - 1] &&
			       braid->braidword[0] == -braid->braidword[braid->braidlength])
				braid->braidword[braid->braidlength] =
					INTRAND(1, braid->nstrands - 1) * (INTRAND(1, 2) * 2 - 3);
			braid->braidlength++;
		}
	} while (count < braid->nstrands - 1 && braid->braidlength < MAXLENGTH);

	braid->startcolor = (MI_NPIXELS(mi) > 2) ?
		(float) NRAND(MI_NPIXELS(mi)) : 0.0;
	/* XSetLineAttributes (display, MI_GC(mi), 2, LineSolid, CapRound,
	   JoinRound); */

	(void) memset((char *) braid->components, 0, sizeof (braid->components));
	c = 1;
	comp = 0;
	braid->components[0] = 1;
	do {
		i = comp;
		do {
			i = applyword(braid, i, 0);
			braid->components[i] = braid->components[comp];
		} while (i != comp);
		count = 0;
		for (i = 0; i < braid->nstrands; i++)
			if (braid->components[i] == 0)
				count++;
		if (count > 0) {
			for (comp = 0; braid->components[comp] != 0; comp++);
			braid->components[comp] = ++c;
		}
	} while (count > 0);

	braid->linewidth = MI_SIZE(mi);

	if (braid->linewidth < 0)
		braid->linewidth = NRAND(-braid->linewidth) + 1;
	if (braid->linewidth * braid->linewidth * 8 > MIN(MI_WIDTH(mi), MI_HEIGHT(mi)))
       braid->linewidth = MIN(1, (int) sqrt((double) MIN(MI_WIDTH(mi), MI_HEIGHT(mi)) / 8));
	for (i = 0; i < braid->nstrands; i++)
		if (!(braid->components[i] & 1))
			braid->components[i] *= -1;
}
コード例 #30
0
ファイル: rotator.c プロジェクト: Bluerise/bitrig-xenocara
static void
rotate_1 (double *pos, double *v, double *dv, double speed, double max_v)
{
  double ppos = *pos;

  if (speed == 0) return;

  /* tick position */
  if (ppos < 0)
    ppos = -(ppos + *v);
  else
    ppos += *v;

  if (ppos > 1.0)
    ppos -= 1.0;
  else if (ppos < 0)
    ppos += 1.0;

  if (ppos < 0) abort();
  if (ppos > 1.0) abort();
  *pos = (*pos > 0 ? ppos : -ppos);

  /* accelerate */
  *v += *dv;

  /* clamp velocity */
  if (*v > max_v || *v < -max_v)
    {
      *dv = -*dv;
    }
  /* If it stops, start it going in the other direction. */
  else if (*v < 0)
    {
      if (LRAND() % 4)
	{
	  *v = 0;

	  /* keep going in the same direction */
	  if (LRAND() % 2)
	    *dv = 0;
	  else if (*dv < 0)
	    *dv = -*dv;
	}
      else
	{
	  /* reverse gears */
	  *v = -*v;
	  *dv = -*dv;
	  *pos = -*pos;
	}
    }

  /* Alter direction of rotational acceleration randomly. */
  if (! (LRAND() % 120))
    *dv = -*dv;

  /* Change acceleration very occasionally. */
  if (! (LRAND() % 200))
    {
      if (*dv == 0)
	*dv = 0.00001;
      else if (LRAND() & 1)
	*dv *= 1.2;
      else
	*dv *= 0.8;
    }
}