本文整理汇总了C++中LRAND函数的典型用法代码示例。如果您正苦于以下问题:C++ LRAND函数的具体用法?C++ LRAND怎么用?C++ LRAND使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了LRAND函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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 = þbirds[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
示例16: Gauss_Rand
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);
}
开发者ID:RazZziel,项目名称:pongclock,代码行数:12,代码来源:strange.c
示例17: init_galaxy
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 */
}
}
开发者ID:Gelma,项目名称:xlockmore-for-13.04,代码行数:52,代码来源:galaxy.c
示例18: Gauss_Rand
/* 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;
}
}
开发者ID:david-sackmary,项目名称:distro-mods,代码行数:24,代码来源:flow.c
示例19: make_uniform_colormap
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;
}
开发者ID:Bluerise,项目名称:bitrig-xenocara,代码行数:38,代码来源:color.c
示例20: ranmod
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) ;
}
开发者ID:b1234561,项目名称:AdmixTools,代码行数:14,代码来源:gds.c
注:本文中的LRAND函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论