Esempio n. 1
0
void
draw_tik_tak(ModeInfo * mi)
{
	Display    *display = MI_DISPLAY(mi);
	int         i;
	tik_takstruct *tiktak;

	if (tik_taks == NULL)
		return;
	tiktak = &tik_taks[MI_SCREEN(mi)];
	if (tiktak->object == NULL)
		return;

	if (tiktak->no_colors) {
		free_tik_tak(display, tiktak);
		init_tik_tak(mi);
		return;
	}
	tiktak->painted = True;
	MI_IS_DRAWN(mi) = True;
	XSetFunction(display, tiktak->gc, GXxor);

/* Rotate colours */
	if (tiktak->cycle_p) {
		rotate_colors(display, tiktak->cmap, tiktak->colors, tiktak->ncolors,
			      tiktak->direction);
		if (!(LRAND() % 1000))
			tiktak->direction = -tiktak->direction;
	}
	for (i = 0; i < tiktak->num_object; i++) {
		tik_takobject *object0;

		object0 = &tiktak->object[i];
		if (MI_IS_INSTALL(mi) && MI_NPIXELS(mi) > 2) {
			XSetForeground(display, tiktak->gc, tiktak->colors[object0->colour].pixel);
		} else {
			XSetForeground(display, tiktak->gc, object0->colour);
		}
		object0->velocity_a += ((float) NRAND(1001) - 500.0) / 200000.0;
		object0->angle += object0->velocity_a;
		object0->velocity_a1 += ((float) NRAND(1001) - 500.0) / 200000.0;
		object0->angle1 += object0->velocity_a1;
		tik_tak_setupobject( mi , object0);
		tik_tak_drawobject(mi, object0 );
	}
	XSetFunction(display, tiktak->gc, GXcopy);
}
Esempio n. 2
0
void
draw_toneclock(ModeInfo * mi)
{
	Display    *display = MI_DISPLAY(mi);
	Window      window = MI_WINDOW(mi);
	int         i;
	toneclockstruct *tclock;

	if (toneclocks == NULL)
		return;
	tclock = &toneclocks[MI_SCREEN(mi)];
	if (tclock->hour == NULL)
		return;

	if (tclock->no_colors) {
		free_toneclock(display, tclock);
		init_toneclock(mi);
		return;
	}
	XSetFunction(display, tclock->gc, GXxor);
#ifndef NO_DBUF
        XSetForeground(display,tclock->dbuf_gc,MI_BLACK_PIXEL(mi));
	XFillRectangle(display, (Drawable) tclock->dbuf, tclock->dbuf_gc,
		0, 0, tclock->win_width, tclock->win_height);
#endif
	tclock->painted = True;
	MI_IS_DRAWN(mi) = True;
/* Rotate colours */
	if (tclock->cycle_p) {
		rotate_colors(display, tclock->cmap, tclock->colors, tclock->ncolors,
			      tclock->direction);
		if (!(LRAND() % 1000))
			tclock->direction = -tclock->direction;
	}
	for (i = 0; i < tclock->num_hour; i++) {
		toneclockhour *hour0;
	   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 ) );
		hour0 = &tclock->hour[i];
		if (MI_IS_INSTALL(mi) && MI_NPIXELS(mi) > 2) {
			XSetForeground(display, tclock->gc, tclock->colors[hour0->colour].pixel);
		} else {
			XSetForeground(display, tclock->gc, hour0->colour);
		}
		toneclock_drawhour(mi, hour0 , x0 , y0);
		hour0->velocity += ((float) NRAND(1001) - 500.0) / 200000.0;
		hour0->angle += hour0->velocity;
	}
   tclock->velocity += ((float) NRAND(1001) - 500.0) / 200000.0;
   tclock->angle += tclock->velocity;
	       if ( tclock->pulsating )
	       tclock->phase += tclock->ph_vel;
   if ( tclock->moving )
     {
	tclock->anglex += tclock->vx;
	tclock->angley += tclock->vy;
     }
#ifdef NO_DBUF
	for (i = 0; i < tclock->num_hour; i++) {
		toneclockhour *hour0;
	   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 ) );
		hour0 = &tclock->hour[i];
		if (MI_IS_INSTALL(mi) && MI_NPIXELS(mi) > 2) {
			XSetForeground(display, tclock->gc, tclock->colors[hour0->colour].pixel);
		} else {
			XSetForeground(display, tclock->gc, hour0->colour);
		}
		toneclock_drawhour(mi, hour0 , x0 , y0);
	}
#else
     XFlush(display);
     XCopyArea (display, (Drawable) tclock->dbuf, window, tclock->dbuf_gc, 0, 0,
		     tclock->win_width, tclock->win_height, 0, 0);
     XFlush(display);
     XSetForeground(display,tclock->dbuf_gc,MI_BLACK_PIXEL(mi));
     XFillRectangle(display, (Drawable) tclock->dbuf, tclock->dbuf_gc,
		0, 0, tclock->win_width, tclock->win_height);
#endif
	XSetFunction(display, tclock->gc, GXcopy);
}
Esempio n. 3
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. 4
0
enum piglit_result
piglit_display(void)
{
    GLboolean pass = GL_TRUE;
    float array[] = {
        10, 10,	   1, 0, 0,
        27, 10,	   1, 0, 0,
        10, 30,	   1, 0, 0,

        30, 10,	   0, 1, 0,
        47, 10,	   0, 1, 0,
        30, 30,	   0, 1, 0,

        50, 10,	   0, 0, 1,
        67, 10,	   0, 0, 1,
        50, 30,	   0, 0, 1,

        70, 10,	   1, 0, 1,
        87, 10,	   1, 0, 1,
        70, 30,	   1, 0, 1
    };
    float seccol[] = {
        0.2, 0.2, 0.2,
        0.2, 0.2, 0.2,
        0.2, 0.2, 0.2,

        0.2, 0.2, 0.2,
        0.2, 0.2, 0.2,
        0.2, 0.2, 0.2,

        0.2, 0.2, 0.2,
        0.2, 0.2, 0.2,
        0.2, 0.2, 0.2,

        0.2, 0.2, 0.2,
        0.2, 0.2, 0.2,
        0.2, 0.2, 0.2,
    };
    float c0[] = {1, 0.2, 0.2};
    float c1[] = {0.2, 1, 0.2};
    float c2[] = {0.2, 0.2, 1};
    float c3[] = {1, 0.2, 1};
    short indices[] = {
        0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11
    };
    int i, j;

    piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);

    printf("From bottom to top:\n");

    glEnable(GL_COLOR_SUM);
    glLoadIdentity();

    /* State change: Vertex arrays. */
    glVertexPointer(2, GL_FLOAT, 20, array);
    glColorPointer(3, GL_FLOAT, 20, array + 2);
    glSecondaryColorPointer(3, GL_FLOAT, 0, seccol);
    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_COLOR_ARRAY);
    glEnableClientState(GL_SECONDARY_COLOR_ARRAY);

    /* The vertex array state should be preserved after glClear. */
    glClear(GL_COLOR_BUFFER_BIT);

    /* Draw. */
    printf("DrawElements\n");
    for (i = 0; i < 4; i++)
        glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_SHORT, indices + i*3);

    /* State change: Constant buffer. */
    glTranslatef(0, 30, 0);

    rotate_colors(array);

    /* Draw. */
    printf("DrawArrays\n");
    for (i = 0; i < 4; i++)
        glDrawArrays(GL_TRIANGLES, i*3, 3);

    /* State change: Vertex arrays. */
    glDisableClientState(GL_VERTEX_ARRAY);
    glDisableClientState(GL_COLOR_ARRAY);
    glDisableClientState(GL_SECONDARY_COLOR_ARRAY);

    /* State change: Constant buffer. */
    glTranslatef(0, 30, 0);

    rotate_colors(array);

    /* Draw. */
    printf("Begin/End\n");
    for (i = 0; i < 4; i++) {
        glBegin(GL_TRIANGLES);
        for (j = 0; j < 3; j++) {
            glColor3fv(array + i*15 + j*5 + 2);
            glSecondaryColor3fv(seccol);
            glVertex2fv(array + i*15 + j*5);
        }
        glEnd();
    }

    /* State change: Constant buffer. */
    glTranslatef(0, 30, 0);

    rotate_colors(array);

    /* Create display lists. */
    for (i = 0; i < 4; i++) {
        glNewList(i+1, GL_COMPILE);
        glBegin(GL_TRIANGLES);
        for (j = 0; j < 3; j++) {
            glColor3fv(array + i*15 + j*5 + 2);
            glSecondaryColor3fv(seccol);
            glVertex2fv(array + i*15 + j*5);
        }
        glEnd();
        glEndList();
    }

    /* Draw. */
    printf("CallList\n");
    for (i = 0; i < 4; i++) {
        glCallList(i+1);
    }

    pass = pass && piglit_probe_pixel_rgb(15, 15, c0);
    pass = pass && piglit_probe_pixel_rgb(35, 15, c1);
    pass = pass && piglit_probe_pixel_rgb(55, 15, c2);
    pass = pass && piglit_probe_pixel_rgb(75, 15, c3);

    pass = pass && piglit_probe_pixel_rgb(15, 45, c1);
    pass = pass && piglit_probe_pixel_rgb(35, 45, c2);
    pass = pass && piglit_probe_pixel_rgb(55, 45, c3);
    pass = pass && piglit_probe_pixel_rgb(75, 45, c0);

    pass = pass && piglit_probe_pixel_rgb(15, 75, c2);
    pass = pass && piglit_probe_pixel_rgb(35, 75, c3);
    pass = pass && piglit_probe_pixel_rgb(55, 75, c0);
    pass = pass && piglit_probe_pixel_rgb(75, 75, c1);

    pass = pass && piglit_probe_pixel_rgb(15, 105, c3);
    pass = pass && piglit_probe_pixel_rgb(35, 105, c0);
    pass = pass && piglit_probe_pixel_rgb(55, 105, c1);
    pass = pass && piglit_probe_pixel_rgb(75, 105, c2);

    glutSwapBuffers();
    return pass ? PIGLIT_PASS : PIGLIT_FAIL;
}
Esempio n. 5
0
/*-
 * draw_swirl
 *
 * Draw one iteration of swirling
 *
 * -      win is the window to draw in
 */
void
draw_swirl(ModeInfo * mi)
{
	swirlstruct *sp;

	if (swirls == NULL)
		return;
	sp = &(swirls[MI_SCREEN(mi)]);
	if (sp->knots == NULL)
		return;

	MI_IS_DRAWN(mi) = True;

	/* are we going? */
	if (sp->started) {
		/* in the middle of drawing? */
		if (sp->drawing) {
		  if(sp->cycle_p) {
		 rotate_colors(MI_DISPLAY(mi), sp->cmap, sp->colors, sp->ncolors, sp->direction);
		    if (!(LRAND() % 1000))
      sp->direction = -sp->direction;
                 }
			/* draw a batch of points */
			sp->batch_todo = BATCH_DRAW;
			while ((sp->batch_todo > 0) && sp->drawing) {
				/* draw a point */
				draw_point(mi, sp);

				/* move to the next point */
				next_point(sp);

				/* done a point */
				sp->batch_todo--;
			}
		} else {
		  if(sp->cycle_p) {
		 rotate_colors(MI_DISPLAY(mi), sp->cmap, sp->colors, sp->ncolors, sp->direction);
		    if (!(LRAND() % 1000))
      sp->direction = -sp->direction;
                 }

			/* time for a higher resolution? */
			if (sp->resolution > sp->max_resolution) {
				/* move to higher resolution */
				sp->resolution--;

				/* calculate the pixel step for this resulution */
				sp->r = (1 << (sp->resolution - 1));

				/* start drawing again */
				sp->drawing = True;

				/* start in the middle of the screen */
				sp->x = (sp->width - sp->r) / 2;
				sp->y = (sp->height - sp->r) / 2;

				/* initialise spiral drawing parameters */
				sp->dir = DRAW_RIGHT;
				sp->dir_todo = 1;
				sp->dir_done = 0;
			} else {
				/* all done, decide when to restart */
				if (sp->start_again == -1) {
					/* start the counter */
					sp->start_again = RESTART;
				} else if (sp->start_again == 0) {
					/* reset the counter */
					sp->start_again = -1;

					/* start again */
					init_swirl(mi);
				} else
					/* decrement the counter */
					sp->start_again--;
			}
		}
	}
}