示例#1
0
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);
}
示例#2
0
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 */
	}

}
示例#3
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);
}
示例#4
0
ENTRYPOINT void
init_galaxy(ModeInfo * mi)
{
 unistruct  *gp;

 if (universes == NULL) {
  if ((universes = (unistruct *) calloc(MI_NUM_SCREENS(mi),
      sizeof (unistruct))) == NULL)
   return;
 }
 gp = &universes[MI_SCREEN(mi)];

# ifdef HAVE_COCOA	/* Don't second-guess Quartz's double-buffering */
  dbufp = False;
# endif

 gp->f_hititerations = MI_CYCLES(mi);

 gp->scale = (double) (MI_WIN_WIDTH(mi) + MI_WIN_HEIGHT(mi)) / 8.0;
 gp->midx =  MI_WIN_WIDTH(mi)  / 2;
 gp->midy =  MI_WIN_HEIGHT(mi) / 2;
 startover(mi);
}
示例#5
0
ENTRYPOINT void
draw_galaxy(ModeInfo * mi)
{
  Display    *display = MI_DISPLAY(mi);
  Window      window = MI_WINDOW(mi);
  GC          gc = MI_GC(mi);
  unistruct  *gp = &universes[MI_SCREEN(mi)];
  double      d, eps, cox, six, cor, sir;  /* tmp */
  int         i, j, k; /* more tmp */
  XPoint    *dummy = NULL;

  if (! dbufp)
    XClearWindow(MI_DISPLAY(mi), MI_WINDOW(mi));

  if(spin){
    gp->rot_y += 0.01;
    gp->rot_x += 0.004;
  }

  cox = COSF(gp->rot_y);
  six = SINF(gp->rot_y);
  cor = COSF(gp->rot_x);
  sir = SINF(gp->rot_x);

  eps = 1/(EPSILON * sqrt_EPSILON * DELTAT * DELTAT * QCONS);

  for (i = 0; i < gp->ngalaxies; ++i) {
    Galaxy     *gt = &gp->galaxies[i];

    for (j = 0; j < gp->galaxies[i].nstars; ++j) {
      Star       *st = &gt->stars[j];
      XPoint     *newp = &gt->newpoints[j];
      double      v0 = st->vel[0];
      double      v1 = st->vel[1];
      double      v2 = st->vel[2];

      for (k = 0; k < gp->ngalaxies; ++k) {
        Galaxy     *gtk = &gp->galaxies[k];
        double      d0 = gtk->pos[0] - st->pos[0];
        double      d1 = gtk->pos[1] - st->pos[1];
        double      d2 = gtk->pos[2] - st->pos[2];

        d = d0 * d0 + d1 * d1 + d2 * d2;
        if (d > EPSILON)
          d = gtk->mass / (d * sqrt(d)) * DELTAT * DELTAT * QCONS;
        else
          d = gtk->mass / (eps * sqrt(eps));
        v0 += d0 * d;
        v1 += d1 * d;
        v2 += d2 * d;
      }

      st->vel[0] = v0;
      st->vel[1] = v1;
      st->vel[2] = v2;

      st->pos[0] += v0;
      st->pos[1] += v1;
      st->pos[2] += v2;

      newp->x = (short) (((cox * st->pos[0]) - (six * st->pos[2])) *
                         gp->scale) + gp->midx;
      newp->y = (short) (((cor * st->pos[1]) - (sir * ((six * st->pos[0]) +
                                                       (cox * st->pos[2]))))
                         * gp->scale) + gp->midy;

    }

    for (k = i + 1; k < gp->ngalaxies; ++k) {
      Galaxy     *gtk = &gp->galaxies[k];
      double      d0 = gtk->pos[0] - gt->pos[0];
      double      d1 = gtk->pos[1] - gt->pos[1];
      double      d2 = gtk->pos[2] - gt->pos[2];

      d = d0 * d0 + d1 * d1 + d2 * d2;
      if (d > EPSILON)
        d = 1 / (d * sqrt(d)) * DELTAT * QCONS;
      else
        d = 1 / (EPSILON * sqrt_EPSILON) * DELTAT * QCONS;

      d0 *= d;
      d1 *= d;
      d2 *= d;
      gt->vel[0] += d0 * gtk->mass;
      gt->vel[1] += d1 * gtk->mass;
      gt->vel[2] += d2 * gtk->mass;
      gtk->vel[0] -= d0 * gt->mass;
      gtk->vel[1] -= d1 * gt->mass;
      gtk->vel[2] -= d2 * gt->mass;
    }

    gt->pos[0] += gt->vel[0] * DELTAT;
    gt->pos[1] += gt->vel[1] * DELTAT;
    gt->pos[2] += gt->vel[2] * DELTAT;

#if 1
    // hacked and optimized by katahiromz
    {
        if (dbufp) {
            int count = gt->nstars;
            const XPoint *pt = gt->oldpoints;
            while (count-- > 0) {
                SetPixelV(display,
                    pt->x, pt->y,
                    0);
                ++pt;
            }
        }
        XSetForeground(display, gc, MI_PIXEL(mi, gt->galcol));
        {
            int count = gt->nstars;
            const XPoint *pt = gt->newpoints;
            const unsigned long rgb = gc->foreground_rgb;
            while (count-- > 0) {
                SetPixelV(display,
                    pt->x, pt->y,
                    rgb);
                ++pt;
            }
        }
    }
#else
    if (dbufp) {
      XSetForeground(display, gc, MI_WIN_BLACK_PIXEL(mi));
      XDrawPoints(display, window, gc, gt->oldpoints, gt->nstars,
                  CoordModeOrigin);
    }
    XSetForeground(display, gc, MI_PIXEL(mi, COLORSTEP * gt->galcol));
    XSetForeground(display, gc, MI_PIXEL(mi, gt->galcol));
    XDrawPoints(display, window, gc, gt->newpoints, gt->nstars,
                CoordModeOrigin);
#endif

    dummy = gt->oldpoints;
    gt->oldpoints = gt->newpoints;
    gt->newpoints = dummy;
  }

  gp->step++;
  if (gp->step > gp->f_hititerations * 4)
    startover(mi);
}
示例#6
0
文件: KAQuery.cpp 项目: xwizard/kde1
void 
KAQuery::start()  // get the first "max_hits" results
{
  processed_matches = 0;
  startover();
}
示例#7
0
void
draw_galaxy(ModeInfo * mi)
{
	Display    *display = MI_DISPLAY(mi);
	Drawable    drawable;
	GC          gc = MI_GC(mi);
	double      d;		/* tmp */
	int         i, j, k;	/* more tmp */
	unistruct  *gp;
	Bool        clipped;

	if (universes == NULL)
		return;
	gp = &universes[MI_SCREEN(mi)];
	if (gp->galaxies == NULL)
		return;

	if (gp->fisheye)
		drawable = (Drawable) gp->pixmap;
	else
		drawable = MI_WINDOW(mi);
	MI_IS_DRAWN(mi) = True;
	for (i = 0; i < gp->ngalaxies; ++i) {
		Galaxy     *gt = &gp->galaxies[i];

		for (j = 0; j < gp->galaxies[i].nstars; ++j) {
			Star       *st = &gt->stars[j];
			double      v0 = st->vel[0];
			double      v1 = st->vel[1];
			double      v2 = st->vel[2];

			for (k = 0; k < gp->ngalaxies; ++k) {
				Galaxy     *gtk = &gp->galaxies[k];
				double      d0 = gtk->pos[0] - st->pos[0];
				double      d1 = gtk->pos[1] - st->pos[1];
				double      d2 = gtk->pos[2] - st->pos[2];

				d = d0 * d0 + d1 * d1 + d2 * d2;
				if (d > EPSILON)
					d = gt->mass / (d * sqrt(d)) * DELTAT * DELTAT * QCONS;
				else
					d = gt->mass / (EPSILON * sqrt_EPSILON) * DELTAT * DELTAT * QCONS;
				v0 += d0 * d;
				v1 += d1 * d;
				v2 += d2 * d;
			}

			st->vel[0] = v0;
			st->vel[1] = v1;
			st->vel[2] = v2;

#ifndef NO_VELOCITY_COLORING
			d = (v0 * v0 + v1 * v1 + v2 * v2) / (3.0 * DELTAT * DELTAT);
			if (d > (double) COLORBASE)
				st->color = gt->galcol + COLORBASE - 1;
			else
				st->color = gt->galcol + ((int) d) % COLORBASE;
#endif
			st->pos[0] += v0;
			st->pos[1] += v1;
			st->pos[2] += v2;

			clipped = True;
			if (gp->fisheye) {
/* clip if star Z position < 0.0 - also avoid divide by zero errors */

			if(st->pos[2]>0.0)
			{
			st->px = (int) ((st->pos[0] * gp->scale) / st->pos[2]) + gp->midx;
			st->py = (int) ((st->pos[1] * gp->scale) / st->pos[2]) + gp->midy;
			st->size = (int) (gp->star_scale_Z / st->pos[2]) + st->Z_size;
			if(st->size>12)st->size=12;
			clipped = False;
			}
			} else {

			if (st->px >= gp->clip.left &&
			    st->px <= gp->clip.right - st->size &&
			    st->py >= gp->clip.top &&
			    st->py <= gp->clip.bottom - st->size) {
				XSetForeground(display, gc, MI_BLACK_PIXEL(mi));
				drawStar(st->px, st->py, st->size);
			}
			st->px = (int) (st->pos[0] * gp->scale) + gp->midx;
			st->py = (int) (st->pos[1] * gp->scale) + gp->midy;


#ifdef WRAP /* won't WRAP if FISHEYE_LENS */
			if (st->px < gp->clip.left) {
				(void) printf("wrap l -> r\n");
				st->px = gp->clip.right;
			}
			if (st->px > gp->clip.right) {
				(void) printf("wrap r -> l\n");
				st->px = gp->clip.left;
			}
			if (st->py > gp->clip.bottom) {
				(void) printf("wrap b -> t\n");
				st->py = gp->clip.top;
			}
			if (st->py < gp->clip.top) {
				(void) printf("wrap t -> b\n");
				st->py = gp->clip.bottom;
			}
#endif /*WRAP */


			if (st->px >= gp->clip.left &&
			    st->px <= gp->clip.right - st->size &&
			    st->py >= gp->clip.top &&
				 st->py <= gp->clip.bottom - st->size) {
			clipped = False;
			}
			}
			if (!clipped) {

				if (MI_NPIXELS(mi) >= COLORS) {
#ifdef NO_VELOCITY_COLORING
					XSetForeground(display, gc, MI_PIXEL(mi, gt->galcol));
#else
					XSetForeground(display, gc, MI_PIXEL(mi, st->color));
#endif
				} else 
					XSetForeground(display, gc, MI_WHITE_PIXEL(mi));
				if (gp->tracks) {
					drawStar(st->px + 1, st->py, st->size);
				} else {
					drawStar(st->px, st->py, st->size);
				}
			}
		}

		for (k = i + 1; k < gp->ngalaxies; ++k) {
			Galaxy     *gtk = &gp->galaxies[k];
			double      d0 = gtk->pos[0] - gt->pos[0];
			double      d1 = gtk->pos[1] - gt->pos[1];
			double      d2 = gtk->pos[2] - gt->pos[2];

			d = d0 * d0 + d1 * d1 + d2 * d2;
			if (d > EPSILON)
				d = gt->mass * gt->mass / (d * sqrt(d)) * DELTAT * QCONS;
			else
				d = gt->mass * gt->mass / (EPSILON * sqrt_EPSILON) * DELTAT * QCONS;
			d0 *= d;
			d1 *= d;
			d2 *= d;
			gt->vel[0] += d0 / gt->mass;
			gt->vel[1] += d1 / gt->mass;
			gt->vel[2] += d2 / gt->mass;
			gtk->vel[0] -= d0 / gtk->mass;
			gtk->vel[1] -= d1 / gtk->mass;
			gtk->vel[2] -= d2 / gtk->mass;
		}
		gt->pos[0] += gt->vel[0] * DELTAT;
		gt->pos[1] += gt->vel[1] * DELTAT;
		gt->pos[2] += gt->vel[2] * DELTAT;
	}

	if (gp->fisheye) {
		XCopyArea(display, drawable, MI_WINDOW(mi), gc,
			0, 0, MI_WIDTH(mi), MI_HEIGHT(mi),0 , 0);

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

		XFillRectangle(display, drawable, gc,
			0, 0, MI_WIDTH(mi), MI_HEIGHT(mi));
	}
	gp->step++;
	if (gp->step > gp->f_hititerations * 4)
		(void) startover(mi);
}