当前位置: 首页>>代码示例>>C++>>正文


C++ LRAND函数代码示例

本文整理汇总了C++中LRAND函数的典型用法代码示例。如果您正苦于以下问题:C++ LRAND函数的具体用法?C++ LRAND怎么用?C++ LRAND使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了LRAND函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: look

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;
}
开发者ID:Gelma,项目名称:xlockmore-for-13.04,代码行数:31,代码来源:nose.c

示例2: drawrock

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);
}
开发者ID:kthxbyte,项目名称:KDE1-Linaro,代码行数:27,代码来源:rock.cpp

示例3: change_fire

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);
    }
}
开发者ID:RazZziel,项目名称:pongclock,代码行数:33,代码来源:glforestfire.c

示例4: init_thornbird

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;
}
开发者ID:RazZziel,项目名称:pongclock,代码行数:54,代码来源:thornbird.c

示例5: think

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;
}
开发者ID:Gelma,项目名称:xlockmore-for-13.04,代码行数:13,代码来源:nose.c

示例6: rock_reset

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);
}
开发者ID:kthxbyte,项目名称:KDE1-Linaro,代码行数:14,代码来源:rock.cpp

示例7: move_blob

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;
}
开发者ID:Bluerise,项目名称:bitrig-xenocara,代码行数:49,代码来源:goop.c

示例8: pick2

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 ;
}
开发者ID:yiqinyang2,项目名称:SOAPpop,代码行数:15,代码来源:gds.c

示例9: init_sierpinski

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);
}
开发者ID:RazZziel,项目名称:pongclock,代码行数:33,代码来源:sierpinski.c

示例10: make_layer

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;
}
开发者ID:Bluerise,项目名称:bitrig-xenocara,代码行数:27,代码来源:goop.c

示例11: throb_blob

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;
	}
}
开发者ID:Bluerise,项目名称:bitrig-xenocara,代码行数:35,代码来源:goop.c

示例12: initswarm

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);
	}
}
开发者ID:kthxbyte,项目名称:KDE1-Linaro,代码行数:47,代码来源:swarm.cpp

示例13: compute_move

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]);
}
开发者ID:kthxbyte,项目名称:KDE1-Linaro,代码行数:46,代码来源:rock.cpp

示例14: init_blot

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;
}
开发者ID:Bluerise,项目名称:bitrig-xenocara,代码行数:45,代码来源:blot.c

示例15: ranmod

int ranmod(int n) 
/* random number 0,...n-1 */
{

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

}
开发者ID:yiqinyang2,项目名称:SOAPpop,代码行数:11,代码来源:gds.c


注:本文中的LRAND函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。