Esempio n. 1
0
static void
drawlissie(ModeInfo * mi, lissiestruct * lissie)
{
	Display    *display = MI_DISPLAY(mi);
	GC          gc = MI_GC(mi);
	lissstruct *lp = &lisses[MI_SCREEN(mi)];
	int         p = (++lissie->pos) % MAXLISSIELEN;
	int         oldp = (lissie->pos - lissie->len + MAXLISSIELEN) % MAXLISSIELEN;

	/* Let time go by ... */
	lissie->tx += lissie->dtx;
	lissie->ty += lissie->dty;
	if (lissie->tx > 2 * M_PI)
		lissie->tx -= 2 * M_PI;
	if (lissie->ty > 2 * M_PI)
		lissie->ty -= 2 * M_PI;

	/* vary both (x/y) speeds by max. 1% */
	lissie->dtx *= FLOATRAND(0.99, 1.01);
	lissie->dty *= FLOATRAND(0.99, 1.01);
	if (lissie->dtx < MINDT)
		lissie->dtx = MINDT;
	else if (lissie->dtx > MAXDT)
		lissie->dtx = MAXDT;
	if (lissie->dty < MINDT)
		lissie->dty = MINDT;
	else if (lissie->dty > MAXDT)
		lissie->dty = MAXDT;

	lissie->loc[p].x = lissie->xi + (int) (sin(lissie->tx) * lissie->rx);
	lissie->loc[p].y = lissie->yi + (int) (sin(lissie->ty) * lissie->ry);

	/* Mask */
	XSetForeground(display, gc, MI_BLACK_PIXEL(mi));
	Lissie(oldp);

	/* Redraw */
	if (MI_NPIXELS(mi) > 2) {
		XSetForeground(display, gc, MI_PIXEL(mi, lissie->color));
		if (++lissie->color >= (unsigned) MI_NPIXELS(mi))
			lissie->color = 0;
	} else
		XSetForeground(display, gc, MI_WHITE_PIXEL(mi));
	Lissie(p);
	if (lissie->redrawing) {
		int         i;

		lissie->redrawpos++;
		/* This compensates for the changed p
		   since the last callback. */

		for (i = 0; i < REDRAWSTEP; i++) {
			Lissie((p - lissie->redrawpos + MAXLISSIELEN) % MAXLISSIELEN);
			if (++(lissie->redrawpos) >= lissie->len) {
				lissie->redrawing = 0;
				break;
			}
		}
	}
}
Esempio n. 2
0
static void
level1_strike(Lightning bolt, ModeInfo * mi)
{
	Display    *display = MI_DISPLAY(mi);
	Window      window = MI_WINDOW(mi);
	Storm      *st = &Helga[MI_SCREEN(mi)];
	GC          gc = MI_GC(mi);
	int         i;

	if (MI_NPIXELS(mi) > 2)	/* color */
		XSetForeground(display, gc, MI_PIXEL(mi, st->color));
	else
		XSetForeground(display, gc, MI_WHITE_PIXEL(mi));
	XDrawLine(display, window, gc,
	bolt.end1.x - 1, bolt.end1.y, bolt.middle[0].x - 1, bolt.middle[0].y);
	draw_line(mi, bolt.middle, BOLT_VERTICIES, gc, -1);
	XDrawLine(display, window, gc,
		  bolt.middle[BOLT_VERTICIES - 1].x - 1,
	    bolt.middle[BOLT_VERTICIES - 1].y, bolt.end2.x - 1, bolt.end2.y);
	XDrawLine(display, window, gc,
	bolt.end1.x + 1, bolt.end1.y, bolt.middle[0].x + 1, bolt.middle[0].y);
	draw_line(mi, bolt.middle, BOLT_VERTICIES, gc, 1);
	XDrawLine(display, window, gc,
		  bolt.middle[BOLT_VERTICIES - 1].x + 1,
	    bolt.middle[BOLT_VERTICIES - 1].y, bolt.end2.x + 1, bolt.end2.y);

	for (i = 0; i < bolt.fork_number; i++) {
		draw_line(mi, bolt.branch[i].ForkVerticies, bolt.branch[i].num_used,
			  gc, -1);
		draw_line(mi, bolt.branch[i].ForkVerticies, bolt.branch[i].num_used,
			  gc, 1);
	}
	first_strike(bolt, mi);
}
Esempio n. 3
0
static void
drawcell(ModeInfo * mi, int col, int row, unsigned char color)
{
	antfarmstruct *ap = &antfarms[MI_SCREEN(mi)];
	GC          gc;

	if (!color) {
		XSetForeground(MI_DISPLAY(mi), MI_GC(mi), MI_BLACK_PIXEL(mi));
		gc = MI_GC(mi);
	} else if (MI_NPIXELS(mi) > 2) {
		XSetForeground(MI_DISPLAY(mi), MI_GC(mi),
			MI_PIXEL(mi, ap->colors[color - 1]));
		gc = MI_GC(mi);
	} else {
		XGCValues   gcv;

		gcv.stipple = ap->pixmaps[color - 1];
		gcv.foreground = MI_WHITE_PIXEL(mi);
		gcv.background = MI_BLACK_PIXEL(mi);
		XChangeGC(MI_DISPLAY(mi), ap->stippledGC,
			  GCStipple | GCForeground | GCBackground, &gcv);
		gc = ap->stippledGC;
	}
	fillcell(mi, gc, col, row);
}
Esempio n. 4
0
static void
init_planet(ModeInfo * mi, planetstruct * planet)
{
	Display    *display = MI_DISPLAY(mi);
	Window      window = MI_WINDOW(mi);
	GC          gc = MI_GC(mi);
	gravstruct *gp = &gravs[MI_SCREEN(mi)];

	if (MI_NPIXELS(mi) > 2)
		planet->colors = MI_PIXEL(mi, NRAND(MI_NPIXELS(mi)));
	else
		planet->colors = MI_WHITE_PIXEL(mi);
	/* Initialize positions */
	POS(X) = FLOATRAND(-XR, XR);
	POS(Y) = FLOATRAND(-YR, YR);
	POS(Z) = FLOATRAND(-ZR, ZR);

	if (POS(Z) > -ALMOST) {
		planet->xi = (int)
			((double) gp->width * (HALF + POS(X) / (POS(Z) + DIST)));
		planet->yi = (int)
			((double) gp->height * (HALF + POS(Y) / (POS(Z) + DIST)));
	} else
		planet->xi = planet->yi = -1;
	planet->ri = RADIUS;

	/* Initialize velocities */
	VEL(X) = FLOATRAND(-VR, VR);
	VEL(Y) = FLOATRAND(-VR, VR);
	VEL(Z) = FLOATRAND(-VR, VR);

	/* Draw planets */
	Planet(planet->xi, planet->yi);
}
Esempio n. 5
0
static void InitDrop(ModeInfo * mi, rainstruct *rp, dropstruct *drop)
{
  /* Where does the drop fall in the pool?
     At least 20% of height from top and not completely at the bottom */
  int yMin = MI_HEIGHT(mi) / 5;
  int yMax = MI_HEIGHT(mi) - ((MAX_RADIUS * 3) / 2);
  drop->pool.x = 0;
  drop->pool.y = yMin + NRAND(yMax - yMin);

  /* How fast does it fall? */
  drop->offset.x = 5 + NRAND(5);
  drop->offset.y = 20 + NRAND(20);

  /* Where does the drop start */
  drop->drop.x = NRAND(MI_WIDTH(mi));
  drop->drop.height = 0;
  drop->drop.width = drop->drop.x + drop->offset.x;
  drop->drop.y = drop->drop.height + drop->offset.y;

  /* How large is the pool and how fast does it grow? */
  drop->radius = 0;
  drop->radius_step = 1 + NRAND(2);
  drop->max_radius = (MAX_RADIUS / 2) + NRAND(MAX_RADIUS / 2);

  /* Colored drops? */
  if (rp->colored_drops)
  {
    if (rp->base_color == 0)
      drop->color = MI_PIXEL(mi, NRAND(MI_NPIXELS(mi)));
    else
      drop->color = rp->base_color + (NRAND(2) == 1 ? -1 : 1) * NRAND(12);
  }
  else
    drop->color = MI_WHITE_PIXEL(mi);
}
Esempio n. 6
0
static void
init_planet(ModeInfo * mi, planetstruct * planet)
{
	gravstruct *gp = &gravs[MI_SCREEN(mi)];

# ifdef HAVE_JWXYZ
    jwxyz_XSetAntiAliasing (MI_DISPLAY(mi), MI_GC(mi), False);
# endif

	if (MI_NPIXELS(mi) > 2)
		planet->colors = MI_PIXEL(mi, NRAND(MI_NPIXELS(mi)));
	else
		planet->colors = MI_WHITE_PIXEL(mi);
	/* Initialize positions */
	POS(X) = FLOATRAND(-XR, XR);
	POS(Y) = FLOATRAND(-YR, YR);
	POS(Z) = FLOATRAND(-ZR, ZR);

	if (POS(Z) > -ALMOST) {
		planet->xi = (int)
			((double) gp->width * (HALF + POS(X) / (POS(Z) + DIST)));
		planet->yi = (int)
			((double) gp->height * (HALF + POS(Y) / (POS(Z) + DIST)));
	} else
		planet->xi = planet->yi = -1;
	planet->ri = RADIUS;

	/* Initialize velocities */
	VEL(X) = FLOATRAND(-VR, VR);
	VEL(Y) = FLOATRAND(-VR, VR);
	VEL(Z) = FLOATRAND(-VR, VR);
}
Esempio n. 7
0
void
draw_turtle(ModeInfo * mi)
{
	turtlestruct *tp;

	if (turtles == NULL)
		return;
	tp = &turtles[MI_SCREEN(mi)];

	if (++tp->time > MI_CYCLES(mi))
		init_turtle(mi);

	MI_IS_DRAWN(mi) = True;

	if (MI_NPIXELS(mi) > 2)
		XSetForeground(MI_DISPLAY(mi), MI_GC(mi),
			       MI_PIXEL(mi, NRAND(MI_NPIXELS(mi))));

	tp->r = tp->r >> 1;
	tp->level++;
	if (tp->r > 1)
		switch (tp->curve) {
			case HILBERT:
				switch (tp->dir) {
					case 0:
						tp->pt1.x = tp->pt2.x = tp->start.x + tp->r / 2;
						tp->pt1.y = tp->pt2.y = tp->start.y + tp->r / 2;
						generate_hilbert(mi, 0, tp->r);
						break;
					case 1:
						tp->pt1.x = tp->pt2.x = tp->start.x + tp->min - tp->r / 2;
						tp->pt1.y = tp->pt2.y = tp->start.y + tp->min - tp->r / 2;
						generate_hilbert(mi, 0, -tp->r);
						break;
					case 2:
						tp->pt1.x = tp->pt2.x = tp->start.x + tp->min - tp->r / 2;
						tp->pt1.y = tp->pt2.y = tp->start.y + tp->min - tp->r / 2;
						generate_hilbert(mi, -tp->r, 0);
						break;
					case 3:
						tp->pt1.x = tp->pt2.x = tp->start.x + tp->r / 2;
						tp->pt1.y = tp->pt2.y = tp->start.y + tp->r / 2;
						generate_hilbert(mi, tp->r, 0);
				}
				break;
			case CESARO_VAR:
				generate_cesarovar(mi,
					(double) tp->pt1.x, (double) tp->pt1.y,
					(double) tp->pt2.x, (double) tp->pt2.y,
					tp->level, tp->sign);
				break;
			case HARTER_HEIGHTWAY:
				generate_harter_heightway(mi,
					(double) tp->pt1.x, (double) tp->pt1.y,
				  	(double) tp->pt2.x, (double) tp->pt2.y,
					tp->level, tp->sign);
				break;
		}
}
Esempio n. 8
0
ENTRYPOINT void
draw_fadeplot (ModeInfo * mi)
{
	Display    *display = MI_DISPLAY(mi);
	Window      window = MI_WINDOW(mi);
	GC          gc = MI_GC(mi);
	int         i, j, temp;
	fadeplotstruct *fp;

	if (fadeplots == NULL)
		return;
	fp = &fadeplots[MI_SCREEN(mi)];
	if (fp->stab == NULL)
		return;

	MI_IS_DRAWN(mi) = True;
	XSetForeground(display, gc, MI_BLACK_PIXEL(mi));
	XDrawPoints(display, window, gc, fp->pts, fp->maxpts, CoordModeOrigin);

	if (MI_NPIXELS(mi) > 2) {
		XSetForeground(display, gc, MI_PIXEL(mi, fp->pix));
		if (++fp->pix >= MI_NPIXELS(mi))
			fp->pix = 0;
	} else
		XSetForeground(display, gc, MI_WHITE_PIXEL(mi));

	temp = 0;
	for (j = 0; j < fp->nbstep; j++) {
		for (i = 0; i < fp->maxpts / fp->nbstep; i++) {
			fp->pts[temp].x =
				fp->stab[(fp->st.x + fp->speed.x * j + i * fp->step.x) % fp->angles] *
				fp->factor.x + fp->width / 2 - fp->min;
			fp->pts[temp].y =
				fp->stab[(fp->st.y + fp->speed.y * j + i * fp->step.y) % fp->angles] *
				fp->factor.y + fp->height / 2 - fp->min;
			temp++;
		}
	}
	XDrawPoints(display, window, gc, fp->pts, temp, CoordModeOrigin);
	fp->st.x = (fp->st.x + fp->speed.x) % fp->angles;
	fp->st.y = (fp->st.y + fp->speed.y) % fp->angles;
	fp->temps++;
	if ((fp->temps % (fp->angles / 2)) == 0) {
		fp->temps = fp->temps % fp->angles * 5;
		if ((fp->temps % (fp->angles)) == 0)
			fp->speed.y = (fp->speed.y + 1) % 30 + 1;
		if ((fp->temps % (fp->angles * 2)) == 0)
			fp->speed.x = (fp->speed.x) % 20;
		if ((fp->temps % (fp->angles * 3)) == 0)
			fp->step.y = (fp->step.y + 1) % 2 + 1;

		MI_CLEARWINDOW(mi);
	}
}
Esempio n. 9
0
void
draw_blot(ModeInfo * mi)
{
	blotstruct *bp;
	XPoint     *xp;
	int         x, y, k;

	if (blots == NULL)
		return;
	bp = &blots[MI_SCREEN(mi)];
	xp = bp->pointBuffer;
	if (xp == NULL)
		init_blot(mi);

	MI_IS_DRAWN(mi) = True;
	if (MI_NPIXELS(mi) > 2) {
		XSetForeground(MI_DISPLAY(mi), MI_GC(mi), MI_PIXEL(mi, bp->pix));
		if (++bp->pix >= MI_NPIXELS(mi))
			bp->pix = 0;
	}
	x = bp->xmid;
	y = bp->ymid;
	k = bp->size;
	while (k >= 4) {
		x += (NRAND(1 + (bp->offset << 1)) - bp->offset);
		y += (NRAND(1 + (bp->offset << 1)) - bp->offset);
		k--;
		xp->x = x;
		xp->y = y;
		xp++;
		if (bp->xsym) {
			k--;
			xp->x = bp->width - x;
			xp->y = y;
			xp++;
		}
		if (bp->ysym) {
			k--;
			xp->x = x;
			xp->y = bp->height - y;
			xp++;
		}
		if (bp->xsym && bp->ysym) {
			k--;
			xp->x = bp->width - x;
			xp->y = bp->height - y;
			xp++;
		}
	}
	XDrawPoints(MI_DISPLAY(mi), MI_WINDOW(mi), MI_GC(mi),
		    bp->pointBuffer, (bp->size - k), CoordModeOrigin);
	if (++bp->count > MI_CYCLES(mi))
		init_blot(mi);
}
Esempio n. 10
0
/* Sets the color to the color of a wall. */
static void
setwallcolor(ModeInfo * mi)
{
	Display    *display = MI_DISPLAY(mi);
	pacmangamestruct *pp = &pacmangames[MI_SCREEN(mi)];

	if (MI_NPIXELS(mi) > 2)
		XSetForeground(display, pp->stippledGC,
				MI_PIXEL(mi, BLUE));
	else
		XSetForeground(display, pp->stippledGC,
				MI_WHITE_PIXEL(mi));
}
Esempio n. 11
0
static void
drawImages(ModeInfo * mi)
{
	Display *display = MI_DISPLAY(mi);
	Window window = MI_WINDOW(mi);
	imagestruct *ip = &ims[MI_SCREEN(mi)];
	GC gc = (message && *message) ? MI_GC(mi) : ip->bgGC;
	int i;

	MI_CLEARWINDOWCOLORMAPFAST(mi, gc, ip->black);
	for (i = 0; i < ip->iconcount; i++) {
	  if (ip->icons[i].x >= 0) {
	    if (message && *message) {
		if (MI_NPIXELS(mi) > 2)
			XSetForeground(display, gc,
				MI_PIXEL(mi, ip->icons[i].color));
		else
			XSetForeground(display, gc, MI_WHITE_PIXEL(mi));
		XCopyPlane(display, ip->pixmap, window, gc,
	                0, 0,
			ip->pixw, ip->pixh,
			ip->pixw * ip->icons[i].x + ip->image_offset.x,
			ip->pixh * ip->icons[i].y + ip->image_offset.y,
			1L);
	    } else if  (ip->logo != NULL) {
		if (MI_NPIXELS(mi) <= 2)
			XSetForeground(display, gc, MI_WHITE_PIXEL(mi));
		else if (ip->graphics_format < IS_XPM)
			XSetForeground(display, gc,
				MI_PIXEL(mi, ip->icons[i].color));
		(void) XPutImage(display, window, gc, ip->logo, 0, 0,
			ip->pixw * ip->icons[i].x + ip->image_offset.x,
			ip->pixh * ip->icons[i].y + ip->image_offset.y,
			ip->pixw, ip->pixh);
	    }
	  }
	}
}
Esempio n. 12
0
static void
random_petal(ModeInfo * mi)
{
	petalstruct *pp = &petals[MI_SCREEN(mi)];

	pp->npoints = compute_petal(pp->points, pp->lines,
				    pp->width / 2, pp->height / 2);

	if (MI_NPIXELS(mi) <= 2)
		pp->color = MI_WHITE_PIXEL(mi);
	else
		pp->color = MI_PIXEL(mi, NRAND(MI_NPIXELS(mi)));
	petal(mi);
}
Esempio n. 13
0
static void InitDropColors(ModeInfo * mi, rainstruct *rp)
{
  /* Once in every 10 times show only white drops */
  rp->colored_drops = (NRAND(10) != 1);

  /* When using colored, use the all random colors or around the base color */
  if (rp->colored_drops)
  {
    if (NRAND(2) == 1)
      rp->base_color = MI_PIXEL(mi, NRAND(MI_NPIXELS(mi)));
    else
      rp->base_color = 0;
  }
}
Esempio n. 14
0
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);
}
Esempio n. 15
0
ENTRYPOINT void
draw_worm (ModeInfo * mi)
{
	Display    *display = MI_DISPLAY(mi);
	Window      window = MI_WINDOW(mi);
	GC          gc = MI_GC(mi);
	wormstruct *wp = &worms[MI_SCREEN(mi)];
	unsigned long wcolor;
	int         i;

	(void) memset((char *) wp->size, 0, wp->nc * sizeof (int));

	for (i = 0; i < wp->nw; i++) {
		if (MI_NPIXELS(mi) > 2) {
			wcolor = (i + wp->chromo) % wp->nc;

			worm_doit(mi, i, wcolor);
		} else
			worm_doit(mi, i, (unsigned long) 0);
	}

	if (MI_WIN_IS_USE3D(mi)) {
		if (MI_WIN_IS_INSTALL(mi))
			XSetFunction(display, gc, GXor);
		XSetForeground(display, gc, MI_RIGHT_COLOR(mi));
		XFillRectangles(display, window, gc, &(wp->rects[0]), wp->size[0]);

		XSetForeground(display, gc, MI_LEFT_COLOR(mi));
		XFillRectangles(display, window, gc, &(wp->rects[wp->maxsize]), wp->size[1]);
		if (MI_WIN_IS_INSTALL(mi))
			XSetFunction(display, gc, GXcopy);
	} else if (MI_NPIXELS(mi) > 2) {
		for (i = 0; i < wp->nc; i++) {
			XSetForeground(display, gc, MI_PIXEL(mi, i));
			XFillRectangles(display, window, gc, &(wp->rects[i * wp->maxsize]), wp->size[i]);
		}
	} else {
		XSetForeground(display, gc, MI_WIN_WHITE_PIXEL(mi));
		XFillRectangles(display, window, gc,
				&(wp->rects[0]), wp->size[0]);
	}

	if (++wp->chromo == (unsigned long) wp->nc)
		wp->chromo = 0;
}
Esempio n. 16
0
static void
drawCell(ModeInfo * mi, int col, int row, unsigned char state)
{
	circuitstruct *wp = &circuits[MI_SCREEN(mi)];
	GC          gc;

	if (MI_NPIXELS(mi) > 2) {
		gc = MI_GC(mi);
		XSetForeground(MI_DISPLAY(mi), gc, MI_PIXEL(mi, wp->colors[state]));
	} else {
		XGCValues   gcv;

		gcv.stipple = wp->pixmaps[state];
		gcv.foreground = MI_WHITE_PIXEL(mi);
		gcv.background = MI_BLACK_PIXEL(mi);
		XChangeGC(MI_DISPLAY(mi), wp->stippledGC,
			  GCStipple | GCForeground | GCBackground, &gcv);
		gc = wp->stippledGC;
	}
	fillcell(mi, gc, col, row);
}
Esempio n. 17
0
static void
drawCell_notused(ModeInfo * mi, int col, int row, unsigned char state)
{
	circuitstruct *wp = &circuits[MI_SCREEN(mi)];
	XGCValues   gcv;
	GC          gc;

	if (MI_NPIXELS(mi) > 2) {
		gc = MI_GC(mi);
		XSetForeground(MI_DISPLAY(mi), gc, MI_PIXEL(mi, wp->colors[state]));
	} else {
		gcv.stipple = wp->pixmaps[state];
		gcv.foreground = MI_WHITE_PIXEL(mi);
		gcv.background = MI_BLACK_PIXEL(mi);
		XChangeGC(MI_DISPLAY(mi), wp->stippledGC,
			  GCStipple | GCForeground | GCBackground, &gcv);
		gc = wp->stippledGC;
	}
	XFillRectangle(MI_DISPLAY(mi), MI_WINDOW(mi), MI_GC(mi),
	       wp->xb + wp->xs * col, wp->yb + wp->ys * row,
		wp->xs - (wp->xs > 3), wp->ys - (wp->ys > 3));
}
Esempio n. 18
0
ENTRYPOINT void
draw_sierpinski(ModeInfo * mi)
{
	Display    *display = MI_DISPLAY(mi);
	GC          gc = MI_GC(mi);
	XPoint     *xp[MAXCORNERS];
	int         i, v;
	sierpinskistruct *sp;

	if (tris == NULL)
		return;
	sp = &tris[MI_SCREEN(mi)];
	if (sp->pointBuffer[0] == NULL)
		return;

	MI_IS_DRAWN(mi) = True;
	if (MI_NPIXELS(mi) <= 2)
		XSetForeground(display, gc, MI_WHITE_PIXEL(mi));
	for (i = 0; i < sp->corners; i++)
		xp[i] = sp->pointBuffer[i];
	for (i = 0; i < sp->total_npoints; i++) {
		v = NRAND(sp->corners);
		sp->px = (sp->px + sp->vertex[v].x) / 2;
		sp->py = (sp->py + sp->vertex[v].y) / 2;
		xp[v]->x = sp->px;
		xp[v]->y = sp->py;
		xp[v]++;
		sp->npoints[v]++;
	}
	for (i = 0; i < sp->corners; i++) {
		if (MI_NPIXELS(mi) > 2)
			XSetForeground(display, gc, MI_PIXEL(mi, sp->colors[i]));
		XDrawPoints(display, MI_WINDOW(mi), gc, sp->pointBuffer[i], sp->npoints[i],
			    CoordModeOrigin);
		sp->npoints[i] = 0;
	}
	if (++sp->time >= MI_CYCLES(mi))
		startover(mi);
}
Esempio n. 19
0
static void
level2_strike(Lightning bolt, ModeInfo * mi)
{
	Display    *display = MI_DISPLAY(mi);
	Window      window = MI_WINDOW(mi);
	Storm      *st = &Helga[MI_SCREEN(mi)];
	GC          gc = MI_GC(mi);
	int         i;

	/* This was originally designed to be a little darker then the
	   level1 strike.  This was changed to get it to work on
	   multiscreens and to add more color variety.   I tried
	   stippling but it did not look good. */
	if (MI_NPIXELS(mi) > 2)
		XSetForeground(display, gc, MI_PIXEL(mi, st->color));
	else
		XSetForeground(display, gc, MI_WHITE_PIXEL(mi));
	XDrawLine(display, window, gc,
	bolt.end1.x - 2, bolt.end1.y, bolt.middle[0].x - 2, bolt.middle[0].y);
	draw_line(mi, bolt.middle, BOLT_VERTICIES, gc, -2);
	XDrawLine(display, window, gc,
		  bolt.middle[BOLT_VERTICIES - 1].x - 2,
	    bolt.middle[BOLT_VERTICIES - 1].y, bolt.end2.x - 2, bolt.end2.y);

	XDrawLine(display, window, gc,
	bolt.end1.x + 2, bolt.end1.y, bolt.middle[0].x + 2, bolt.middle[0].y);
	draw_line(mi, bolt.middle, BOLT_VERTICIES, gc, 2);
	XDrawLine(display, window, gc,
		  bolt.middle[BOLT_VERTICIES - 1].x + 2,
	    bolt.middle[BOLT_VERTICIES - 1].y, bolt.end2.x + 2, bolt.end2.y);

	for (i = 0; i < bolt.fork_number; i++) {
		draw_line(mi, bolt.branch[i].ForkVerticies, bolt.branch[i].num_used,
			  gc, -2);
		draw_line(mi, bolt.branch[i].ForkVerticies, bolt.branch[i].num_used,
			  gc, 2);
	}
	level1_strike(bolt, mi);
}
Esempio n. 20
0
static void
drawcell(ModeInfo * mi, int col, int row, unsigned int state)
{
	Display    *display = MI_DISPLAY(mi);
	Window      window = MI_WINDOW(mi);
	life1dstruct *lp = &life1ds[MI_SCREEN(mi)];
	GC          gc = lp->backGC;

	if (!state) {
		XSetForeground(display, gc, lp->black);
		XFillRectangle(display, window, gc,
		lp->xb + lp->xs * col, lp->yb + lp->ys * row, lp->xs, lp->ys);
		return;
	}
	if (MI_NPIXELS(mi) > 2)
		XSetForeground(display, gc, MI_PIXEL(mi, lp->colors[state - 1]));
	if (lp->pixelmode || (MI_NPIXELS(mi) <= 2)) {
		if (MI_NPIXELS(mi) <= 2) {
			XGCValues   gcv;

			gcv.stipple = lp->pixmaps[state - 1];
			gcv.foreground = MI_WHITE_PIXEL(mi);
			gcv.background = lp->black;
			gcv.fill_style = FillOpaqueStippled;
			XChangeGC(display, lp->stippledGC,
				  GCStipple | GCFillStyle | GCForeground | GCBackground, &gcv);
			XFillRectangle(display, window, lp->stippledGC,
				       lp->xb + lp->xs * col, lp->yb + lp->ys * row, lp->xs, lp->ys);
		} else
			XFillRectangle(display, window, gc,
				       lp->xb + lp->xs * col, lp->yb + lp->ys * row, lp->xs, lp->ys);
	}
	 else {
		(void) XPutImage(display, window, gc,
		lp->logo, 0, 0, lp->xb + lp->xs * col, lp->yb + lp->ys * row,
				 lp->logo->width, lp->logo->height);
	}
}
Esempio n. 21
0
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]);
}
Esempio n. 22
0
static void
init_fly(ModeInfo * mi, Fly * f)
{
	EyeScrInfo *ep = &eye_info[MI_SCREEN(mi)];
	int         win_width = MI_WIDTH(mi);
	int         win_height = MI_HEIGHT(mi);

	(void) memset((char *) f, 0, sizeof (Fly));	/* clear everything to zero */

	f->side = FLY_SIDE_LEFT;
	if (!MI_IS_ICONIC(mi))
	{
		f->width = ep->flywidth;
		f->height = ep->flyheight;
		f->vx = NRAND(15) + 1;	/* random horiz velocity */
	} else
	{
		/* image is just a dot when iconic */
		f->width = f->height = FLY_ICON_SIZE;
		f->vx = NRAND(4) + 1;	/* slower when iconic */
	}

	f->y = NRAND(win_height);
	if (f->y > (win_height / 2)) {
		f->side = FLY_SIDE_RIGHT;	/* change to right side */
		f->y -= win_height / 2;		/* start in top half */
		f->x = win_width - f->width;	/* move to right of screen */
		f->vx = -(f->vx);	/* flip direction */
	}
	f->oldx = -(f->width);	/* prevent undraw 1st time */

	if (MI_NPIXELS(mi) <= 2) {
		f->pixel = MI_WHITE_PIXEL(mi);	/* always white when mono */
	} else {
		f->pixel = MI_PIXEL(mi, NRAND(MI_NPIXELS(mi)));
	}
}
Esempio n. 23
0
void
init_toneclock(ModeInfo * mi)
{
	Display    *display = MI_DISPLAY(mi);
	Window      window = MI_WINDOW(mi);
	int         i, size_hour, istart;
	toneclockstruct *tclock;

/* initialize */
	if (toneclocks == NULL) {
		if ((toneclocks = (toneclockstruct *) calloc(MI_NUM_SCREENS(mi),
				sizeof (toneclockstruct))) == NULL)
			return;
	}
	tclock = &toneclocks[MI_SCREEN(mi)];
	tclock->mi = mi;

	if (tclock->gc == None) {
		if (MI_IS_INSTALL(mi) && MI_NPIXELS(mi) > 2) {
			XColor      color;

#ifndef STANDALONE
			tclock->fg = MI_FG_PIXEL(mi);
			tclock->bg = MI_BG_PIXEL(mi);
#endif
			tclock->blackpixel = MI_BLACK_PIXEL(mi);
			tclock->whitepixel = MI_WHITE_PIXEL(mi);
			if ((tclock->cmap = XCreateColormap(display, window,
					MI_VISUAL(mi), AllocNone)) == None) {
				free_toneclock(display, tclock);
				return;
			}
			XSetWindowColormap(display, window, tclock->cmap);
			(void) XParseColor(display, tclock->cmap, "black", &color);
			(void) XAllocColor(display, tclock->cmap, &color);
			MI_BLACK_PIXEL(mi) = color.pixel;
			(void) XParseColor(display, tclock->cmap, "white", &color);
			(void) XAllocColor(display, tclock->cmap, &color);
			MI_WHITE_PIXEL(mi) = color.pixel;
#ifndef STANDALONE
			(void) XParseColor(display, tclock->cmap, background, &color);
			(void) XAllocColor(display, tclock->cmap, &color);
			MI_BG_PIXEL(mi) = color.pixel;
			(void) XParseColor(display, tclock->cmap, foreground, &color);
			(void) XAllocColor(display, tclock->cmap, &color);
			MI_FG_PIXEL(mi) = color.pixel;
#endif
			tclock->colors = (XColor *) NULL;
			tclock->ncolors = 0;
		}
		if ((tclock->gc = XCreateGC(display, MI_WINDOW(mi),
			     (unsigned long) 0, (XGCValues *) NULL)) == None) {
			free_toneclock(display, tclock);
			return;
		}
	}
/* Clear Display */
	MI_CLEARWINDOW(mi);
	tclock->painted = False;
	XSetFunction(display, tclock->gc, GXxor);


/*Set up toneclock data */
	if (MI_IS_FULLRANDOM(mi)) {
	   if (NRAND(10))
	     tclock->original = False;
	   else
	     tclock->original = True;
	} else {
	   tclock->original = original;
	}
	tclock->direction = (LRAND() & 1) ? 1 : -1;
	tclock->win_width = MI_WIDTH(mi);
	tclock->win_height = MI_HEIGHT(mi);
	if (tclock->hour != NULL)
		free_hour(tclock);
	if ( tclock->original )
          {
	     tclock->num_hour = 12;
	  }
        else
          {
	     tclock->num_hour = MI_COUNT(mi);
	  }
        tclock->x0 = tclock->win_width / 2;
        tclock->y0 = tclock->win_height / 2;
	if (tclock->num_hour == 0) {
		tclock->num_hour = DEF_NUM_hour;
	} else if (tclock->num_hour < 0) {
		tclock->num_hour = NRAND(-tclock->num_hour) + 1;
	}
        if ( tclock->num_hour < 12 )
          istart = NRAND( 12 - tclock->num_hour );
        else
          istart = 0;
	if ((tclock->hour = (toneclockhour *) calloc(tclock->num_hour,
			sizeof (toneclockhour))) == NULL) {
		free_toneclock(display, tclock);
		return;
	}
	if (MI_IS_INSTALL(mi) && MI_NPIXELS(mi) > 2) {
/* Set up colour map */
		if (tclock->colors != NULL) {
			if (tclock->ncolors && !tclock->no_colors)
				free_colors(display, tclock->cmap, tclock->colors, tclock->ncolors);
			free(tclock->colors);
			tclock->colors = (XColor *) NULL;
		}
		tclock->ncolors = MI_NCOLORS(mi);
		if (tclock->ncolors < 2)
			tclock->ncolors = 2;
		if (tclock->ncolors <= 2)
			tclock->mono_p = True;
		else
			tclock->mono_p = False;

		if (tclock->mono_p)
			tclock->colors = (XColor *) NULL;
		else
			if ((tclock->colors = (XColor *) malloc(sizeof (*tclock->colors) *
					(tclock->ncolors + 1))) == NULL) {
				free_toneclock(display, tclock);
				return;
			}
		tclock->cycle_p = has_writable_cells(mi);
		if (tclock->cycle_p) {
			if (MI_IS_FULLRANDOM(mi)) {
				if (!NRAND(8))
					tclock->cycle_p = False;
				else
					tclock->cycle_p = True;
			} else {
				tclock->cycle_p = cycle_p;
			}
		}
		if (!tclock->mono_p) {
			if (!(LRAND() % 10))
				make_random_colormap(
#ifdef STANDALONE
						MI_DISPLAY(mi), MI_WINDOW(mi),
#else
            mi,
#endif
						tclock->cmap, tclock->colors, &tclock->ncolors,
						True, True, &tclock->cycle_p);
			else if (!(LRAND() % 2))
				make_uniform_colormap(
#ifdef STANDALONE
						MI_DISPLAY(mi), MI_WINDOW(mi),
#else
            mi,
#endif
                  tclock->cmap, tclock->colors, &tclock->ncolors,
						      True, &tclock->cycle_p);
			else
				make_smooth_colormap(
#ifdef STANDALONE
						MI_DISPLAY(mi), MI_WINDOW(mi),
#else
            mi,
#endif
                 tclock->cmap, tclock->colors, &tclock->ncolors,
						     True, &tclock->cycle_p);
		}
		XInstallColormap(display, tclock->cmap);
		if (tclock->ncolors < 2) {
			tclock->ncolors = 2;
			tclock->no_colors = True;
		} else
			tclock->no_colors = False;
		if (tclock->ncolors <= 2)
			tclock->mono_p = True;

		if (tclock->mono_p)
			tclock->cycle_p = False;

	}
#ifndef NO_DBUF
	if (tclock->dbuf != None)
		XFreePixmap(display, tclock->dbuf);
	tclock->dbuf = XCreatePixmap(display, window,
		tclock->win_width,
		tclock->win_height,
		MI_DEPTH(mi));
	/* Allocation checked */
	if (tclock->dbuf != None) {
		XGCValues   gcv;

		gcv.foreground = 0;
		gcv.background = 0;
		gcv.graphics_exposures = False;
		gcv.function = GXcopy;

		if (tclock->dbuf_gc != None)
			XFreeGC(display, tclock->dbuf_gc);
		if ((tclock->dbuf_gc = XCreateGC(display, (Drawable) tclock->dbuf,
			GCForeground | GCBackground | GCGraphicsExposures | GCFunction,
				&gcv)) == None) {
			XFreePixmap(display, tclock->dbuf);
			tclock->dbuf = None;
		} else {
			XFillRectangle(display, (Drawable) tclock->dbuf, tclock->dbuf_gc,
				0, 0, tclock->win_width, tclock->win_height);
			/*XSetBackground(display, MI_GC(mi), MI_BLACK_PIXEL(mi));
			XSetFunction(display, MI_GC(mi), GXcopy);*/
		}
	}
#endif
	tclock->angle = NRAND(360) * PI_RAD;
	tclock->velocity = (NRAND(7) - 3) * PI_RAD;
	size_hour = MIN( tclock->win_width , tclock->win_height) / 3;
   tclock->pulsating = False;
   tclock->moving = False;
   tclock->anglex = 0.0;
   tclock->angley = 0.0;
   tclock->fill = 0;
   tclock->radius = size_hour;
   tclock->max_radius =0.0;
   if ( ( !tclock->original && NRAND( 15 ) == 3 ) || tclock->num_hour > 12 )
     tclock->randomhour = True;
   else
     tclock->randomhour = False;
   if ( !tclock->original && tclock->win_width > 20 )
     {
	if ( abs( MI_SIZE(mi) ) > size_hour ) {
	   if ( MI_SIZE( mi ) < 0 )
	     {
		size_hour = -size_hour;
	     }
	}
	else
	  {
	     size_hour = MI_SIZE(mi);
          }
    	if ( size_hour < 0 )
          {
	     tclock->radius = MIN(NRAND( size_hour - 10) + 10,
		tclock->radius );
          }
        else
          {
  	     tclock->radius = MIN( size_hour , tclock->radius );
          }
	if ( MI_IS_FULLRANDOM( mi ) )
	  {
	     if ( NRAND(2) )
	       tclock->pulsating = True;
	     else
	       tclock->pulsating = False;
	     tclock->fill = NRAND( 101 );
	  }
	else
	  {
	     tclock->pulsating = pulsating;
	     tclock->fill = fill;
	  }
     }
   tclock->phase = 0.0;
   if ( tclock->pulsating )
	tclock->ph_vel = (NRAND(7) - 3) * PI_RAD;
   for (i = 0; i < tclock->num_hour; i++) {
		toneclockhour *hour0;

		hour0 = &tclock->hour[i];
		if (MI_IS_INSTALL(mi) && MI_NPIXELS(mi) > 2) {
			if (tclock->ncolors > 2)
				hour0->colour = NRAND(tclock->ncolors - 2) + 2;
			else
				hour0->colour = 1;	/* Just in case */
			XSetForeground(display, tclock->gc, tclock->colors[hour0->colour].pixel);
		} else {
			if (MI_NPIXELS(mi) > 2)
				hour0->colour = MI_PIXEL(mi, NRAND(MI_NPIXELS(mi)));
			else
				hour0->colour = 1;	/*Xor'red so WHITE may not be appropriate */
			XSetForeground(display, tclock->gc, hour0->colour);
		}
		hour0->angle = NRAND(360) * PI_RAD;
		hour0->velocity = (NRAND(7) - 3) * PI_RAD;
	        hour0->radius = tclock->radius / 5.0;
      		tclock->max_radius = MAX( tclock->max_radius , hour0->radius );
	        hour0->num_point = 12;
		hour0->num_point1 = 16;
                if ( tclock->randomhour )
	          {
		     int j;

		     hour0->point_numbers = tclock->hexadecimal_clock + i *
			     hour0->num_point1;
		     if ( NRAND( 14 ) == 4 )
		       {
			  for (j = 0; j < ( hour0->num_point1 / 4 ) - 1 ; j++)
			    {
			       hour0->point_numbers[ j * 4 ] = NRAND( 12 ) + 1;
			       hour0->point_numbers[ j * 4 + 1 ] = NRAND( 12 )
				 + 1;
			       hour0->point_numbers[ j * 4 + 2 ] = NRAND( 12 )
				 + 1;
			       hour0->point_numbers[ j * 4 + 3 ] = NRAND( 12 )
				 + 1;
			    }
			  hour0->point_numbers[ hour0->num_point1 / 4 ] = 1;
			  hour0->point_numbers[ 1 + hour0->num_point1 / 4 ] =
			    1;
			  hour0->point_numbers[ 2 + hour0->num_point1 / 4 ] =
			    1;
			  hour0->point_numbers[ 3 + hour0->num_point1 / 4 ] =
			    1;
		       }
		     else
		       {
			  for (j = 0; j < hour0->num_point1 / 4 ; j++)
			    {
			       hour0->point_numbers[ j * 4 ] = NRAND( 12 ) + 1;
			       hour0->point_numbers[ j * 4 + 1 ] =
				 hour0->point_numbers[ j * 4 ];
			       hour0->point_numbers[ j * 4 + 2 ] = NRAND( 12 )
				 + 1;
			       hour0->point_numbers[ j * 4 + 3 ] = NRAND( 12 )
				 + 1;
			    }
		       }
	          }
                else
	          hour0->point_numbers = original_clock[i+istart];
		if ( NRAND( 100 ) >= tclock->fill )
			hour0->draw = True;
		else
			hour0->draw = False;
#ifdef NO_DBUF
		{
		  int x0 , y0;

		  x0 = (int) (tclock->radius * sin( -tclock->angle - PI_RAD * i *
			360.0 / tclock->num_hour ) *
			0.5 * ( 1 + cos( tclock->phase ) ) + tclock->x0 +
			tclock->a_x * sin( tclock->anglex ) );
		  y0 = (int) (tclock->radius * cos( -tclock->angle - PI_RAD * i *
			360.0 / tclock->num_hour ) *
			0.5 * ( 1 + cos( tclock->phase ) ) + tclock->y0 +
			tclock->a_y * sin( tclock->angley ) );
	 	  toneclock_drawhour(mi , hour0 , x0 , y0 );
		}
#endif
	}
   tclock->a_x = 0;
   tclock->a_y = 0;
   if ( !tclock->original && tclock->win_width > 20 )
     {
	if ( tclock->radius < MIN( tclock->win_width , tclock->win_height) /
	     4 )
	  {
	     if ( MI_IS_FULLRANDOM( mi ) )
	       {
		  if ( NRAND(2) )
		    tclock->moving = True;
	       }
	     else
	       {
		    tclock->moving = move_clock;
	       }
	     if ( tclock->moving )
	       {
		  tclock->a_x = (int) floor( ( tclock->win_width / 2 ) - 1.05 *
					( tclock->radius + tclock->max_radius )
					);
		  tclock->a_y = (int) floor( ( tclock->win_height / 2 ) - 1.05 *
					( tclock->radius + tclock->max_radius )
					);
		  tclock->vx = (NRAND(15) - 7) * PI_RAD;
		  tclock->vy = (NRAND(15) - 7) * PI_RAD;
	       }
	  }
     }
	XFlush(display);
	XSetFunction(display, tclock->gc, GXcopy);
}
Esempio n. 24
0
void
init_laser(ModeInfo * mi)
{
	Display *display = MI_DISPLAY(mi);
	int         i, c = 0;
	lasersstruct *lp;

	if (lasers == NULL) {
		if ((lasers = (lasersstruct *) calloc(MI_NUM_SCREENS(mi),
					     sizeof (lasersstruct))) == NULL)
			return;
	}
	lp = &lasers[MI_SCREEN(mi)];

	lp->width = MI_WIDTH(mi);
	lp->height = MI_HEIGHT(mi);
	lp->time = 0;

	lp->ln = MI_COUNT(mi);
	if (lp->ln < -MINLASER) {
		/* if lp->ln is random ... the size can change */
		if (lp->laser != NULL) {
			free(lp->laser);
			lp->laser = (laserstruct *) NULL;
		}
		lp->ln = NRAND(-lp->ln - MINLASER + 1) + MINLASER;
	} else if (lp->ln < MINLASER)
		lp->ln = MINLASER;

	if (lp->laser == NULL) {
		if ((lp->laser = (laserstruct *) malloc(lp->ln *
				sizeof (laserstruct))) == NULL) {
			free_laser(display, lp);
			return;
		}
	}
	if (lp->stippledGC == None) {
		XGCValues   gcv;

		gcv.foreground = MI_WHITE_PIXEL(mi);
		gcv.background = MI_BLACK_PIXEL(mi);
		lp->gcv_black.foreground = MI_BLACK_PIXEL(mi);
		if ((lp->stippledGC = XCreateGC(display, MI_WINDOW(mi),
				GCForeground | GCBackground, &gcv)) == None) {
			free_laser(display, lp);
			return;
		}
	}
	MI_CLEARWINDOWCOLORMAPFAST(mi, MI_GC(mi), MI_BLACK_PIXEL(mi));

	if (MINDIST < lp->width - MINDIST)
		lp->cx = RANGE_RAND(MINDIST, lp->width - MINDIST);
	else
		lp->cx = RANGE_RAND(0, lp->width);
	if (MINDIST < lp->height - MINDIST)
		lp->cy = RANGE_RAND(MINDIST, lp->height - MINDIST);
	else
		lp->cy = RANGE_RAND(0, lp->height);
	lp->lw = RANGE_RAND(MINWIDTH, MAXWIDTH);
	lp->lr = RANGE_RAND(MINREDRAW, MAXREDRAW);
	lp->sw = 0;
	lp->so = 0;

	if (MI_NPIXELS(mi) > 2)
		c = NRAND(MI_NPIXELS(mi));

	for (i = 0; i < lp->ln; i++) {
		laserstruct *l = &lp->laser[i];

		l->bn = (border) NRAND(4);

		switch (l->bn) {
			case TOP:
				l->bx = NRAND(lp->width);
				l->by = 0;
				break;
			case RIGHT:
				l->bx = lp->width;
				l->by = NRAND(lp->height);
				break;
			case BOTTOM:
				l->bx = NRAND(lp->width);
				l->by = lp->height;
				break;
			case LEFT:
				l->bx = 0;
				l->by = NRAND(lp->height);
		}

		l->dir = (int) (LRAND() & 1);
		l->speed = ((RANGE_RAND(MINSPEED, MAXSPEED) * lp->width) / 1000) + 1;
		if (MI_NPIXELS(mi) > 2) {
			l->gcv.foreground = MI_PIXEL(mi, c);
			c = (c + COLORSTEP) % MI_NPIXELS(mi);
		} else
			l->gcv.foreground = MI_WHITE_PIXEL(mi);
	}
}
Esempio n. 25
0
static Bool
draw_state(ModeInfo * mi, int state)
{
	demonstruct *dp = &demons[MI_SCREEN(mi)];
	GC          gc;
	XRectangle *rects;
	CellList   *current;

	if (!state) {
		XSetForeground(MI_DISPLAY(mi), MI_GC(mi), MI_BLACK_PIXEL(mi));
		gc = MI_GC(mi);
	} else if (MI_NPIXELS(mi) >= NUMSTIPPLES) {
		XSetForeground(MI_DISPLAY(mi), MI_GC(mi),
			   MI_PIXEL(mi, (((int) state - 1) * MI_NPIXELS(mi) /
					 (dp->states - 1)) % MI_NPIXELS(mi)));
		gc = MI_GC(mi);
	} else {
		XGCValues   gcv;

#ifdef DO_STIPPLE
		gcv.stipple = dp->pixmaps[(state - 1) % (NUMSTIPPLES - 1)];
#endif /* DO_STIPPLE */
		gcv.foreground = MI_WHITE_PIXEL(mi);
		gcv.background = MI_BLACK_PIXEL(mi);
		XChangeGC(MI_DISPLAY(mi), dp->stippledGC,
			  GCStipple | GCForeground | GCBackground, &gcv);
		gc = dp->stippledGC;
	}
	if (dp->neighbors == 6) {	/* Draw right away, slow */
		current = dp->cellList[state];
		while (current) {
			int         col, row, ccol, crow;

			col = current->pt.x;
			row = current->pt.y;
			ccol = 2 * col + !(row & 1), crow = 2 * row;
			dp->shape.hexagon[0].x = dp->xb + ccol * dp->xs;
			dp->shape.hexagon[0].y = dp->yb + crow * dp->ys;
			if (dp->xs == 1 && dp->ys == 1)
				XDrawPoint(MI_DISPLAY(mi), MI_WINDOW(mi),
					       gc, dp->shape.hexagon[0].x, dp->shape.hexagon[0].y);
			else
				XFillPolygon(MI_DISPLAY(mi), MI_WINDOW(mi), gc,
					     dp->shape.hexagon, 6, Convex, CoordModePrevious);
			current = current->next;
		}
	} else if (dp->neighbors == 4 || dp->neighbors == 8) {
		/* Take advantage of XDrawRectangles */
		int         ncells = 0;

		/* Create Rectangle list from part of the cellList */
		if ((rects = (XRectangle *) malloc(dp->ncells[state] *
			 sizeof (XRectangle))) == NULL) {
			return False;
		}
		current = dp->cellList[state];
		while (current) {
			rects[ncells].x = dp->xb + current->pt.x * dp->xs;
			rects[ncells].y = dp->yb + current->pt.y * dp->ys;
			rects[ncells].width = dp->xs - (dp->xs > 3);
			rects[ncells].height = dp->ys - (dp->ys > 3);
			current = current->next;
			ncells++;
		}
		/* Finally get to draw */
		XFillRectangles(MI_DISPLAY(mi), MI_WINDOW(mi), gc, rects, ncells);
		/* Free up rects list and the appropriate part of the cellList */
		(void) free((void *) rects);
	} else {		/* TRI */
		current = dp->cellList[state];
		while (current) {
			int         col, row, orient;

			col = current->pt.x;
			row = current->pt.y;
			orient = (col + row) % 2;	/* O left 1 right */
			dp->shape.triangle[orient][0].x = dp->xb + col * dp->xs;
			dp->shape.triangle[orient][0].y = dp->yb + row * dp->ys;
			if (dp->xs <= 3 || dp->ys <= 3)
				XDrawPoint(MI_DISPLAY(mi), MI_WINDOW(mi), gc,
					       ((orient) ? -1 : 1) + dp->shape.triangle[orient][0].x,
				      dp->shape.triangle[orient][0].y);
			else {
				if (orient)
					dp->shape.triangle[orient][0].x += (dp->xs / 2 - 1);
				else
					dp->shape.triangle[orient][0].x -= (dp->xs / 2 - 1);
				XFillPolygon(MI_DISPLAY(mi), MI_WINDOW(mi), gc,
					     dp->shape.triangle[orient], 3, Convex, CoordModePrevious);
			}
			current = current->next;
		}
	}
	free_state(dp, state);
	return True;
}
Esempio n. 26
0
static void
drawcell(ModeInfo * mi, int col, int row, unsigned char state)
{
	demonstruct *dp = &demons[MI_SCREEN(mi)];
	GC          gc;

	if (!state) {
		XSetForeground(MI_DISPLAY(mi), MI_GC(mi), MI_BLACK_PIXEL(mi));
		gc = MI_GC(mi);
	} else if (MI_NPIXELS(mi) >= NUMSTIPPLES) {
		XSetForeground(MI_DISPLAY(mi), MI_GC(mi),
			   MI_PIXEL(mi, (((int) state - 1) * MI_NPIXELS(mi) /
					 (dp->states - 1)) % MI_NPIXELS(mi)));
		gc = MI_GC(mi);
	} else {
		XGCValues   gcv;

#ifdef DO_STIPPLE
		gcv.stipple = dp->pixmaps[(state - 1) % (NUMSTIPPLES - 1)];
#endif /* DO_STIPPLE */
		gcv.foreground = MI_WHITE_PIXEL(mi);
		gcv.background = MI_BLACK_PIXEL(mi);
		XChangeGC(MI_DISPLAY(mi), dp->stippledGC,
			  GCStipple | GCForeground | GCBackground, &gcv);
		gc = dp->stippledGC;
	}
	if (dp->neighbors == 6) {
		int         ccol = 2 * col + !(row & 1), crow = 2 * row;

		dp->shape.hexagon[0].x = dp->xb + ccol * dp->xs;
		dp->shape.hexagon[0].y = dp->yb + crow * dp->ys;
		if (dp->xs == 1 && dp->ys == 1)
			XDrawPoint(MI_DISPLAY(mi), MI_WINDOW(mi),
				       gc, dp->shape.hexagon[0].x, dp->shape.hexagon[0].y);
		else
			XFillPolygon(MI_DISPLAY(mi), MI_WINDOW(mi), gc,
			    dp->shape.hexagon, 6, Convex, CoordModePrevious);
	} else if (dp->neighbors == 4 || dp->neighbors == 8) {
		XFillRectangle(MI_DISPLAY(mi), MI_WINDOW(mi), gc,
		dp->xb + dp->xs * col, dp->yb + dp->ys * row,
		dp->xs - (dp->xs > 3), dp->ys - (dp->ys > 3));
	} else {		/* TRI */
		int         orient = (col + row) % 2;	/* O left 1 right */

		dp->shape.triangle[orient][0].x = dp->xb + col * dp->xs;
		dp->shape.triangle[orient][0].y = dp->yb + row * dp->ys;
		if (dp->xs <= 3 || dp->ys <= 3)
			XDrawPoint(MI_DISPLAY(mi), MI_WINDOW(mi), gc,
			((orient) ? -1 : 1) + dp->shape.triangle[orient][0].x,
				       dp->shape.triangle[orient][0].y);
		else {
			if (orient)
				dp->shape.triangle[orient][0].x += (dp->xs / 2 - 1);
			else
				dp->shape.triangle[orient][0].x -= (dp->xs / 2 - 1);
			XFillPolygon(MI_DISPLAY(mi), MI_WINDOW(mi), gc,
				     dp->shape.triangle[orient], 3, Convex, CoordModePrevious);

		}
	}
}
Esempio n. 27
0
void
draw_mandelbrot(ModeInfo * mi)
{
	Display    *display = MI_DISPLAY(mi);
	Window      window = MI_WINDOW(mi);
	int         h;
	complex     c;
	double      demrange;
	mandelstruct *mp;

	if (mandels == NULL)
		return;
	mp = &mandels[MI_SCREEN(mi)];

	MI_IS_DRAWN(mi) = True;
        if (MI_IS_INSTALL(mi) && MI_NPIXELS(mi) > 2) {
                if (mp->mono_p) {
                        XSetForeground(display, mp->gc, mp->cur_color);
                } else {
                        mp->cur_color = (mp->cur_color + 1) % mp->ncolors;
                        XSetForeground(display, mp->gc, mp->colors[mp->cur_color].pixel);
                }
        } else {
                if (MI_NPIXELS(mi) > 2)
                        XSetForeground(display, mp->gc, MI_PIXEL(mi, mp->cur_color));
                else if (mp->cur_color)
                        XSetForeground(display, mp->gc, MI_BLACK_PIXEL(mi));
                else
                        XSetForeground(display, mp->gc, MI_WHITE_PIXEL(mi));
                if (++mp->cur_color >= (unsigned int) MI_NPIXELS(mi))
                        mp->cur_color = 0;
        }

  /* Rotate colours */
  if (mp->cycle_p) {
    rotate_colors(display, mp->cmap, mp->colors, mp->ncolors,
      mp->direction);
    if (!(LRAND() % 1000))
      mp->direction = -mp->direction;
  }
	/* so we iterate columns beyond the width of the physical screen, so that
	** we just wait around and show what we've done
	*/
	if ((!mp->backwards && (mp->column >= 3 * mp->screen_width)) ||
	    (mp->backwards && (mp->column < -2 * mp->screen_width))) {
		/* reset to left edge of screen, bump power */
		mp->backwards = (Bool) (LRAND() & 1);
		if (mp->backwards)
			mp->column = mp->screen_width - 1;
		else
			mp->column = 0;
		mp->power = NRAND(3) + MINPOWER;
		/* select a new region! */
		Select(&mp->extreme_ul,&mp->extreme_lr,
			mp->screen_width,mp->screen_height,
			(int) mp->power,mp->reptop, mp->pow, mp->sin,
			&mp->ul,&mp->lr);
	} else if (mp->column >= mp->screen_width || mp->column < 0) {
		/* delay a while */
		if (mp->backwards)
			mp->column--;
		else
			mp->column++;
		mp->counter++;
		return;
	}
	/* demrange is used to give some idea of scale */
	demrange = mp->dem ? fabs(mp->ul.real - mp->lr.real) / 2 : 0;
	for (h = 0; h < mp->screen_height; h++) {
		unsigned int color;
		int         result;

		/* c.real = 1.3 - (double) mp->column / mp->screen_width * 3.4; */
		/* c.imag = -1.6 + (double) h / mp->screen_height * 3.2; */
		c.real = mp->ul.real +
			(mp->ul.real-mp->lr.real)*(((double)(mp->column))/mp->screen_width);
		c.imag = mp->ul.imag +
			(mp->ul.imag - mp->lr.imag)*(((double) h) / mp->screen_height);
		result = reps(c, mp->power, mp->reptop, mp->binary, mp->interior, demrange, mp->pow, mp->sin);
		if (result < 0 || result >= mp->reptop)
			XSetForeground(display, mp->gc, MI_BLACK_PIXEL(mi));
		else {
			color=(unsigned int) ((MI_NPIXELS(mi) * (float)result) / mp->reptop);
			XSetForeground(display, mp->gc, MI_PIXEL(mi, color));
		}
		/* we no longer have vertical symmetry - so we compute all points
		** and don't draw with redundancy
		*/
		XDrawPoint(display, window, mp->gc, mp->column, h);
	}
	if (mp->backwards)
		mp->column--;
	else
		mp->column++;

	mp->counter++;
	if (mp->counter > MI_CYCLES(mi)) {
		init_mandelbrot(mi);
	}
}
Esempio n. 28
0
void
init_puzzle(ModeInfo * mi)
{
	Display    *display = MI_DISPLAY(mi);
	Window      window = MI_WINDOW(mi);
	puzzlestruct *pp;
	int         x, y;
	XPoint      size;

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

	if (pp->painted && pp->windowsize.x == MI_WIDTH(mi) &&
	    pp->windowsize.y == MI_HEIGHT(mi))
		return;		/* Debounce since refresh_puzzle is init_puzzle */

#ifdef HAVE_XPM
	if (pp->graphics_format >= IS_XPM) {
        	/* This is needed when another program changes the colormap. */
        	free_puzzle(display, pp);
	}
#endif
	if (!init_stuff(mi))
		return;
	pp->excount = MI_COUNT(mi);
	if (pp->excount < 0) {
		if (pp->fixbuff != NULL) {
			free(pp->fixbuff);
			pp->fixbuff = (int *) NULL;
		}
		pp->excount = NRAND(-pp->excount) + 1;
	}
	pp->lastbox = -1;
	pp->moves = 0;
	pp->movingBox = False;

	pp->windowsize.x = MI_WIDTH(mi);
	pp->windowsize.y = MI_HEIGHT(mi);
	if (pp->windowsize.x < 7)
		pp->windowsize.x = 7;
	if (pp->windowsize.y < 7)
		pp->windowsize.y = 7;
	pp->forward = 1;
	pp->prev = 0;
	/* don't want any exposure events from XCopyArea */
	XSetGraphicsExposures(display, pp->backGC, False);

	MI_CLEARWINDOWCOLORMAP(mi, pp->backGC, pp->black);

	if (pp->logo) {
		size.x = (pp->logo->width < pp->windowsize.x) ?
			pp->logo->width : pp->windowsize.x;
		size.y = (pp->logo->height < pp->windowsize.y) ?
			pp->logo->height : pp->windowsize.y;
	} else {
		size.x = pp->windowsize.x;
		size.y = pp->windowsize.y;
	}
	pp->boxsize.y = NRAND(1 + size.y / 4) + 6;
	pp->boxsize.x = NRAND(1 + size.x / 4) + 6;
	if ((pp->boxsize.x > 4 * pp->boxsize.y) ||
	    pp->boxsize.y > 4 * pp->boxsize.x)
		pp->boxsize.x = pp->boxsize.y = 2 * MIN(pp->boxsize.x, pp->boxsize.y);
	pp->count.x = size.x / pp->boxsize.x;
	pp->count.y = size.y / pp->boxsize.y;

	if (pp->bufferBox != None) {
		XFreePixmap(display, pp->bufferBox);
		pp->bufferBox = None;
	}
	pp->usablewindow.x = pp->count.x * pp->boxsize.x;
	pp->usablewindow.y = pp->count.y * pp->boxsize.y;
	pp->offsetwindow.x = (pp->windowsize.x - pp->usablewindow.x) / 2;
	pp->offsetwindow.y = (pp->windowsize.y - pp->usablewindow.y) / 2;

	pp->incrementOfMove = MIN(pp->usablewindow.x, pp->usablewindow.y) / 20;
	pp->incrementOfMove = MAX(pp->incrementOfMove, 1);

	if (pp->logo) {
		pp->randompos.x = NRAND(MAX((pp->windowsize.x - pp->logo->width),
					    2 * pp->offsetwindow.x + 1));
		pp->randompos.y = NRAND(MAX((pp->windowsize.y - pp->logo->height),
					    2 * pp->offsetwindow.y + 1));
		if (MI_NPIXELS(mi) <= 2)
			XSetForeground(display, pp->backGC, MI_WHITE_PIXEL(mi));
		else
			XSetForeground(display, pp->backGC, MI_PIXEL(mi, NRAND(MI_NPIXELS(mi))));
		(void) XPutImage(display, window, pp->backGC, pp->logo,
		(int) (NRAND(MAX(1, (pp->logo->width - pp->usablewindow.x)))),
				 (int) (NRAND(MAX(1, (pp->logo->height - pp->usablewindow.y)))),
				 pp->randompos.x, pp->randompos.y,
				 pp->usablewindow.x, pp->usablewindow.y);
		XSetForeground(display, pp->backGC, pp->black);
		for (x = 0; x <= pp->count.x; x++) {
			int         tempx = x * pp->boxsize.x;

			XDrawLine(display, window, pp->backGC,
				  tempx + pp->randompos.x, pp->randompos.y,
				  tempx + pp->randompos.x, pp->usablewindow.y + pp->randompos.y);
			XDrawLine(display, window, pp->backGC,
				tempx + pp->randompos.x - 1, pp->randompos.y,
				  tempx + pp->randompos.x - 1, pp->usablewindow.y + pp->randompos.y);
		}
		for (y = 0; y <= pp->count.y; y++) {
			int         tempy = y * pp->boxsize.y;

			XDrawLine(display, window, pp->backGC,
				  pp->randompos.x, tempy + pp->randompos.y,
				  pp->usablewindow.x + pp->randompos.x, tempy + pp->randompos.y);
			XDrawLine(display, window, pp->backGC,
				pp->randompos.x, tempy + pp->randompos.y - 1,
				  pp->usablewindow.x + pp->randompos.x, tempy + pp->randompos.y - 1);
		}
	}
#ifdef NUMBERED
	else {
		if (pp->image)
			(void) XDestroyImage(pp->image);
		pp->randompos.x = pp->offsetwindow.x;
		pp->randompos.y = pp->offsetwindow.y;
		if (!NumberScreen(mi)) {
			release_puzzles(mi);
			return;
		}
		if ((pp->image = XGetImage(display, window,
				      pp->offsetwindow.x, pp->offsetwindow.y,
				      pp->usablewindow.x, pp->usablewindow.y,
				      AllPlanes,
				 (MI_NPIXELS(mi) <= 2) ? XYPixmap : ZPixmap)) == None) {
			free_puzzle(display, pp);
			return;
		}
	}

	pp->row = pp->count.y - 1;
	pp->col = pp->count.x - 1;
#else
	pp->row = NRAND(pp->count.y);
	pp->col = NRAND(pp->count.x);
#endif

	if ((pp->excount) && (pp->fixbuff == NULL))
		if ((pp->fixbuff = (int *) calloc(pp->excount,
				sizeof (int))) == NULL) {
			free_puzzle(display, pp);
			return;
		}
	pp->painted = True;
}
Esempio n. 29
0
ENTRYPOINT void
draw_braid(ModeInfo * mi)
{
	Display    *display = MI_DISPLAY(mi);
	Window      window = MI_WINDOW(mi);
	int         num_points = 500;
	float       t_inc;
	float       theta, psi;
	float       t, r_diff;
	int         i, s;
	float       x_1, y_1, x_2, y_2, r1, r2;
	float       color, color_use = 0.0, color_inc;
	braidtype  *braid;

	if (braids == NULL)
		return;
	braid = &braids[MI_SCREEN(mi)];

#ifdef STANDALONE
    if (braid->eraser) {
      braid->eraser = erase_window (MI_DISPLAY(mi), MI_WINDOW(mi), braid->eraser);
      return;
    }
#endif

	MI_IS_DRAWN(mi) = True;
	XSetLineAttributes(display, MI_GC(mi), braid->linewidth,
			   LineSolid,
			   (braid->linewidth <= 3 ? CapButt : CapRound),
			   JoinMiter);

	theta = (2.0 * M_PI) / (float) (braid->braidlength);
	t_inc = (2.0 * M_PI) / (float) num_points;
	color_inc = (float) MI_NPIXELS(mi) * braid->color_direction /
		(float) num_points;
	braid->startcolor += SPINRATE * color_inc;
	if (((int) braid->startcolor) >= MI_NPIXELS(mi))
		braid->startcolor = 0.0;

	r_diff = (braid->max_radius - braid->min_radius) / (float) (braid->nstrands);

	color = braid->startcolor;
	psi = 0.0;
	for (i = 0; i < braid->braidlength; i++) {
		psi += theta;
		for (t = 0.0; t < theta; t += t_inc) {
#ifdef COLORROUND
			color += color_inc;
			if (((int) color) >= MI_NPIXELS(mi))
				color = 0.0;
			color_use = color;
#endif
			for (s = 0; s < braid->nstrands; s++) {
				if (ABS(braid->braidword[i]) == s)
					continue;
				if (ABS(braid->braidword[i]) - 1 == s) {
					/* crosSINFg */
#ifdef COLORCOMP
					if (MI_NPIXELS(mi) > 2) {
						color_use = color + SPINRATE *
							braid->components[applywordbackto(braid, s, i)] +
							(psi + t) / 2.0 / M_PI * (float) MI_NPIXELS(mi);
						while (((int) color_use) >= MI_NPIXELS(mi))
							color_use -= (float) MI_NPIXELS(mi);
						while (((int) color_use) < 0)
							color_use += (float) MI_NPIXELS(mi);
					}
#endif
#ifdef COLORROUND
					if (MI_NPIXELS(mi) > 2) {
						color_use += SPINRATE * color_inc;
						while (((int) color_use) >= MI_NPIXELS(mi))
							color_use -= (float) MI_NPIXELS(mi);
					}
#endif
					r1 = braid->min_radius + r_diff * (float) (s);
					r2 = braid->min_radius + r_diff * (float) (s + 1);
					if (braid->braidword[i] > 0 ||
					    (FABSF(t - theta / 2.0) > theta / 7.0)) {
						x_1 = ((0.5 * (1.0 + SINF(t / theta * M_PI - M_PI_2)) * r2 +
							0.5 * (1.0 + SINF((theta - t) / theta * M_PI - M_PI_2)) * r1)) *
							COSF(t + psi) + braid->center_x;
						y_1 = ((0.5 * (1.0 + SINF(t / theta * M_PI - M_PI_2)) * r2 +
							0.5 * (1.0 + SINF((theta - t) / theta * M_PI - M_PI_2)) * r1)) *
							SINF(t + psi) + braid->center_y;
						x_2 = ((0.5 * (1.0 + SINF((t + t_inc) / theta * M_PI - M_PI_2)) * r2 +
							0.5 * (1.0 + SINF((theta - t - t_inc) / theta * M_PI - M_PI_2)) * r1)) *
							COSF(t + t_inc + psi) + braid->center_x;
						y_2 = ((0.5 * (1.0 + SINF((t + t_inc) / theta * M_PI - M_PI_2)) * r2 +
							0.5 * (1.0 + SINF((theta - t - t_inc) / theta * M_PI - M_PI_2)) * r1)) *
							SINF(t + t_inc + psi) + braid->center_y;
						if (MI_NPIXELS(mi) > 2)
							XSetForeground(display, MI_GC(mi), MI_PIXEL(mi, (int) color_use));
						else
							XSetForeground(display, MI_GC(mi), MI_WHITE_PIXEL(mi));

						XDrawLine(display, window, MI_GC(mi),
							  (int) (x_1), (int) (y_1), (int) (x_2), (int) (y_2));
					}
#ifdef COLORCOMP
					if (MI_NPIXELS(mi) > 2) {
						color_use = color + SPINRATE *
							braid->components[applywordbackto(braid, s + 1, i)] +
							(psi + t) / 2.0 / M_PI * (float) MI_NPIXELS(mi);
						while (((int) color_use) >= MI_NPIXELS(mi))
							color_use -= (float) MI_NPIXELS(mi);
						while (((int) color_use) < 0)
							color_use += (float) MI_NPIXELS(mi);
					}
#endif
					if (braid->braidword[i] < 0 ||
					    (FABSF(t - theta / 2.0) > theta / 7.0)) {
						x_1 = ((0.5 * (1.0 + SINF(t / theta * M_PI - M_PI_2)) * r1 +
							0.5 * (1.0 + SINF((theta - t) / theta * M_PI - M_PI_2)) * r2)) *
							COSF(t + psi) + braid->center_x;
						y_1 = ((0.5 * (1.0 + SINF(t / theta * M_PI - M_PI_2)) * r1 +
							0.5 * (1.0 + SINF((theta - t) / theta * M_PI - M_PI_2)) * r2)) *
							SINF(t + psi) + braid->center_y;
						x_2 = ((0.5 * (1.0 + SINF((t + t_inc) / theta * M_PI - M_PI_2)) * r1 +
							0.5 * (1.0 + SINF((theta - t - t_inc) / theta * M_PI - M_PI_2)) * r2)) *
							COSF(t + t_inc + psi) + braid->center_x;
						y_2 = ((0.5 * (1.0 + SINF((t + t_inc) / theta * M_PI - M_PI_2)) * r1 +
							0.5 * (1.0 + SINF((theta - t - t_inc) / theta * M_PI - M_PI_2)) * r2)) *
							SINF(t + t_inc + psi) + braid->center_y;
						if (MI_NPIXELS(mi) > 2)
							XSetForeground(display, MI_GC(mi), MI_PIXEL(mi, (int) color_use));
						else
							XSetForeground(display, MI_GC(mi), MI_WHITE_PIXEL(mi));

						XDrawLine(display, window, MI_GC(mi),
							  (int) (x_1), (int) (y_1), (int) (x_2), (int) (y_2));
					}
				} else {
					/* no crosSINFg */
#ifdef COLORCOMP
					if (MI_NPIXELS(mi) > 2) {
						color_use = color + SPINRATE *
							braid->components[applywordbackto(braid, s, i)] +
							(psi + t) / 2.0 / M_PI * (float) MI_NPIXELS(mi);
						while (((int) color_use) >= MI_NPIXELS(mi))
							color_use -= (float) MI_NPIXELS(mi);
						while (((int) color_use) < 0)
							color_use += (float) MI_NPIXELS(mi);
					}
#endif
#ifdef COLORROUND
					if (MI_NPIXELS(mi) > 2) {
						color_use += SPINRATE * color_inc;
						while (((int) color_use) >= MI_NPIXELS(mi))
							color_use -= (float) MI_NPIXELS(mi);
					}
#endif
					r1 = braid->min_radius + r_diff * (float) (s);
					x_1 = r1 * COSF(t + psi) + braid->center_x;
					y_1 = r1 * SINF(t + psi) + braid->center_y;
					x_2 = r1 * COSF(t + t_inc + psi) + braid->center_x;
					y_2 = r1 * SINF(t + t_inc + psi) + braid->center_y;
					if (MI_NPIXELS(mi) > 2)
						XSetForeground(display, MI_GC(mi), MI_PIXEL(mi, (int) color_use));
					else
						XSetForeground(display, MI_GC(mi), MI_WHITE_PIXEL(mi));

					XDrawLine(display, window, MI_GC(mi),
						  (int) (x_1), (int) (y_1), (int) (x_2), (int) (y_2));
				}
			}
		}
	}
	XSetLineAttributes(display, MI_GC(mi), 1, LineSolid, CapNotLast, JoinRound);

	if (++braid->age > MI_CYCLES(mi)) {
#ifdef STANDALONE
      braid->eraser = erase_window (MI_DISPLAY(mi), MI_WINDOW(mi), braid->eraser);
#endif
		init_braid(mi);
	}
}
Esempio n. 30
0
ENTRYPOINT void
draw_strange(ModeInfo * mi)
{
	int         i, j, n, Cur_Pt;
	PRM         x, y, xo, yo;
	DBL         u;
	XPoint     *Buf;
	Display    *display = MI_DISPLAY(mi);
	Window      window = MI_WINDOW(mi);
	GC          gc = MI_GC(mi);
	DBL         Lx, Ly;
	void        (*Iterate) (ATTRACTOR *, PRM, PRM, PRM *, PRM *);
	PRM         xmin, xmax, ymin, ymax;
	ATTRACTOR  *A;

	if (Root == NULL)
		return;
	A = &Root[MI_SCREEN(mi)];
	if (A->Fold == NULL)
		return;

	Cur_Pt = A->Cur_Pt;
	Iterate = A->Iterate;

	u = (DBL) (A->Count) / 1000.0;
	for (j = MAX_PRM - 1; j >= 0; --j)
		A->Prm[j] = DBL_To_PRM((1.0 - u) * A->Prm1[j] + u * A->Prm2[j]);

	x = y = DBL_To_PRM(.0);
	for (n = SKIP_FIRST; n; --n) {
		(*Iterate) (A, x, y, &xo, &yo);
		x = xo + NRAND(8) - 4;
		y = yo + NRAND(8) - 4;
	}

	xmax = 0;
	xmin = UNIT * 4;
	ymax = 0;
	ymin = UNIT * 4;
	A->Cur_Pt = 0;
	Buf = A->Buffer2;
	Lx = (DBL) A->Width / UNIT / 2.2;
	Ly = (DBL) A->Height / UNIT / 2.2;
	for (n = A->Max_Pt; n; --n) {
		(*Iterate) (A, x, y, &xo, &yo);
		Buf->x = (int) (Lx * (x + DBL_To_PRM(1.1)));
		Buf->y = (int) (Ly * (DBL_To_PRM(1.1) - y));
		/* (void) fprintf( stderr, "X,Y: %d %d    ", Buf->x, Buf->y ); */
		Buf++;
		A->Cur_Pt++;
		if (xo > xmax)
			xmax = xo;
		else if (xo < xmin)
			xmin = xo;
		if (yo > ymax)
			ymax = yo;
		else if (yo < ymin)
			ymin = yo;
		x = xo + NRAND(8) - 4;
		y = yo + NRAND(8) - 4;
	}

	MI_IS_DRAWN(mi) = True;

	XSetForeground(display, gc, MI_BLACK_PIXEL(mi));

	if (A->dbuf != None) {		/* jwz */
		XSetForeground(display, A->dbuf_gc, 0);
/* XDrawPoints(display, A->dbuf, A->dbuf_gc, A->Buffer1,
   Cur_Pt,CoordModeOrigin); */
		XFillRectangle(display, A->dbuf, A->dbuf_gc, 0, 0, A->Width, A->Height);
	} else
		XDrawPoints(display, window, gc, A->Buffer1, Cur_Pt, CoordModeOrigin);

	if (MI_NPIXELS(mi) < 2)
		XSetForeground(display, gc, MI_WHITE_PIXEL(mi));
	else
		XSetForeground(display, gc, MI_PIXEL(mi, A->Col % MI_NPIXELS(mi)));

	if (A->dbuf != None) {
		XSetForeground(display, A->dbuf_gc, 1);
		XDrawPoints(display, A->dbuf, A->dbuf_gc, A->Buffer2, A->Cur_Pt,
			    CoordModeOrigin);
		XCopyPlane(display, A->dbuf, window, gc, 0, 0, A->Width, A->Height, 0, 0, 1);
	} else
		XDrawPoints(display, window, gc, A->Buffer2, A->Cur_Pt, CoordModeOrigin);

	Buf = A->Buffer1;
	A->Buffer1 = A->Buffer2;
	A->Buffer2 = Buf;

	if ((xmax - xmin < DBL_To_PRM(.2)) && (ymax - ymin < DBL_To_PRM(.2)))
		A->Count += 4 * A->Speed;
	else
		A->Count += A->Speed;
	if (A->Count >= 1000) {
		for (i = MAX_PRM - 1; i >= 0; --i)
			A->Prm1[i] = A->Prm2[i];
		Random_Prm(A->Prm2);
		A->Count = 0;
	}
	A->Col++;
}