Esempio n. 1
0
int writeImageColor(const ImageColor *im, const char *fname) {
  FILE *output; 
  int nRows;
  int nCols;
  int colors;
  int i, j;
  
  /* open the file */
  if (!fname || (output=fopen(fname, "wb"))==0)
    return(-1);

  nRows=getNRowsColor(im);
  nCols=getNColsColor(im);
  colors=getColorsColor(im);

  /* write the header */
  fprintf(output,"P6\n"); /* magic number */
  fprintf(output,"#\n");  /* empty comment */
  fprintf(output,"%d %d\n%03d\n",nCols,nRows,colors); /* image info */

  /* write pixels row by row */
  for(i=0;i<nRows;i++)
    {
      for(j=0;j<nCols;j++)
        {
          int byteR, byteG, byteB;
          byteR=getPixelColor(im,i,j, 1);
          if (fputc(byteR,output)==EOF) /* couldn't write */
            {
              fclose(output);
              return -1;
            }      
          byteG=getPixelColor(im,i,j, 2);
          if (fputc(byteG,output)==EOF) /* couldn't write */
            {
              fclose(output);
              return -1;
            }      
          byteB=getPixelColor(im,i,j, 3);
          if (fputc(byteB,output)==EOF) /* couldn't write */
            {
              fclose(output);
              return -1;
            }      
        }
    }

  /* close the file */
  if (fclose(output)==EOF) return -1;
  return 0; /* OK */
}
void ColorSelectionControl::mouseMoveEvent(QMouseEvent *event)
{
    if (event->buttons() & Qt::LeftButton)
    {
        setColor(getPixelColor(event->pos()));
    }

    QWidget::mouseMoveEvent(event);
}
Esempio n. 3
0
//display the given time (if different from time given with prior call)
void GoldieClock::displayClock(time_t utc)
{
    static time_t utcLast;
    if ( utc != utcLast )
    {
        utcLast = utc;
        time_t local = (*tz).toLocal(utc, &tcr);
        uint8_t h = hour(local);
        uint8_t m = minute(local);
        uint8_t s = second(local);
        uint8_t hourHand = ( h >= 12 ? h - 12 : h ) * 5;
        hourHand = hourHand + m / 12;      //adjust hour hand between hours

        //one rainbow on the quarter hour, two on the half, four on the hour
        if ( s == 0  && _showRainbows )
        {
            if ( m == 15 || m == 45 ) rainbowCycle(2, 1);
            else if ( m == 30 ) rainbowCycle(2, 2);
            else if ( m == 0 ) rainbowCycle(2, 4);
        }

        clear();

        //hour hand (3 pixels wide)
        setPixelColor( LAST_PIXEL - hourHand, HOUR_HAND );
        setPixelColor( LAST_PIXEL - (hourHand + 1U > LAST_PIXEL ? FIRST_PIXEL : hourHand + 1U), HOUR_HAND_DIM );
        setPixelColor( LAST_PIXEL - (hourHand - 1U > LAST_PIXEL ? LAST_PIXEL : hourHand - 1U), HOUR_HAND_DIM );

        //minute hand & second hand -- additive colors
        setPixelColor( LAST_PIXEL - m, getPixelColor(LAST_PIXEL - m) + MINUTE_HAND );
        setPixelColor( LAST_PIXEL - s, getPixelColor(LAST_PIXEL - s) + SECOND_HAND );

        //hour markers (do not overlay hands)
        for (uint16_t i = 0; i <= LAST_PIXEL; i += 5)
            if ( getPixelColor(LAST_PIXEL - i) == 0 ) setPixelColor(LAST_PIXEL - i, HOUR_MARKER);

        show();
    }
}
void floodFill(GLint x, GLint y, Color oldColor, Color newColor) {
	Color color;
	color = getPixelColor(x, y);

	if(color.r == oldColor.r && color.g == oldColor.g && color.b == oldColor.b)
	{
		setPixelColor(x, y, newColor);
		floodFill(x+1, y, oldColor, newColor);
		floodFill(x, y+1, oldColor, newColor);
		floodFill(x-1, y, oldColor, newColor);
		floodFill(x, y-1, oldColor, newColor);
	}
	return;
}
MazeLoader::MazeLoader(const char *imagePath)
{
    SDL_Surface *surface = IMG_Load(imagePath);
    if (!surface)
        throw std::runtime_error(std::string("Cannot open image") + imagePath);

    m_maze.reset(new Maze(surface->w, surface->h, MAZE_WALL_HEIGHT));
    Maze &maze = *m_maze;

    for (int x = 0; x < surface->w; ++x) {
        for (int y = 0; y < surface->h; ++y) {
            vec3 color = getPixelColor(surface, x, y);
            if (color.x <= 0.01 && color.y <= 0.01 && color.z <= 0.01) {
                maze.setBlack(x, y);
            } else if (color.x >= 0.9f && color.y <= 0.1f && color.z <= 0.1f) {
                maze.setStartPosition(x, y);
            }
        }
        fflush(stdout);
    }

    maze.createWalls();
}
Esempio n. 6
0
void Balls::moon2() {
	if (counter == 0) {
		if (dir) {
			dir = false;
		} else {
			dir = true;
		}
		posmoon = posmoon1;
	}

	if (counter > targetCycles) {
		drawColorEqual();
	} else {
		if (dir) {
			for (int i = 0; i < numLedsProBar; i++) {
				pliste[i].active = false;
			}
			posmoon1 = linearApp(posmoon, numLedsProBar - 4, targetCycles,
					counter);
			pixel colorpix;
			//cout << (int) colorpix.r << " " << (int) colorpix.g << " " << (int) colorpix.b << " "<< " " <<(int) posmoon1 + 3 << endl;
			getPixelColor(1, (int) posmoon1 + 3, &colorpix);

			for (int i = posmoon1 + 1; i <= posmoon1 + 3; i++) {
				pliste[i].active = true;
				pliste[i].color = color;
				pliste[i].r = quadApp(dim[0] * colors[color].a, colorpix.r, 3,
						i - (posmoon1));
				pliste[i].g = quadApp(dim[0] * colors[color].b, colorpix.g, 3,
						i - (posmoon1));
				pliste[i].b = quadApp(dim[0] * colors[color].c, colorpix.b, 3,
						i - (posmoon1));
			}
			getPixelColor(1, (int) posmoon1 - 2, &colorpix);
			for (int i = posmoon1 - 2; i <= posmoon1; i++) {
				pliste[i].active = true;
				pliste[i].color = color;
				pliste[i].r = quadApp(colorpix.r, dim[0] * colors[color].a, 3,
						i - (posmoon1 - 2));
				pliste[i].g = quadApp(colorpix.g, dim[0] * colors[color].b, 3,
						i - (posmoon1 - 2));
				pliste[i].b = quadApp(colorpix.b, dim[0] * colors[color].c, 3,
						i - (posmoon1 - 2));
			}
		} else {
			for (int i = 0; i < numLedsProBar; i++) {
				pliste[i].active = false;
			}
			posmoon1 = linearApp(posmoon, 2, targetCycles, counter);
			pixel colorpix;
			//cout << (int) colorpix.r << " " << (int) colorpix.g << " " << (int) colorpix.b << " " <<(int) posmoon1 + 3 << endl;
			getPixelColor(1, (int) posmoon1 + 3, &colorpix);

			for (int i = posmoon1 + 1; i <= posmoon1 + 3; i++) {
				pliste[i].active = true;
				pliste[i].color = color;
				pliste[i].r = quadApp(dim[0] * colors[color].a, colorpix.r, 3,
						i - (posmoon1));
				pliste[i].g = quadApp(dim[0] * colors[color].b, colorpix.g, 3,
						i - (posmoon1));
				pliste[i].b = quadApp(dim[0] * colors[color].c, colorpix.b, 3,
						i - (posmoon1));
			}
			getPixelColor(1, (int) posmoon1 - 2, &colorpix);
			for (int i = posmoon1 - 2; i <= posmoon1; i++) {
				pliste[i].active = true;
				pliste[i].color = color;
				pliste[i].r = quadApp(colorpix.r, dim[0] * colors[color].a, 3,
						i - (posmoon1 - 2));
				pliste[i].g = quadApp(colorpix.g, dim[0] * colors[color].b, 3,
						i - (posmoon1 - 2));
				pliste[i].b = quadApp(colorpix.b, dim[0] * colors[color].c, 3,
						i - (posmoon1 - 2));
			}
		}
		drawColorEqual();
	}
}
Esempio n. 7
0
int main (void) {
  point a; a.x= 2; a.y= 2; a.z = 4;
  point b; b.x= 4; b.y= 2; b.z = 2;
  point c; c.x= 3; c.y= 4; c.z = 4;

  point d; d.x= 0.5; d.y= 3; d.z = 0.1;
  point e; e.x= 0; e.y= 4; e.z = 0.1;
  point f; f.x= 0.5; f.y= 3; f.z = 1;
  
	point g; g.x= 0; g.y= 6; g.z = 6;
  point h; h.x= 4; h.y= 2; h.z = 5;
  point i; i.x= 1; i.y= 6; i.z = 0;
  point j; j.x= 5; j.y= 4; j.z = 3;
  point k; k.x= 2; k.y=-5; k.z = 5;
  point l; l.x= 4; l.y= 3; l.z = 1;



  point x; x.x= 0; x.y= 0; x.z = 0;
  point y; y.x= 6; y.y= 0; y.z = 0;
  point z; z.x= 0; z.y= 6; z.z = 0;

  facet m = createFacet(x, y, z);
  facet n = createFacet(d, e, f);
  facet o = createFacet(y, z, g);
  facet q = createFacet(a, e, i);
  facet s = createFacet(c, e, g);
  facet t = createFacet(f, h, j);


	m.name = "m";
	n.name = "n"; // green
	o.name = "o"; // red
	q.name = "q";
	s.name = "s";
	t.name = "t";

	n.cp.r = 0;
	n.cp.g = 255;
	n.cp.b = 0;
	
	o.cp.r = 255;
	o.cp.g = 0;
	o.cp.b = 0;

	o.k = 1;

	m.cp.r = 0;
	m.cp.g = 0;
	m.cp.b = 255;
	m.k = 0;
	n.k = 0;

	


	printf ("Ordering the facets...\n");
	flist facets;
	printf (" -> Check-up 1... \n");
	facets.f = &m;

	

	printf (" -> Check-up 2... \n");
	flist facet2;
	facet2.f = &n;
	facets.next = &facet2;
	facet2.next = NULL;

	flist facet3;
	facet3.f = &o;
	facet2.next = &facet3;
	
	facet3.next = NULL;

	/*

	flist facet4;
	facet4.f = &q;
	facet3.next = &facet4;

	flist facet5;
	facet5.f = &s;
	facet4.next = &facet5;

	flist facet6;
	facet6.f = &t;
	facet5.next = &facet6;

	facet6.next = NULL;
*/



	settings set;
	set.size_x = 7;
	set.size_y = 7;
	set.size_z = 7;
	set.depth = 1;
	set.height_scn = 1;
	set.width_scn = 1;
	set.height_px = 200;
	set.width_px = 200;

	set.top_lefthand.x = 0;
	set.top_lefthand.y = 0;
	set.top_lefthand.z = 1;

	set.screenA.x = 0.5;
	set.screenA.y = 0.0;
	set.screenA.z = 0.5;

	set.screenB.x = 1.0;
	set.screenB.y = 0.0;
	set.screenB.z = 0.5;
	
	set.i.x = 1.0;
	set.i.y = 0.0;
	set.i.z = 0.0;

	set.j.x = 0.0;
	set.j.y = 0.0;
	set.j.z = -1.0;

	color back; back.r = 50; back.g = 70; back.b = 150;
	set.back = back;

	source so;
	so.p.x = 0.5; so.p.y = 0.5 ; so.p.z = 0.5;
	so.cp.r = 255; so.cp.g = 255; so.cp.b = 255;
	set.s = so;

	set.obs.x = 0.5 ; set.obs.y = -0.5 ; set.obs.z = 0.5;
	set.facets = &facets;

	printf ("Initializing the scene...\n");
	box space = initialize (set);
	

	SDL_Init (SDL_INIT_VIDEO);

	SDL_Surface* sdl_screen = SDL_SetVideoMode (200, 200, 32, SDL_HWSURFACE);
	SDL_FillRect (sdl_screen, NULL, SDL_MapRGB(sdl_screen->format, 0, 0, 0));

	for (int i = 1; i < 200; i++) {
		for (int j = 1; j < 200; j++) {


		//	printf ("i = %d ; j = %d\n================\n\n", i, j);
			color whatup = getPixelColor (i, j, set, space);

	
	
	
	






			SDL_Surface* rectangle = SDL_CreateRGBSurface(SDL_HWSURFACE, 1, 1, 32, 0, 0, 0, 0);

			SDL_FillRect(rectangle, NULL, SDL_MapRGB(sdl_screen->format,whatup.r, 	whatup.g, whatup.b));

			SDL_Rect position;
			position.x = i;
			position.y = j;
			SDL_BlitSurface(rectangle, NULL, sdl_screen, &position);





			SDL_Flip(sdl_screen);
		}
	}

			sleep(20);

	SDL_Quit ();


//			printf ("Color of the ambiance : %d %d %d\n", whatup.r, whatup.g, whatup.b);




/*







// TEST WITH FILES

	entry scene = *read("scenes/cubes.scn");
	flist* n_facets = scene.Facets;
	set.depth = 1;
	set.width = scene.width;
	set.height = scene.height;

	// size_x, size_y, size_z
	double size_x = 0.0;
	double size_y = 0.0;
	double size_z = 0.0;

	flist* tmp = n_facets->f;
	while (tmp != NULL) {
		if (tmp->f.a.x > size_x)
			size_x = tmp->f.a.x;
		if (tmp->f.b.x > size_x)
			size_x = tmp->f.b.x;
		if (tmp->f.c.x > size_x)
			size_x = tmp->f.c.x;

		if (tmp->f.a.y > size_y)
			size_y = tmp->f.a.y;
		if (tmp->f.b.y > size_y)
			size_y = tmp->f.b.y;
		if (tmp->f.c.y > size_y)
			size_y = tmp->f.c.y;

		if (tmp->f.a.z > size_z)
			size_z = tmp->f.a.z;
		if (tmp->f.b.z > size_z)
			size_z = tmp->f.b.z;
		if (tmp->f.c.z > size_z)
			size_z = tmp->f.c.z;

		tmp = tmp->next;
	}

	set.size_x = size_x; set.size_y = size_y ; set.size_z = size_z;
	
	set.back.r = 50;
	set.back.r = 75;
	set.back.r = 100;

	printf ("Initializing the scene...\n");
	box space = initialize (size_x, size_y, size_z,1, &facets);



	screen n_screen = defScreen(&scene);








*/
	return 0;
}