HIDDEN double wood_turb(double x, double y, double z, struct wood_specific *wd) { register struct resource *resp = &rt_uniresource; int i; fastf_t a, b, c, turb = 0.0, scale; for (i = 0; i < wd->ns; i++) { scale = (double)i / (double)wd->ns; a = (x * scale) + (bn_rand_half(resp->re_randptr) * wd->jitter) + wd->dither[X]; b = (y * scale) + (bn_rand_half(resp->re_randptr) * wd->jitter) + wd->dither[Y]; c = (z * scale) + (bn_rand_half(resp->re_randptr) * wd->jitter) + wd->dither[Z]; turb += wood_noise(a, b, c, wd); } return turb; }
/** * Creates one metaball object with 'count' random points using * LIBWDB's mk_metaball() interface. */ static void make_meatballs(struct rt_wdb *fp, const char *name, long count) { static float *ctx; /* random context */ static const int method = 1; /* 1==ISO */ static const fastf_t threshold = 1.0; static const fastf_t SZ = 1000.0; long i; fastf_t **pts; RT_CK_WDB(fp); bn_rand_init(ctx, rand()); bu_log("Creating [%s] object with %ld random point%s\n", name, count, count > 1 ? "s" : ""); /* allocate a dynamic array of pointers to points. this may be * subject to change but is presently the format mk_metaball() * wants. */ pts = (fastf_t **)bu_calloc(count, sizeof(fastf_t*), "alloc metaball pts array"); for (i=0; i < count; i++) { pts[i] = (fastf_t *)bu_malloc(sizeof(fastf_t)*5, "alloc metaball point"); } /* create random metaball point values positioned randomly within * a cube with random field strengths. */ for (i=0; i < count; i++) { /* just for explicit clarity */ fastf_t x = bn_rand_half(ctx) * SZ; fastf_t y = bn_rand_half(ctx) * SZ; fastf_t z = bn_rand_half(ctx) * SZ; fastf_t field_strength = bn_rand0to1(ctx) * SZ / (2.0 * sqrt(count)); VSET(pts[i], x, y, z); pts[i][3] = field_strength; /* something blobbly random */ pts[i][4] = 0.0; /* sweat/goo field is unused with iso method */ } /* pack the meat, create the metaball */ mk_metaball(fp, name, count, method, threshold, (const fastf_t **)pts); /* free up our junk */ for (i=0; i < count; i++) { bu_free(pts[i], "dealloc metaball point"); } bu_free(pts, "dealloc metaball pts array"); }
int main(int argc, char **argv) { register float *randp; struct color_rec { unsigned char red, green, blue; } cur_color; bn_rand_init( randp, 0); if ( !get_args( argc, argv ) ) { (void)fputs(usage, stderr); bu_exit ( 1, NULL ); } /* fprintf(stderr, "pixfade: max = %d, multiplier = %f\n", max, multiplier); */ for (;;) { register double t; if ( fread(&cur_color, 1, 3, inp) != 3 ) break; if ( feof(inp) ) break; t = cur_color.red * multiplier + bn_rand_half(randp); if (t > max) cur_color.red = max; else cur_color.red = t; t = cur_color.green * multiplier + bn_rand_half(randp); if (t > max) cur_color.green = max; else cur_color.green = t; t = cur_color.blue * multiplier + bn_rand_half(randp); if (t > max) cur_color.blue = max; else cur_color.blue = t; fwrite(&cur_color, 1, 3, stdout); } return 0; }
/** * Compute the origin for this ray, based upon the number of samples * per pixel and the number of the current sample. For certain * ray-counts, it is highly advantageous to subdivide the pixel and * fire each ray in a specific sub-section of the pixel. */ static void jitter_start_pt(vect_t point, struct application *a, int samplenum, int pat_num) { fastf_t dx, dy; if (pat_num >= 0) { dx = a->a_x + pt_pats[pat_num].coords[samplenum*2] + (bn_rand_half(a->a_resource->re_randptr) * pt_pats[pat_num].rand_scale[X]); dy = a->a_y + pt_pats[pat_num].coords[samplenum*2 + 1] + (bn_rand_half(a->a_resource->re_randptr) * pt_pats[pat_num].rand_scale[Y]); } else { dx = a->a_x + bn_rand_half(a->a_resource->re_randptr); dy = a->a_y + bn_rand_half(a->a_resource->re_randptr); } VJOIN2(point, viewbase_model, dx, dx_model, dy, dy_model); }