void MI_CALL Datetime_EnumerateInstances( Datetime_Self* self, MI_Context* context, const MI_Char* nameSpace, const MI_Char* className, const MI_PropertySet* propertySet, MI_Boolean keysOnly, const MI_Filter* filter) { Datetime inst; Datetime_Construct(&inst, context); MI_Datetime iv; MI_Datetime ts; memset(&ts, 0, sizeof(ts)); ts.isTimestamp = MI_TRUE; ts.u.timestamp.year = 2001; ts.u.timestamp.month = 12; ts.u.timestamp.month = 25; memset(&iv, 0, sizeof(iv)); iv.isTimestamp = MI_FALSE; iv.u.interval.days = 365; iv.u.interval.hours = 24; iv.u.interval.minutes = 60; // Datetime.timestamp: Datetime_Set_timestamp(&inst, ts); // Datetime.timestamp: Datetime_Set_interval(&inst, iv); // Datetime.timestamps: { MI_Datetime data[2]; data[0] = ts; data[1] = ts; Datetime_Set_timestamps(&inst, data, MI_COUNT(data)); } // Datetime.interval: { MI_Datetime data[2]; data[0] = iv; data[1] = iv; Datetime_Set_intervals(&inst, data, MI_COUNT(data)); } // Datetime.interval: { MI_Datetime data[2]; data[0] = ts; data[1] = iv; Datetime_Set_mixed(&inst, data, MI_COUNT(data)); } Datetime_Post(&inst, context); MI_PostResult(context, MI_RESULT_OK); }
void init_morph3d(ModeInfo * mi) { morph3dstruct *mp; if (morph3d == NULL) { if ((morph3d = (morph3dstruct *) calloc(MI_NUM_SCREENS(mi), sizeof (morph3dstruct))) == NULL) return; } mp = &morph3d[MI_SCREEN(mi)]; mp->step = NRAND(90); mp->VisibleSpikes = 1; if ((mp->glx_context = init_GL(mi)) != NULL) { reshape_morph3d(mi, MI_WIDTH(mi), MI_HEIGHT(mi)); glDrawBuffer(GL_BACK); mp->object = MI_COUNT(mi); if (mp->object <= 0 || mp->object > 5) mp->object = NRAND(5) + 1; pinit(mi); } else { MI_CLEARWINDOW(mi); } }
static void draw_spikes (ModeInfo *mi) { ball_configuration *bp = &bps[MI_SCREEN(mi)]; GLfloat diam = 0.2; GLfloat pos = bp->pos; int i; if (pos < 0) pos = -pos; pos = (asin (0.5 + pos/2) - 0.5) * 2; for (i = 0; i < MI_COUNT(mi); i++) { glPushMatrix(); glRotatef(bp->spikes[i*2], 0, 1, 0); glRotatef(bp->spikes[i*2+1], 0, 0, 1); glTranslatef(0.7, 0, 0); glRotatef(-90, 0, 0, 1); glScalef (diam, pos, diam); glCallList (bp->spike_list); glPopMatrix(); mi->polygon_count += (SPIKE_FACES + 1); } }
/* Calculate new positions for all images. */ static void set_new_positions(photopile_state *ss) { ModeInfo *mi = ss->mi; int i; for (i = 0; i < MI_COUNT(mi)+1; ++i) { image *frame = ss->frames + i; GLfloat w = frame->w; GLfloat h = frame->h; GLfloat d = sqrt(w*w + h*h); GLfloat leave = frand(M_PI * 2.0); GLfloat enter = frand(M_PI * 2.0); /* start position */ frame->pos[0] = frame->pos[3]; /* end position */ frame->pos[3].x = BELLRAND(MI_WIDTH(mi)); frame->pos[3].y = BELLRAND(MI_HEIGHT(mi)); frame->pos[3].angle = (frand(2.0) - 1.0) * max_tilt; /* Try to keep the images mostly inside the screen bounds */ frame->pos[3].x = MAX(0.5*w, MIN(MI_WIDTH(mi)-0.5*w, frame->pos[3].x)); frame->pos[3].y = MAX(0.5*h, MIN(MI_HEIGHT(mi)-0.5*h, frame->pos[3].y)); /* intermediate points */ frame->pos[1] = offset_pos(frame->pos[0], leave, d * (0.5 + frand(1.0))); frame->pos[2] = offset_pos(frame->pos[3], enter, d * (0.5 + frand(1.0))); } }
void draw_puzzle(ModeInfo * mi) { puzzlestruct *pp; if (puzzles == NULL) return; pp = &puzzles[MI_SCREEN(mi)]; if (pp->fixbuff == NULL) return; MI_IS_DRAWN(mi) = True; pp->painted = False; if (pp->movingBox) { if (moveboxdelta(mi)) { wrapupmovedelta(mi); wrapupmove(mi); pp->movingBox = False; if (pp->moves++ > 2 * MI_COUNT(mi)) init_puzzle(mi); } } else { if (setupmove(mi)) { setupmovedelta(mi); pp->movingBox = True; } } }
ENTRYPOINT void init_lisa (ModeInfo * mi) { int lctr; lisacons *lc; if (Lisa == NULL) { if ((Lisa = (lisacons *) calloc(MI_NUM_SCREENS(mi), sizeof (lisacons))) == NULL) return; } lc = &Lisa[MI_SCREEN(mi)]; lc->width = MI_WIDTH(mi); lc->height = MI_HEIGHT(mi); lc->loopcount = 0; lc->nlissajous = MI_COUNT(mi); if (lc->nlissajous <= 0) lc->nlissajous = 1; MI_CLEARWINDOW(mi); lc->painted = False; if (lc->lissajous == NULL) { if ((lc->lissajous = (lisas *) calloc(lc->nlissajous, sizeof (lisas))) == NULL) return; for (lctr = 0; lctr < lc->nlissajous; lctr++) { if (!initlisa(mi, &lc->lissajous[lctr])) return; lc->loopcount++; } } else { refreshlisa(mi); } }
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); }
ENTRYPOINT void draw_hydrostat (ModeInfo *mi) { hydrostat_configuration *bp = &bps[MI_SCREEN(mi)]; Display *dpy = MI_DISPLAY(mi); Window window = MI_WINDOW(mi); int i; if (!bp->glx_context) return; glXMakeCurrent(MI_DISPLAY(mi), MI_WINDOW(mi), *(bp->glx_context)); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glPushMatrix (); glScalef (0.03, 0.03, 0.03); # ifdef USE_TRACKBALL gltrackball_rotate (bp->trackball); # endif mi->polygon_count = 0; if (opacity_arg < 1.0) qsort (bp->squids, MI_COUNT(mi), sizeof(*bp->squids), cmp_squid); for (i = 0; i < MI_COUNT(mi); i++) { squid *sq = bp->squids[i]; move_squid (mi, sq); draw_squid (mi, sq); if (opacity_arg < 1.0) glClear (GL_DEPTH_BUFFER_BIT); } if (! (random() % 700)) /* Reverse the flow every now and then */ current_arg = -current_arg; glPopMatrix (); if (mi->fps_p) do_fps (mi); glFinish(); glXSwapBuffers(dpy, window); }
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; }
ENTRYPOINT void init_fire(ModeInfo * mi) { firestruct *fs; /* allocate the main fire table if needed */ if (fire == NULL) { if ((fire = (firestruct *) calloc(MI_NUM_SCREENS(mi), sizeof(firestruct))) == NULL) return; } /* initialise the per screen fire structure */ fs = &fire[MI_SCREEN(mi)]; fs->np = MI_COUNT(mi); fs->fog = do_fog; fs->shadows = do_shadows; /* initialise fire particles if any */ if ((fs->np)&&(fs->p == NULL)) { if ((fs->p = (part *) calloc(fs->np, sizeof(part))) == NULL) { free_fire(fs); return; } } else if (fs->r == NULL) { /* initialise rain particles if no fire particles */ if ((fs->r = (rain *) calloc(NUMPART, sizeof(part))) == NULL) { free_fire(fs); return; } } /* check tree number */ if (do_texture) fs->num_trees = (num_trees<MAX_TREES)?num_trees:MAX_TREES; else fs->num_trees = 0; fs->trackball = gltrackball_init (); /* xlock GL stuff */ if ((fs->glx_context = init_GL(mi)) != NULL) { #ifndef STANDALONE Reshape(mi); /* xlock mode */ #else reshape_fire(mi,MI_WIDTH(mi),MI_HEIGHT(mi)); /* xscreensaver mode */ #endif glDrawBuffer(GL_BACK); if (!Init(mi)) { free_fire(fs); return; } } else { MI_CLEARWINDOW(mi); } }
static Bool load_initial_images (ModeInfo *mi) { carousel_state *ss = &sss[MI_SCREEN(mi)]; int i; Bool all_loaded_p = True; for (i = 0; i < ss->nframes; i++) if (! ss->frames[i]->loaded_p) all_loaded_p = False; if (all_loaded_p) { if (ss->nframes < MI_COUNT (mi)) { /* The frames currently on the list are fully loaded. Start the next one loading. (We run the image loader asynchronously, but we load them one at a time.) */ load_image (mi, alloc_frame (mi)); } else { /* The first batch of images are now all loaded! Stagger the expire times so that they don't all drop out at once. */ time_t now = time((time_t *) 0); int i; for (i = 0; i < ss->nframes; i++) { image_frame *frame = ss->frames[i]; frame->r = 1.0; frame->theta = i * 360.0 / ss->nframes; frame->expires = now + (duration * (i + 1)); frame->mode = NORMAL; } /* Instead of always going clockwise, shuffle the expire times of the frames so that they drop out in a random order. */ for (i = 0; i < ss->nframes; i++) { image_frame *frame1 = ss->frames[i]; image_frame *frame2 = ss->frames[random() % ss->nframes]; time_t swap = frame1->expires; frame1->expires = frame2->expires; frame2->expires = swap; } ss->awaiting_first_images_p = False; } } loading_msg (mi, ss->nframes-1); return !ss->awaiting_first_images_p; }
ENTRYPOINT void init_cube (ModeInfo *mi) { int i; cube_configuration *cc; MI_INIT (mi, ccs); cc = &ccs[MI_SCREEN(mi)]; if ((cc->glx_context = init_GL(mi)) != NULL) { reshape_cube (mi, MI_WIDTH(mi), MI_HEIGHT(mi)); } cc->trackball = gltrackball_init (False); cc->ncolors = 256; cc->colors = (XColor *) calloc(cc->ncolors, sizeof(XColor)); reset_colors (mi); init_wave (mi); cc->ncubes = MI_COUNT (mi); if (cc->ncubes < 1) cc->ncubes = 1; cc->cubes = (cube *) calloc (sizeof(cube), cc->ncubes); for (i = 0; i < cc->ncubes; i++) { /* Set the size to roughly cover a 2x2 square on average. */ GLfloat scale = 1.8 / sqrt (cc->ncubes); cube *cube = &cc->cubes[i]; double th = -(skew ? frand(skew) : 0) * M_PI / 180; cube->x = (frand(1)-0.5); cube->y = (frand(1)-0.5); cube->z = frand(0.12); cube->cth = cos(th); cube->sth = sin(th); cube->w = scale * (frand(1) + 0.2); cube->d = scale * (frand(1) + 0.2); if (cube->x < cc->min_x) cc->min_x = cube->x; if (cube->y < cc->min_y) cc->min_y = cube->y; if (cube->x > cc->max_x) cc->max_x = cube->x; if (cube->y > cc->max_y) cc->max_y = cube->y; } /* Sorting by depth improves frame rate slightly. With 6000 polygons we get: 3.9 FPS unsorted; 3.1 FPS back to front; 4.3 FPS front to back. */ qsort (cc->cubes, cc->ncubes, sizeof(*cc->cubes), cmp_cubes); }
static void make_plane (ModeInfo *mi) { hexstrut_configuration *bp = &bps[MI_SCREEN(mi)]; int n = MI_COUNT(mi) * 2; GLfloat size = 2.0 / n; int x, y; GLfloat w = size; GLfloat h = size * sqrt(3) / 2; triangle **grid = (triangle **) calloc (n * n, sizeof(*grid)); for (y = 0; y < n; y++) for (x = 0; x < n; x++) { triangle *t; t = (triangle *) calloc (1, sizeof(*t)); t->p[0].x = (x - n/2) * w; t->p[0].y = (y - n/2) * h; if (y & 1) t->p[0].x += w / 2; t->p[1].x = t->p[0].x - w/2; t->p[2].x = t->p[0].x + w/2; t->p[1].y = t->p[0].y + h; t->p[2].y = t->p[0].y + h; if (x > 0) { triangle *t2 = grid[y * n + (x-1)]; link_neighbor (t, t2); link_neighbor (t2, t); } if (y > 0) { triangle *t2 = grid[(y-1) * n + x]; link_neighbor (t, t2); link_neighbor (t2, t); if (x < n-1) { t2 = grid[(y-1) * n + (x+1)]; link_neighbor (t, t2); link_neighbor (t2, t); } } t->next = bp->triangles; bp->triangles = t; grid[y * n + x] = t; bp->count++; } free (grid); }
ENTRYPOINT void init_photopile (ModeInfo *mi) { int screen = MI_SCREEN(mi); photopile_state *ss; int wire = MI_IS_WIREFRAME(mi); if (sss == NULL) { if ((sss = (photopile_state *) calloc (MI_NUM_SCREENS(mi), sizeof(photopile_state))) == NULL) return; } ss = &sss[screen]; ss->mi = mi; if ((ss->glx_context = init_GL(mi)) != NULL) { reshape_photopile (mi, MI_WIDTH(mi), MI_HEIGHT(mi)); clear_gl_error(); /* WTF? sometimes "invalid op" from glViewport! */ } else { MI_CLEARWINDOW(mi); } ss->shadow = init_drop_shadow(); ss->texfont = load_texture_font (MI_DISPLAY(mi), "font"); if (debug_p) hack_resources (MI_DISPLAY (mi)); ss->frames = (image *)calloc (MI_COUNT(mi) + 1, sizeof(image)); ss->nframe = 0; if (!wire) { int i; for (i = 0; i < MI_COUNT(mi) + 1; ++i) { glGenTextures (1, &(ss->frames[i].texid)); if (ss->frames[i].texid <= 0) abort(); } } ss->mode = EARLY; load_image(mi); /* start loading the first image */ }
static void free_hydrostat (ModeInfo *mi) { hydrostat_configuration *bp = &bps[MI_SCREEN(mi)]; int i; if (!bp->squids) return; for (i = 0; i < MI_COUNT(mi); i++) free_squid (bp->squids[i]); free (bp->squids); }
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; }
ENTRYPOINT void init_atlantis(ModeInfo * mi) { int screen = MI_SCREEN(mi); atlantisstruct *ap; Display *display = MI_DISPLAY(mi); Window window = MI_WINDOW(mi); if (atlantis == NULL) { if ((atlantis = (atlantisstruct *) calloc(MI_NUM_SCREENS(mi), sizeof (atlantisstruct))) == NULL) return; } ap = &atlantis[screen]; ap->num_sharks = MI_COUNT(mi); if (ap->sharks == NULL) { if ((ap->sharks = (fishRec *) calloc(ap->num_sharks, sizeof (fishRec))) == NULL) { /* free everything up to now */ (void) free((void *) atlantis); atlantis = NULL; return; } } ap->sharkspeed = MI_CYCLES(mi); /* has influence on the "width" of the movement */ ap->sharksize = MI_SIZE(mi); /* has influence on the "distance" of the sharks */ ap->whalespeed = whalespeed; ap->wire = MI_IS_WIREFRAME(mi); if (MI_IS_DEBUG(mi)) { (void) fprintf(stderr, "%s:\n\tnum_sharks=%d\n\tsharkspeed=%.1f\n\tsharksize=%d\n\twhalespeed=%.1f\n\twireframe=%s\n", MI_NAME(mi), ap->num_sharks, ap->sharkspeed, ap->sharksize, ap->whalespeed, ap->wire ? "yes" : "no" ); } if ((ap->glx_context = init_GL(mi)) != NULL) { reshape_atlantis(mi, MI_WIDTH(mi), MI_HEIGHT(mi)); glDrawBuffer(GL_BACK); Init(mi); AllDisplay(ap); glXSwapBuffers(display, window); } else { MI_CLEARWINDOW(mi); } }
static void randomize_spikes (ModeInfo *mi) { ball_configuration *bp = &bps[MI_SCREEN(mi)]; int i; bp->pos = 0; for (i = 0; i < MI_COUNT(mi); i++) { bp->spikes[i*2] = (random() % 360) - 180; bp->spikes[i*2+1] = (random() % 180) - 90; } # define ROT_SCALE 22 for (i = 0; i < MI_COUNT(mi) * 2; i++) bp->spikes[i] = (bp->spikes[i] / ROT_SCALE) * ROT_SCALE; if ((random() % 3) == 0) bp->color_shift = random() % (bp->ncolors / 2); else bp->color_shift = 0; }
static void loading_msg (ModeInfo *mi, int n) { carousel_state *ss = &sss[MI_SCREEN(mi)]; int wire = MI_IS_WIREFRAME(mi); char text[100]; GLfloat scale; if (wire) return; if (n == 0) sprintf (text, "Loading images..."); else sprintf (text, "Loading images... (%d%%)", (int) (n * 100 / MI_COUNT(mi))); if (ss->loading_sw == 0) /* only do this once, so that the string doesn't move. */ ss->loading_sw = texture_string_width (ss->texfont, text, &ss->loading_sh); scale = ss->loading_sh / (GLfloat) MI_HEIGHT(mi); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); gluOrtho2D(0, MI_WIDTH(mi), 0, MI_HEIGHT(mi)); glTranslatef ((MI_WIDTH(mi) - ss->loading_sw) / 2, (MI_HEIGHT(mi) - ss->loading_sh) / 2, 0); glColor3f (1, 1, 0); glEnable (GL_TEXTURE_2D); glDisable (GL_DEPTH_TEST); print_texture_string (ss->texfont, text); glEnable (GL_DEPTH_TEST); glPopMatrix(); glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(GL_MODELVIEW); glFinish(); glXSwapBuffers (MI_DISPLAY (mi), MI_WINDOW(mi)); }
static void new_cube_colors (ModeInfo *mi) { cube_configuration *bp = &bps[MI_SCREEN(mi)]; int i; bp->ncolors = 128; if (bp->colors) free (bp->colors); bp->colors = (XColor *) calloc(bp->ncolors, sizeof(XColor)); make_smooth_colormap (0, 0, 0, bp->colors, &bp->ncolors, False, 0, False); for (i = 0; i < MI_COUNT(mi); i++) bp->subcubes[i].ccolor = random() % bp->ncolors; }
ENTRYPOINT void init_fadeplot (ModeInfo * mi) { fadeplotstruct *fp; if (fadeplots == NULL) { if ((fadeplots = (fadeplotstruct *) calloc(MI_NUM_SCREENS(mi), sizeof (fadeplotstruct))) == NULL) return; } fp = &fadeplots[MI_SCREEN(mi)]; fp->width = MI_WIDTH(mi); fp->height = MI_HEIGHT(mi); fp->min = MAX(MIN(fp->width, fp->height) / 2, 1); fp->speed.x = 8; fp->speed.y = 10; fp->step.x = 1; fp->step.y = 1; fp->temps = 0; fp->factor.x = MAX(fp->width / (2 * fp->min), 1); fp->factor.y = MAX(fp->height / (2 * fp->min), 1); fp->nbstep = MI_COUNT(mi); if (fp->nbstep < -MINSTEPS) { fp->nbstep = NRAND(-fp->nbstep - MINSTEPS + 1) + MINSTEPS; } else if (fp->nbstep < MINSTEPS) fp->nbstep = MINSTEPS; fp->maxpts = MI_CYCLES(mi); if (fp->maxpts < 1) fp->maxpts = 1; if (fp->pts == NULL) { if ((fp->pts = (XPoint *) calloc(fp->maxpts, sizeof (XPoint))) == NULL) { free_fadeplot(fp); return; } } if (MI_NPIXELS(mi) > 2) fp->pix = NRAND(MI_NPIXELS(mi)); if (fp->stab != NULL) (void) free((void *) fp->stab); if (!initSintab(mi)) return; MI_CLEARWINDOW(mi); }
ENTRYPOINT void change_sballs(ModeInfo * mi) { sballsstruct *sb; if (sballs == NULL) return; sb = &sballs[MI_SCREEN(mi)]; if (!sb->glx_context) return; /* initialise object number */ if ((object == 0) || (object > MAX_OBJ)) object = NRAND(MAX_OBJ-1)+1; object--; /* correct sphere number */ spheres = MI_COUNT(mi); if (MI_COUNT(mi) > polygons[object].numverts) spheres = polygons[object].numverts; if (MI_COUNT(mi) < 1) spheres = polygons[object].numverts; if (MI_IS_DEBUG(mi)) { (void) fprintf(stderr, "%s:\n\tobject=%s\n\tspheres=%d\n\tspeed=%d\n\ttexture=%s\n", MI_NAME(mi), polygons[object].shortname, spheres, (int) MI_CYCLES(mi), do_texture ? "on" : "off" ); } glXMakeCurrent(MI_DISPLAY(mi), MI_WINDOW(mi), *(sb->glx_context)); }
ENTRYPOINT void init_grav(ModeInfo * mi) { Display *display = MI_DISPLAY(mi); GC gc = MI_GC(mi); unsigned char ball; gravstruct *gp; if (gravs == NULL) { if ((gravs = (gravstruct *) calloc(MI_NUM_SCREENS(mi), sizeof (gravstruct))) == NULL) return; } gp = &gravs[MI_SCREEN(mi)]; gp->width = MI_WIDTH(mi); gp->height = MI_HEIGHT(mi); gp->sr = STARRADIUS; gp->nplanets = MI_COUNT(mi); if (gp->nplanets < 0) { if (gp->planets) { (void) free((void *) gp->planets); gp->planets = (planetstruct *) NULL; } gp->nplanets = NRAND(-gp->nplanets) + 1; /* Add 1 so its not too boring */ } if (gp->planets == NULL) { if ((gp->planets = (planetstruct *) calloc(gp->nplanets, sizeof (planetstruct))) == NULL) return; } MI_CLEARWINDOW(mi); if (MI_NPIXELS(mi) > 2) gp->starcolor = MI_PIXEL(mi, NRAND(MI_NPIXELS(mi))); else gp->starcolor = MI_WHITE_PIXEL(mi); for (ball = 0; ball < (unsigned char) gp->nplanets; ball++) init_planet(mi, &gp->planets[ball]); /* Draw centrepoint */ XDrawArc(display, MI_WINDOW(mi), gc, gp->width / 2 - gp->sr / 2, gp->height / 2 - gp->sr / 2, gp->sr, gp->sr, 0, 23040); }
ENTRYPOINT void init_superquadrics(ModeInfo * mi) { Display *display = MI_DISPLAY(mi); Window window = MI_WINDOW(mi); int screen = MI_SCREEN(mi); superquadricsstruct *sp; if (superquadrics == NULL) { if ((superquadrics = (superquadricsstruct *) calloc(MI_NUM_SCREENS(mi), sizeof (superquadricsstruct))) == NULL) return; } sp = &superquadrics[screen]; sp->mono = (MI_IS_MONO(mi) ? 1 : 0); sp->pats[1][1] = 1; sp->pats[1][3] = 1; sp->pats[2][2] = 1; sp->pats[2][3] = 1; sp->pats[3][1] = 1; sp->pats[3][2] = 1; /* {0, 0, 0, 0}, {0, 1, 0, 1}, {0, 0, 1, 1}, {0, 1, 1, 0} */ if ((sp->glx_context = init_GL(mi)) != NULL) { InitSuperquadrics(MI_IS_WIREFRAME(mi), 0, MI_COUNT(mi), MI_CYCLES(mi), spinspeed, sp); ReshapeSuperquadrics(MI_WIDTH(mi), MI_HEIGHT(mi)); DisplaySuperquadrics(sp); glFinish(); glXSwapBuffers(display, window); } else { MI_CLEARWINDOW(mi); } }
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); }
ENTRYPOINT void init_lissie (ModeInfo * mi) { lissstruct *lp; unsigned char ball; MI_INIT (mi, lisses, 0); lp = &lisses[MI_SCREEN(mi)]; lp->width = MI_WIDTH(mi); #ifdef HAVE_JWXYZ jwxyz_XSetAntiAliasing (MI_DISPLAY(mi), MI_GC(mi), False); #endif lp->height = MI_HEIGHT(mi); lp->nlissies = MI_COUNT(mi); if (lp->nlissies < -MINLISSIES) { if (lp->lissie) { (void) free((void *) lp->lissie); lp->lissie = (lissiestruct *) NULL; } lp->nlissies = NRAND(-lp->nlissies - MINLISSIES + 1) + MINLISSIES; } else if (lp->nlissies < MINLISSIES) lp->nlissies = MINLISSIES; lp->loopcount = 0; if (lp->lissie == NULL) if ((lp->lissie = (lissiestruct *) calloc(lp->nlissies, sizeof (lissiestruct))) == NULL) return; MI_CLEARWINDOW(mi); lp->painted = False; for (ball = 0; ball < (unsigned char) lp->nlissies; ball++) initlissie(mi, &lp->lissie[ball]); }
ENTRYPOINT void init_morph3d(ModeInfo * mi) { morph3dstruct *mp; MI_INIT (mi, morph3d); mp = &morph3d[MI_SCREEN(mi)]; mp->step = NRAND(90); mp->VisibleSpikes = 1; if ((mp->glx_context = init_GL(mi)) != NULL) { reshape_morph3d(mi, MI_WIDTH(mi), MI_HEIGHT(mi)); glDrawBuffer(GL_BACK); mp->object = MI_COUNT(mi); if (mp->object <= 0 || mp->object > 5) mp->object = NRAND(5) + 1; pinit(mi); } else { MI_CLEARWINDOW(mi); } }
static void draw_spiral (ModeInfo *mi, disc *d) { int wire = MI_IS_WIREFRAME(mi); hypnowheel_configuration *bp = &bps[MI_SCREEN(mi)]; GLfloat rr = 0.5; int n = MI_COUNT(mi); int steps = n * (wire ? 3 : (n < 5 ? 60 : n < 10 ? 20 : 10)); GLfloat dth = M_PI*2 / n; GLfloat dr = rr / steps; GLfloat th; GLfloat twist = d->twist; GLfloat dtwist = M_PI * 2 * twist / steps; double cscale = 65536.0; if (nlayers > 3 && !wire) cscale *= (nlayers-2); /* don't wash out to white */ glColor4f (bp->colors[d->color].red / cscale, bp->colors[d->color].green / cscale, bp->colors[d->color].blue / cscale, d->alpha); for (th = 0; th < M_PI*2; th += dth) { GLfloat th1 = th; GLfloat r; glBegin (wire ? GL_LINE_STRIP : GL_QUAD_STRIP); for (r = 0; r <= rr; r += dr) { GLfloat th2 = th1 + dth/2 + dtwist; th1 += dtwist; glVertex3f (r * cos(th1), r * sin(th1), 0); if (! wire) glVertex3f (r * cos(th2), r * sin(th2), 0); mi->polygon_count++; } glEnd(); } }
ENTRYPOINT void init_grav(ModeInfo * mi) { unsigned char ball; gravstruct *gp; MI_INIT (mi, gravs); gp = &gravs[MI_SCREEN(mi)]; gp->width = MI_WIDTH(mi); gp->height = MI_HEIGHT(mi); gp->sr = STARRADIUS; gp->nplanets = MI_COUNT(mi); if (gp->nplanets < 0) { if (gp->planets) { (void) free((void *) gp->planets); gp->planets = (planetstruct *) NULL; } gp->nplanets = NRAND(-gp->nplanets) + 1; /* Add 1 so its not too boring */ } if (gp->planets == NULL) { if ((gp->planets = (planetstruct *) calloc(gp->nplanets, sizeof (planetstruct))) == NULL) return; } MI_CLEARWINDOW(mi); if (MI_NPIXELS(mi) > 2) gp->starcolor = MI_PIXEL(mi, NRAND(MI_NPIXELS(mi))); else gp->starcolor = MI_WHITE_PIXEL(mi); for (ball = 0; ball < (unsigned char) gp->nplanets; ball++) init_planet(mi, &gp->planets[ball]); }
ENTRYPOINT void init_ball (ModeInfo *mi) { ball_configuration *bp; int wire = MI_IS_WIREFRAME(mi); MI_INIT (mi, bps); bp = &bps[MI_SCREEN(mi)]; bp->glx_context = init_GL(mi); if (! wire) build_texture (mi); reshape_ball (mi, MI_WIDTH(mi), MI_HEIGHT(mi)); bp->th = 180 - frand(360); if (MI_COUNT(mi) < 10) MI_COUNT(mi) = 10; if (MI_COUNT(mi) > 200) MI_COUNT(mi) = 200; { double spin_speed = 0.1; double wander_speed = 0.003; double spin_accel = 1; bp->rot = make_rotator (do_spin ? spin_speed : 0, do_spin ? spin_speed : 0, do_spin ? spin_speed : 0, spin_accel, do_wander ? wander_speed : 0, False); bp->trackball = gltrackball_init (True); } build_ball (mi); if (!wire) { GLfloat color[4] = {0.5, 0.5, 0.5, 1}; GLfloat cspec[4] = {1, 1, 1, 1}; static const GLfloat shiny = 10; static GLfloat pos0[4] = { 0.5, -1, -0.5, 0}; static GLfloat pos1[4] = {-0.75, -1, 0, 0}; static GLfloat amb[4] = {0, 0, 0, 1}; static GLfloat dif[4] = {1, 1, 1, 1}; static GLfloat spc[4] = {1, 1, 1, 1}; glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glEnable(GL_LIGHT1); glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE); color[0] += frand(0.2); color[1] += frand(0.2); color[2] += frand(0.2); cspec[0] -= frand(0.2); cspec[1] -= frand(0.2); cspec[2] -= frand(0.2); glLightfv(GL_LIGHT0, GL_POSITION, pos0); glLightfv(GL_LIGHT0, GL_AMBIENT, amb); glLightfv(GL_LIGHT0, GL_DIFFUSE, dif); glLightfv(GL_LIGHT0, GL_SPECULAR, spc); glLightfv(GL_LIGHT1, GL_POSITION, pos1); glLightfv(GL_LIGHT1, GL_AMBIENT, amb); glLightfv(GL_LIGHT1, GL_DIFFUSE, dif); glLightfv(GL_LIGHT1, GL_SPECULAR, spc); glMaterialfv (GL_FRONT, GL_AMBIENT_AND_DIFFUSE, color); glMaterialfv (GL_FRONT, GL_SPECULAR, cspec); glMateriali (GL_FRONT, GL_SHININESS, shiny); } }