Beispiel #1
0
struct color input_ambient(int argc, char *in[]){
   int i = 0;
   while(strcmp(in[i],"-ambient")!= 0){
      if(i>=argc-1)
         return create_color(1,1,1);
      i++;
   }
   double x = 1;
   double y = 1;
   double z = 1;
   
   if(i+1<argc && !equalToFlag(argc,in,i+1))
      x = convert_double(in[i+1],1);
    else
         return create_color(x,y,z);

   if(i+2<argc&& !equalToFlag(argc,in,i+2))
      y = convert_double(in[i+2],1);
    else
         return create_color(x,y,z);

   if(i+3<argc&& !equalToFlag(argc,in,i+3))
      z = convert_double(in[i+3],1);
    else
         return create_color(x,y,z);

   return create_color(x,y,z); 
}
Beispiel #2
0
void test_set_color()
{
    Color expected_color = create_color(255, 255, 255);
    Color color = create_color(0, 1, 2);
    clear_color(&color);
    set_color(&color, &expected_color);
    
    assert(color.r == expected_color.r);
    assert(color.g == expected_color.g);
    assert(color.b == expected_color.b);

    printf("Set Color Passed\n");
}
Beispiel #3
0
/*
 * React to changes
 */
static errr Term_xtra_gcu_react(void)
{

#ifdef A_COLOR
	if (COLORS == 256 || COLORS == 88) {
		/* If we have more than 16 colors, find the best matches. These numbers
		 * correspond to xterm/rxvt's builtin color numbers--they do not
		 * correspond to curses' constants OR with curses' color pairs.
		 *
		 * XTerm has 216 (6*6*6) RGB colors, with each RGB setting 0-5.
		 * RXVT has 64 (4*4*4) RGB colors, with each RGB setting 0-3.
		 *
		 * Both also have the basic 16 ANSI colors, plus some extra grayscale
		 * colors which we do not use.
		 */
		int i;
		int scale = COLORS == 256 ? 6 : 4;

		for (i = 0; i < BASIC_COLORS; i++) {
			int fg = create_color(i, scale);
			init_pair(i + 1, fg, bg_color);
			if (bold_extended)
				colortable[i] = COLOR_PAIR(i + 1) | A_BRIGHT;
			else
				colortable[i] = COLOR_PAIR(i + 1);
		}
	}
#endif

	return 0;
}
Beispiel #4
0
/*
** brief : for a cone determine its luminosity
** @scene : our scene
** @cone : our cone
** @point : our vector point P
** return : the color
*/
t_color		*lumi_cone(t_scene *scene, t_cone *cone, t_vector *point)
{
  t_color	*color;
  int		nb_l;
  t_light	*light;

  nb_l = 0;
  light = scene->list_light;
  if (light == NULL)
    return (cone->color);
  color = create_color(0, 0, 0);
  while (light != NULL)
    {
      ++nb_l;
      to_simple(&(light)->coord, cone->coord, cone->rot);
      if (scene->ambiance)
	_normal_cone_amb(light, point, cone, &color);
      else
	_normal_cone(light, point, cone, &color);
      to_real_life(&(light)->coord, cone->coord, cone->rot);
      light = light->next;
    }
  div_color(&color, nb_l);
  return (color);
}
Beispiel #5
0
void input_spheres(char **argv, struct sphere s[], int c[]){

   c[0] = 0;
   FILE *fp;
   fp= fopen(argv[1],"r");
  
   if (fp == NULL) {
       perror("usage: a.out <filename> [-eye x y z] [-view min_x max_x min_y max_y width height] [-light x y z r g b] [-ambient r g b]\n");
   }

   double x, y,z, radius,r,g, b,a,d, sp, ro;
   int index = 0;   

   while (fscanf(fp, "%lf %lf%lf %lf%lf %lf%lf %lf%lf %lf%lf ", 
                       &x, &y, &z,&radius, &r, &g,&b, &a, &d,&sp, &ro) != EOF &&
                 index<10000) {
      struct sphere sphere =  create_sphere(create_point(x,y,z),
                                            radius,
                                            create_color(r,g,b),
                                            create_finish(a,d,sp,ro));
      s[index] = sphere;
      index++;
   }
   c[0] = index;
   fclose(fp);

}
Beispiel #6
0
void test_cast_ray(void){
   struct sphere s[2];
   struct color c1 = create_color(1,0,.3);
   s[0] = create_sphere(create_point(1.4,2.6,0), 2, c1);
   s[1] = create_sphere(create_point(4.5, 5, 0), 1,c1);

   struct ray r = create_ray(create_point(0,0,0), 
                             create_vector(1.4,2.6,0));

   struct ray r2 = create_ray(create_point(-123.2,-4,-.3),
                             create_vector(1.3,-2.9,-.3));

   struct ray r3 = create_ray(create_point(-4.5,-4.3,0),
                             create_vector(-23,-100,-100));

   checkit_int(cast_ray(r,s,2).r, 1);
   checkit_int(cast_ray(r,s,2).g, 0);
   checkit_int(cast_ray(r,s,2).b, .3);

   checkit_int(cast_ray(r2,s,2).r, 1);
   checkit_int(cast_ray(r2,s,2).g, 1);
   checkit_int(cast_ray(r2,s,2).b, 1);

   checkit_int(cast_ray(r3,s,2).r, 1);
   checkit_int(cast_ray(r3,s,2).g, 1);
   checkit_int(cast_ray(r3,s,2).b, 1);

}
Beispiel #7
0
/*
 * React to changes
 */
static errr Term_xtra_gcu_react(void)
{

#ifdef A_COLOR
    if (COLORS == 256 || COLORS == 88)
    {
        /* CTK: I snagged this color handling from current Vanilla */
        /* If we have more than 16 colors, find the best matches. These numbers
        * correspond to xterm/rxvt's builtin color numbers--they do not
        * correspond to curses' constants OR with curses' color pairs.
        *
        * XTerm has 216 (6*6*6) RGB colors, with each RGB setting 0-5.
        * RXVT has 64 (4*4*4) RGB colors, with each RGB setting 0-3.
        *
        * Both also have the basic 16 ANSI colors, plus some extra grayscale
        * colors which we do not use.
        */
        int i;
        int scale = COLORS == 256 ? 6 : 4;
        for (i = 0; i < 16; i++)
        {
            int fg = create_color(i, scale);
            init_pair(i + 1, fg, bg_color);
            colortable[i] = COLOR_PAIR(i + 1) | A_NORMAL;
        }
    }

#endif

	/* Success */
	return (0);
}
Beispiel #8
0
BComboBox::ChoiceListView::ChoiceListView(BRect frame, BComboBox *parent)
	: BView(frame, "_choice_list_view_", B_FOLLOW_ALL_SIDES, B_WILL_DRAW
			| B_NAVIGABLE),
	fClickLoc(-100, -100)
{
	fParent = parent;
	GetFontHeight(&fFontHeight);
	menu_info mi;
	get_menu_info(&mi);
	fForeCol = create_color(0, 0, 0);
	fBackCol = mi.background_color;
	fSelCol  = create_color(144, 144, 144);
	SetViewColor(B_TRANSPARENT_COLOR);
	SetHighColor(fForeCol);
	fTrackingMouseDown = false;
	fClickTime = 0;
}
Beispiel #9
0
unsigned int	hsv_to_rgb(double h, double s, double v)
{
	double	f;
	double	l;
	double	m;
	double	n;

	f = floor(h / 60);
	f = (h / 60) - f;
	l = (v * (1 - s)) * 255;
	m = (v * (1 - f * s)) * 255;
	n = (v * (1 - (1 - f) * s)) * 255;
	v *= 255;
	if (floor(h / 60) == 0)
		return (create_color((int)v, (int)n, (int)l));
	else if (floor(h / 60) == 1)
		return (create_color((int)m, (int)v, (int)l));
	else if (floor(h / 60) == 2)
		return (create_color((int)l, (int)v, (int)n));
	else if (floor(h / 60) == 3)
		return (create_color((int)l, (int)m, (int)v));
	else if (floor(h / 60) == 4)
		return (create_color((int)n, (int)l, (int)v));
	else if (floor(h / 60) == 5)
		return (create_color((int)v, (int)l, (int)m));
	else
		return (create_color(0, 0, 0));
}
Beispiel #10
0
/*
** brief : calculate color for the cone
** @angle : angle from luminosity
** @cone : our struct cone
** @light : our struct light
*/
static t_color	*_calc(double angle, t_cone *cone, t_light *l)
{
  return (create_color((cone->color->r * angle * (1.0 - cone->brill) +
			l->color->r * cone->brill * angle) * l->puiss / 100,
		       (cone->color->g * angle * (1.0 - cone->brill) +
			l->color->g * cone->brill * angle) * l->puiss / 100,
		       (cone->color->b * angle * (1.0 - cone->brill) +
			l->color->b * cone->brill * angle) * l->puiss / 100));
}
Beispiel #11
0
unsigned int	linear_interpolation(t_env *env, int i)
{
	int		rgb_result[3];
	double	t;

	t = i / (double)env->iter_max;
	rgb_result[0] = (1 - t) * R_C2 + t * R_C1;
	rgb_result[1] = (1 - t) * G_C2 + t * G_C1;
	rgb_result[2] = (1 - t) * B_C2 + t * B_C1;
	return (create_color(rgb_result[0], rgb_result[1], rgb_result[2]));
}
Beispiel #12
0
void test_cast_all_rays(void){
   struct color	c = create_color(.3,.5,.9);

   struct sphere s[2];
   s[0] = create_sphere(create_point(1,1,0), 2,c);
   s[1] = create_sphere(create_point(.5, 1.5, -3.0), .5,c);
   struct point eye = create_point(0,0,-14);
   
   cast_all_rays(-10,10,-7.5,7.5,1024,768,eye,s,2);

}
Beispiel #13
0
void test_create_color()
{
    uint8_t expected_color[3] = {0, 1, 2};
    Color color = create_color(0, 1, 2);
    
    assert(color.r == expected_color[0]);
    assert(color.g == expected_color[1]);
    assert(color.b == expected_color[2]);

    printf("Create Color Passed\n");
}
Beispiel #14
0
t_color* create_color_from_id(int id)
{
    if(id >= MAX_NB_COLOR || id < 0) return NULL;

    if(id == 0) return create_color(255.0/255.0, 0.0, 0.0); // RED
    if(id == 1) return create_color(0, 255.0/255.0, 0.0); // GREEN
    if(id == 2) return create_color(0.0, 0.0, 255.0/255.0); // BLUE
    if(id == 3) return create_color(255.0/255.0, 255.0/255.0, 0.0); // YELLOW
    if(id == 4) return create_color(255.0/255.0, 0.0, 255.0/255.0); // PINK
    if(id == 5) return create_color(255.0/255.0, 165.0/255.0, 0.0); // ORANGE
    if(id == 6) return create_color(131.0/255.0, 131.0/255.0, 131.0/255.0); // GREY
    if(id == 7) return create_color(139.0/255.0, 69.0/255.0, 19.0/255.0); // BROWN
    if(id == 8) return create_color(132.0/255.0, 112.0/255.0, 255.0/255.0); // PURPLE
    //if(id == 9) return create_color(255.0/255.0, 255.0/255.0, 255.0/255.0); // WHITE

    return NULL;
}
Beispiel #15
0
void test_clear_color()
{
    uint8_t expected_color[3] = {0, 0, 0};
    Color color = create_color(0, 1, 2);
    clear_color(&color);
    
    assert(color.r == expected_color[0]);
    assert(color.g == expected_color[1]);
    assert(color.b == expected_color[2]);

    printf("Clear Color Passed\n");
}
Beispiel #16
0
/**
 * React to changes
 */
static errr Term_xtra_gcu_react(void) {
    if (ascii_walls) {
        int i;
        ascii_walls = FALSE;
        for (i = 0; i < 4; i++) {
            // magma as %:D
            feat_x_char[i][FEAT_MAGMA] = 0x23;
            feat_x_attr[i][FEAT_MAGMA] = 0x01;

            // quartz as %:D
            feat_x_char[i][FEAT_QUARTZ] = 0x23;
            feat_x_attr[i][FEAT_QUARTZ] = 0x01;

            // quartz/magma w treasure as *:o
            feat_x_char[i][FEAT_MAGMA_K] = feat_x_char[i][FEAT_QUARTZ_K] = 0x2A;
            feat_x_attr[i][FEAT_MAGMA_K] = feat_x_attr[i][FEAT_QUARTZ_K] = 0x03;

            // granite walls as #:D
            feat_x_char[i][FEAT_GRANITE] = 0x23;
            feat_x_attr[i][FEAT_GRANITE] = 0x01;

            // permanent walls as #:r
            feat_x_char[i][FEAT_PERM] = 0x23;
            feat_x_attr[i][FEAT_PERM] = 0x04;
        }
    }

#ifdef A_COLOR
    if (COLORS == 256 || COLORS == 88) {
        /* If we have more than 16 colors, find the best matches. These numbers
         * correspond to xterm/rxvt's builtin color numbers--they do not
         * correspond to curses' constants OR with curses' color pairs.
         *
         * XTerm has 216 (6*6*6) RGB colors, with each RGB setting 0-5.
         * RXVT has 64 (4*4*4) RGB colors, with each RGB setting 0-3.
         *
         * Both also have the basic 16 ANSI colors, plus some extra grayscale
         * colors which we do not use.
         */
        int i;
        int scale = COLORS == 256 ? 6 : 4;

        for (i = 0; i < BASIC_COLORS; i++) {
            int fg = create_color(i, scale);
            int isbold = bold_extended ? A_BRIGHT : A_NORMAL;
            init_pair(i + 1, fg, bg_color);
            colortable[i] = COLOR_PAIR(i + 1) | isbold;
        }
    }
#endif

    return 0;
}
Beispiel #17
0
void the_end(display &disp, std::string text, unsigned int duration)
{
	//
	// Some sane defaults.
	//
	if(text.empty())
		text = _("The End");
	if(!duration)
		duration = 3500;

	SDL_Rect area = screen_area();
	CVideo &video = disp.video();
	sdl_fill_rect(video.getSurface(),&area,0);

	update_whole_screen();
	disp.flip();

	const size_t font_size = font::SIZE_XLARGE;

	area = font::text_area(text,font_size);
	area.x = screen_area().w/2 - area.w/2;
	area.y = screen_area().h/2 - area.h/2;

	for(size_t n = 0; n < 255; n += 5) {
		if(n)
			sdl_fill_rect(video.getSurface(),&area,0);

		const SDL_Color col = create_color(n, n, n, n);
		font::draw_text(&video,area,font_size,col,text,area.x,area.y);
		update_rect(area);

		events::pump();
		events::raise_process_event();
		events::raise_draw_event();
		disp.flip();
		disp.delay(10);
	}

	//
	// Delay after the end of fading.
	// Rounded to multiples of 10.
	//
	unsigned int count = duration/10;
	while(count) {
		events::pump();
		events::raise_process_event();
		events::raise_draw_event();
		disp.flip();
		disp.delay(10);
		--count;
	}
}
Beispiel #18
0
void CDebugger::Update(const CPlayer& Player, CBullets& Bullets, CEnemies& Enemies)
{
    static std::stringstream ss;
    static int mouse_x, mouse_y;
    static SDL_Surface* debug   = NULL;
    static SDL_Color white      = create_color(WHITE);

    if(this->IsDebug())
    {
        GetMousePosition(mouse_x, mouse_y);

        /* First, place (x, y) coordinates next to the player sprite. */
        ss << "(" << (int)Player.GetX() << ", " << (int)Player.GetY() << ")";
        debug = render_text(this->debug_font, ss.str(), NULL, white, CREATE_SURFACE | TRANSPARENT_BG);
        this->Display.Blit(debug, (int)Player.GetX(), (int)Player.GetY() - get_text_height(this->debug_font, ss.str()));

        SDL_FreeSurface(debug); // Free memory
        ss.str(std::string());

        /* Then, place (x, y) coordinates next to the mouse. */
        ss << "(" << mouse_x << ", " << mouse_y << ")";
        debug = render_text(this->debug_font, ss.str(), NULL, white, CREATE_SURFACE | TRANSPARENT_BG);
        this->Display.Blit(debug, mouse_x, mouse_y - get_text_height(this->debug_font, ss.str()));

        SDL_FreeSurface(debug); // Free memory
        ss.str(std::string());

        /* Every bullet also gets (x, y) info next to it. */
        for(CBullets::iterator i = Bullets.begin(); i != Bullets.end(); i++)
        {
            ss << "(" << (int)(*i)->GetX() << ", " << (int)(*i)->GetY() << ")";
            debug = render_text(this->debug_font, ss.str(), NULL, white, CREATE_SURFACE | TRANSPARENT_BG);
            this->Display.Blit(debug, (int)(*i)->GetX(), (int)(*i)->GetY() - get_text_height(this->debug_font, ss.str()));

            SDL_FreeSurface(debug); // Free memory
            ss.str(std::string());
        }

        ss.str(std::string());

        /* And finally, every enemy gets (x, y) as well. */
        for(CEnemies::iterator i = Enemies.begin(); i != Enemies.end(); i++)
        {
            ss << "(" << (int)(*i)->GetX() << ", " << (int)(*i)->GetY() << ")";
            debug = render_text(this->debug_font, ss.str(), NULL, white, CREATE_SURFACE | TRANSPARENT_BG);
            this->Display.Blit(debug, (int)(*i)->GetX(), (int)(*i)->GetY() - get_text_height(this->debug_font, ss.str()));

            SDL_FreeSurface(debug);
            ss.str(std::string());
        }
    }
}
Beispiel #19
0
void test_set_rgb_color()
{
    uint8_t expected_color[3] = {255, 255, 255};
    Color color = create_color(0, 1, 2);
    clear_color(&color);
    set_color_rgb(&color, 255, 255, 255);
    
    assert(color.r == expected_color[0]);
    assert(color.g == expected_color[1]);
    assert(color.b == expected_color[2]);

    printf("Set RGB Color Passed\n");
}
Beispiel #20
0
struct light input_light(int argc, char *in[]){
   int i = 0;
   while(strcmp(in[i],"-light")!= 0){
      if(i>=argc-1)
         return create_light(create_point(-100,100,-100),create_color(1.5,1.5,1.5));
      i++;
   }
   double x = -100;
   double y = 100;
   double z = -100;
   
   double r = 1.5;
   double g = 1.5;
   double b = 1.5;

   if(i+1<argc && !equalToFlag(argc,in,i+1))
      x = convert_double(in[i+1],-100);
   else 
      return create_light(create_point(x,y,z),create_color(r,g,b)); 
 
   if(i+2<argc && !equalToFlag(argc,in,i+2))
      y = convert_double(in[i+2],100);
   else 
      return create_light(create_point(x,y,z),create_color(r,g,b)); 

   if(i+3<argc && !equalToFlag(argc,in,i+3))
      z = convert_double(in[i+3],-100);
   else 
      return create_light(create_point(x,y,z),create_color(r,g,b)); 

   if(i+4<argc && !equalToFlag(argc,in,i+4))
      r = convert_double(in[i+4],1.5);
   else 
      return create_light(create_point(x,y,z),create_color(r,g,b)); 
   
   if(i+5<argc && !equalToFlag(argc,in,i+5))
      g = convert_double(in[i+5],1.5);
   else 
      return create_light(create_point(x,y,z),create_color(r,g,b)); 

   if(i+6<argc && !equalToFlag(argc,in,i+6))
      b = convert_double(in[i+6],1.5);
   else 
      return create_light(create_point(x,y,z),create_color(r,g,b)); 

   return create_light(create_point(x,y,z),create_color(r,g,b)); 
}
Beispiel #21
0
/*
** brief : create our struct light
** @scene : our scene
** @arr : our tab (informations)
*/
void		create_light(t_scene **scene, char **arr)
{
  t_light	*elt;

  if (my_arrlen(arr) < 7)
    my_warning_obj("light");
  else
    {
      elt = my_malloc(sizeof(*elt));
      elt->coord = create_vector(atof(arr[0]), atof(arr[1]), atof(arr[2]));
      elt->color = create_color(atoi(arr[3]), atoi(arr[4]), atoi(arr[5]));
      elt->puiss = atof(arr[6]);
      elt->next = (*scene)->list_light;
      (*scene)->list_light = elt;
    }
}
Beispiel #22
0
void game_display::float_label(const map_location& loc, const std::string& text,
						  int red, int green, int blue)
{
	if(preferences::show_floating_labels() == false || fogged(loc)) {
		return;
	}

	font::floating_label flabel(text);
	flabel.set_font_size(font::SIZE_XLARGE);
	const SDL_Color color = create_color(red, green, blue);
	flabel.set_color(color);
	flabel.set_position(get_location_x(loc)+zoom_/2, get_location_y(loc));
	flabel.set_move(0, -2 * turbo_speed());
	flabel.set_lifetime(60/turbo_speed());
	flabel.set_scroll_mode(font::ANCHOR_LABEL_MAP);

	font::add_floating_label(flabel);
}
Beispiel #23
0
void CParticleEngine::GenerateExplosion(const CEntity* Entity)
{
    /* Set the amount of particles to create */
    int limit = 20 + rand() % 20;

    /* Obtain pixel color at the center of the sprite for explosions */
    Uint8 r, g, b;
    SDL_GetRGB(get_pixel(Entity->GetEntity(),
        Entity->GetCollisionBoundaries()->w / 2,
        Entity->GetCollisionBoundaries()->h / 2),
        Entity->GetEntity()->format, &r, &g, &b);

    SDL_Color color = create_color(r, g, b);

    for(short i = 0; i < limit; i++)
    {
        this->Particles.push_back(new CParticle(this->Display, this->Timer,
            color, (int)Entity->GetX(), (int)Entity->GetY()));
    }
}
Beispiel #24
0
void test_printColor(void){
   struct color	c = create_color(.3,.5,.9);
   struct color c2 = create_color(1,0,1.0);
   printColor(c);
   printColor(c2);  
}
Beispiel #25
0
t_color* copy_color(t_color* color)
{
    return create_color(color->r, color->g, color->b);
}