Beispiel #1
0
/**
 * Draws a single star at x and y, using the LUM_N colors from offset c.
 * The color offset must be the first of the set.
 *
 * Uses _putpixel(), so use with care. Don't call with invalid x/y values.
 */
void draw_star(BITMAP *buffer, int x, int y, int c) {
    int a, b;
    int center = LUM_N - 1;

    // Center dot.
    _putpixel(buffer, center + x, center + y, palette_color[c]);

    // All other shades.
    for (a = 1; a < LUM_N; ++a) {
        _putpixel(buffer, center + x, center - a + y, palette_color[c + a]);
        _putpixel(buffer, center + x, center + a + y, palette_color[c + a]);
        _putpixel(buffer, center - a + x, center + y, palette_color[c + a]);
        _putpixel(buffer, center + a + x, center + y, palette_color[c + a]);
    }
}
Beispiel #2
0
int main (int argc, char **argv)
{
  int gd, gm;
  int col;
  unsigned int seed;
  long int counter;
  float j, k, x, y, xx, xp, yp, r, xoffs, yoffs;
  
  if (argc == 2)
    seed = atoi (argv [1]); /* no checks! */
  else {  
    printf ("Seed: ");
    j = scanf ("%d", &seed);
  }
  srand (seed);
  // random each time:
  // srand (time(NULL));
  
  gd = X11;
  gm = getmaxmode ();
  initgraph(&gd, &gm, "");
  
  setbkcolor (BLACK);
  cleardevice ();
  setcolor (YELLOW);
  outtextxy (0, 0, "Press a key or click to exit: ");
  
  xoffs = getmaxx () / 2;
  yoffs = getmaxy () / 3;
  j = random (100);
  k = random (100);
  x = y = xx = xp = yp = r = 0.0;
  col = 1; /* colours codes run from 0 (black) to 15 (white) */
  counter = 0;
  setcolor (col);

  while (!kbhit () && !mouseclick ()) {
    xx = y - sgn (x) * sqrt (abs (k * x - 1));
    y = j - x;
    x = xx;
    xp = x * 2 + xoffs;
    yp = y * 2 + yoffs;
    _putpixel (xp, yp);
    if (++counter == 20000) {
      counter = 0;
      col++;
      if (col == 16)
	col = 1;
    }
    setcolor (col);
  }
   
  closegraph ();
  return 0;
}
void Bitmap::PutPixel(int x, int y, color_t color)
{
    if (x < 0 || x >= _alBitmap->w || y < 0 || y >= _alBitmap->h)
    {
        return;
    }

	switch (bitmap_color_depth(_alBitmap))
	{
	case 8:
		return _putpixel(_alBitmap, x, y, color);
	case 15:
		return _putpixel15(_alBitmap, x, y, color);
	case 16:
		return _putpixel16(_alBitmap, x, y, color);
	case 24:
		return _putpixel24(_alBitmap, x, y, color);
	case 32:
		return _putpixel32(_alBitmap, x, y, color);
	}
    assert(0); // this should not normally happen
	return putpixel(_alBitmap, x, y, color);
}
Beispiel #4
0
void _line( int p_xStart, int p_yStart, int p_xEnd, int p_yEnd/*, int p_color*/ ) {
	/** Draw line using Bresenham's line algorithm.
	 *  author Zingl Alois
	 *  code from http://members.chello.at/~easyfilter/bresenham.html */
	int dx = abs( p_xEnd - p_xStart ), sx = p_xStart < p_xEnd ? 1 : -1;
	int dy = -abs( p_yEnd - p_yStart ), sy = p_yStart < p_yEnd ? 1 : -1;
	int err = dx + dy, e2; /* error value e_xy */

	for ( ;; ) {
		_putpixel( p_xStart, p_yStart/*, p_color*/ );
		if ( p_xStart == p_xEnd && p_yStart == p_yEnd ) {
			break;
		}

		e2 = 2 * err;
		if ( e2 >= dy ) { /* e_xy + e_x > 0 */
			err += dy; p_xStart += sx;
		}

		if ( e2 <= dx ) { /* e_xy + e_y < 0 */
			err += dx; p_yStart += sy;
		}
	}
}