示例#1
0
// constructor sets up new sphere
// NOTE : while condition was removed
// TODO : maybe include it again
Sphere::Sphere(double rad)
{
	// RADIUS MUST BE BEFORE RANDOM POINTS
	radius = rad;
	// gets 4 random points for the bezier curve
	p1 = random_ranged_point(radius);
	p2 = new_curve_point(p1);		
	p3 = new_curve_point(p2);
	p4 = new_curve_point(p3);
	
	// position starts at p1
	pos = p1;
	// 3D
	previous_pos.x = 0.0;
	previous_pos.y = 5.0;
	previous_pos.z = 0.0;
	// = {0.0, 5.0, 0.0};
		
	// gets a random direction, this might be a wasted step
	direction = random_direction(radius);

	active = 0;
	velocity = random_velocity();	

	// start on a curved path
	path = 1;
	color = random_color();		

	curve_length = get_curve_length();
	start_time = (double) clock();
	curve_time = curve_length / velocity;
	ghost = 0;
}
示例#2
0
static char *get_random_color_str(void)
{
    unsigned char r,g,b;
    random_color(&r, &g, &b);
    MPL_snprintf(random_color_str, MAX_RANDOM_COLOR_STR, "%3d %3d %3d", (int)r, (int)g, (int)b);
    return random_color_str;
}
示例#3
0
static char *get_random_color_str(void)
{
    unsigned char r,g,b;
    random_color(&r, &g, &b);
    MPL_snprintf(random_color_str, sizeof(random_color_str),
		  "%3d %3d %3d", (int)r, (int)g, (int)b);
    return random_color_str;
}
示例#4
0
void draw_lines(ScreenBuffer *s, int frame) {
  set_frame_rate(30);
  s->dim(240);
  //fall(); // broken!
  
  if ((frame % 10) == 0) {
    if (random(0, 2)) {
      // horizontal
      int y = random(0, HEIGHT);
      s->line(random(0, WIDTH), y, random(0, WIDTH), y, random_color());
    } else {
      // vertical
      int x = random(0, WIDTH);
      s->line(x, random(0, HEIGHT), x, random(0, HEIGHT), random_color());
    }
  }
}
 void reset() {
   x = rand() % WIDTH;
   y = rand() % HEIGHT;
   do {
     xv = (rand() % 3) - 1;
     yv = (rand() % 3) - 1;
   } while (!xv && !yv);
   c = random_color();
 }
示例#6
0
文件: Track.C 项目: shanipribadi/non
void
Track::add ( Control_Sequence *t )
{
    DMESSAGE( "adding control sequence" );

    t->track( this );

    t->color( random_color() );

//    control->insert( *t, 0 );
    control->add( t );
    
    adjust_size();
}
示例#7
0
Particle *World::insert_particle(Real x, Real y, Real vx, Real vy, float mass) {
    if (n>=nmax) return NULL;
    pt[n].pos = Vec2(x, y);
    pt[n].vel = Vec2(vx, vy);
    pt[n].mass = mass;

    // for display, we set particle's display radius proportional to
    // the square root of mass, so that area is proportional to mass
    // (this is an aesthetic decision, not a physical one)
    pt[n].radius = sqrt(mass);
    pt[n].color = random_color();
    printf("World::insert_particle %d at (%g,%g) m=%g r=%g\n",
	n, x, y, mass, pt[n].radius);
    return &pt[n++];
}
示例#8
0
文件: Track.C 项目: shanipribadi/non
Track::Track ( const char *L, int channels ) :
    Fl_Group ( 0, 0, 0, 0, 0 )
{
    init();

    if ( L )
        name( L );

    color( random_color() );

    configure_inputs( channels );
    configure_outputs( channels );

    log_create();
}
示例#9
0
int
main (int argc, char* argv[]) {
    
    // Read inputs
    Inputs* inputs = read_inputs();

    // Create image
    Image* image = new_image(
            inputs->box.xMax - inputs->box.xMin,
            inputs->box.yMax - inputs->box.xMin);

    // Generate random colors
    Color colors[inputs->numSites];
    for (int i = 0; i < inputs->numSites; i++) {
        colors[i] = random_color(); 
    }

    // Bruteforce voronoi
    for (int i = inputs->box.xMin; i < inputs->box.xMax; i++) {
        for (int j = inputs->box.yMin; j < inputs->box.yMax; j++) {
            Point curr = { .x = i, .y = j };
            int nearest = 0;
            for (int k = 0; k < inputs->numSites; k++) {
                double old_dist = distance_squared(&curr, &inputs->sites[nearest]);
                double new_dist = distance_squared(&curr, &inputs->sites[k]);
                if (new_dist < old_dist) {
                    nearest = k;
                }
            }
            set_pixel(i, j, colors[nearest], image); 
        }
    }

    // Do line sweep
    fortune(inputs, image);
    print_image(image);

    // Free memory
    free_image(image);
    free_inputs(inputs);

    return 0;
}
示例#10
0
std::vector< types::color > GenerateRandomColorPalette( int how_many, const types::color& background_color, float distance_from_background )
{
	//int how_many_random = 25000;
	std::vector< types::color > random_colors;

	for( int i = 0; i < how_many || (int)random_colors.size() < how_many * 10; ++i )
	{
		types::color random_color( ceng::Random( 0, 255 ), ceng::Random( 0, 255 ), ceng::Random( 0, 255 ) );
		if( ColorDistance( random_color, background_color ) > distance_from_background )
			random_colors.push_back( random_color );
	}
	
	if( random_colors.empty() )
		return random_colors;

	types::color rand_color = random_colors[ ceng::Random( 0, random_colors.size() - 1 ) ];
	std::vector< types::color > result;
	result.push_back( rand_color );

	for( int k = 0; k < how_many; ++k )
	{
		float max_distance = 0;
		types::color max_color;
		for( unsigned int i = 0; i < random_colors.size(); ++i )
		{
			float distance = ColorDistance( random_colors[ i ], result[ 0 ] );
			for( unsigned int j = 1; j < result.size(); ++j )
			{
				distance *= ColorDistance( random_colors[ i ], result[ j ] );
			}

			if( distance > max_distance )
			{
				max_distance = distance;
				max_color = random_colors[ i ];
			}
		}
		result.push_back( max_color );
	}

	return result;
}
/*
 * struct sphere generate_sphere();
 * 
 * return a ball 
 */
struct sphere generate_sphere() {
		struct sphere ball;
		
		do{
			// RADIUS MUST BE BEFORE RANDOM POINTS
			ball.radius = random_radius();
			// gets 4 random points for the bezier curve
			ball.p1 = random_ranged_point(ball.radius);
			ball.p2 = new_curve_point(ball.p1);		
			ball.p3 = new_curve_point(ball.p2);
			ball.p4 = new_curve_point(ball.p3);
			
			// position starts at p1
			ball.pos = ball.p1;
			ball.previous_pos = {0.0, 0.0};
	//printf("generation: %f %f || %f %f\n", ball.previous_pos.x, ball.previous_pos.y, ball.pos.x, ball.pos.y);
			
			// gets a random direction, this might be a wasted step
			ball.direction = random_direction(ball.radius);

			ball.active = 0;

			ball.velocity = random_velocity();	

			// start on a curved path
			ball.path = 1;
			// dead variable is set to 0, used to prevent collisions
			//ball.dead = 0;
			ball.color = random_color();		

			ball.curve_length = curve_length( &ball );
			ball.start_time = (double) clock();
			ball.curve_time = ball.curve_length / ball.velocity;
			ball.ghost = 0;
		}while(collision_detection(ball) == 1 );	
		
		return ball;
}
示例#12
0
/*
 * struct sphere generate_sphere();
 * 
 * return a ball 
 */
struct sphere generate_sphere(int rad) {
		struct sphere ball;
		
		do{
			// RADIUS MUST BE BEFORE RANDOM POINTS
			ball.radius = (rad) ? next_ball_radius : random_radius();
			// gets 4 random points for the bezier curve
			ball.p1 = random_ranged_point(ball.radius);
			ball.p2 = new_curve_point(ball.p1);		
			ball.p3 = new_curve_point(ball.p2);
			ball.p4 = new_curve_point(ball.p3);
			
			// position starts at p1
			ball.pos = ball.p1;
			// 3D
			ball.previous_pos = {0.0, 5.0, 0.0};
			
			// gets a random direction, this might be a wasted step
			ball.direction = random_direction(ball.radius);

			ball.active = 0;

			ball.velocity = random_velocity();	

			// start on a curved path
			ball.path = 1;
			ball.color = random_color();		

			ball.curve_length = curve_length( &ball );
			ball.start_time = (double) clock();
			ball.curve_time = ball.curve_length / ball.velocity;
			ball.ghost = 0;
			// 3D
		}while(collision_detection(ball) == 1 || ball.p1.x == 0.0 || ball.p1.y == 0.0 ||
				ball.p1.z == 0.0);	
		
		return ball;
}
示例#13
0
 // when there is much color accepted, this function 
 // will lead to an dead loop
 RgbColor RandomColor::diff_random_color(){
     if (_acceptedColors.size() < _defColors.size()) {
         // usef default color first
         return _idxDefColors[_acceptedColors.size()]->second;
     }
     LuvColor newluv;
     RgbColor color;
     while(true){
         color = random_color();    
         newluv = rgb2luv(color);
         int i = 0;
         while( i < _acceptedColors.size()) {
             // condition
             if(LuvColor::color_distance(newluv, _acceptedColors[i]) < _dist){
                 break;
             }
             i++;
         }
         if (i == _acceptedColors.size()) 
             break;
     }
     return color;
 }
示例#14
0
void draw_insane_lines(ScreenBuffer *s, int frame) {
  set_frame_rate(30);

  uint32_t c = random_color();
/*  if (frame & 1) {
    // invert
    rect(0, 0, WIDTH, HEIGHT, c);
    c = 0;
  } else {*/
    s->blank();
//  }
  if (frame & 1) {
    // horizontal
    int y = random(0, HEIGHT);
    s->line(0, y, WIDTH, y, c);
  } else {
    // vertical
    for (uint8_t i = 0; i < 2; ++i) {
      int x = random(0, WIDTH);
      s->line(x, 0, x, HEIGHT, c);
    }
  }
}
示例#15
0
PaletteIndex ColorCount::getRandomColor() const
{
    if(m_should_recalc)
    {
        recalc(m_quantity_by_color, m_number_of_colors, getTotal(), m_minimal_chance, m_cumuliative_percent_chance);
        m_should_recalc = false;
    }

    // Get the random color
    PaletteIndex random_color(0);
    {
        float rand = my_utility::random();
        for(float*chance_iter=m_cumuliative_percent_chance; chance_iter!=m_cumuliative_percent_chance+m_number_of_colors; ++chance_iter,++random_color)
        {
            if(rand<*chance_iter)
            {
                break;
            }
        }
    }

    return random_color;
}
示例#16
0
int 
main (int argc, char ** argv)
{
  if (argc < 2) 
  {
    pcl::console::print_info ("Syntax is: %s input.pcd <options>\n", argv[0]);
    pcl::console::print_info ("  where options are:\n");
    pcl::console::print_info ("    -p dist_threshold,max_iters  ..... Subtract the dominant plane\n");
    pcl::console::print_info ("    -c tolerance,min_size,max_size ... Cluster points\n");
    pcl::console::print_info ("    -s output.pcd .................... Save the largest cluster\n");
    return (1);
  }

  // Load the input file
  PointCloudPtr cloud (new PointCloud);
  pcl::io::loadPCDFile (argv[1], *cloud);
  pcl::console::print_info ("Loaded %s (%zu points)\n", argv[1], cloud->size ());

  // Subtract the dominant plane
  double dist_threshold, max_iters;
  bool subtract_plane = pcl::console::parse_2x_arguments (argc, argv, "-p", dist_threshold, max_iters) > 0;
  if (subtract_plane)
  {
    size_t n = cloud->size ();
    cloud = findAndSubtractPlane (cloud, dist_threshold, (int)max_iters);
    pcl::console::print_info ("Subtracted %zu points along the detected plane\n", n - cloud->size ());
  }

  // Cluster points
  double tolerance, min_size, max_size;
  std::vector<pcl::PointIndices> cluster_indices;
  bool cluster_points = pcl::console::parse_3x_arguments (argc, argv, "-c", tolerance, min_size, max_size) > 0;
  if (cluster_points)
  {
    clusterObjects (cloud, tolerance, (int)min_size, (int)max_size, cluster_indices);
    pcl::console::print_info ("Found %zu clusters\n", cluster_indices.size ());
  }

  // Save output
  std::string output_filename;
  bool save_cloud = pcl::console::parse_argument (argc, argv, "-s", output_filename) > 0;
  if (save_cloud)
  {
    // If clustering was performed, save only the first (i.e., largest) cluster
    if (cluster_points)
    {
      PointCloudPtr temp_cloud (new PointCloud);
      pcl::copyPointCloud (*cloud, cluster_indices[0], *temp_cloud);
      cloud = temp_cloud;
    }
    pcl::console::print_info ("Saving result as %s...\n", output_filename.c_str ());
    pcl::io::savePCDFile (output_filename, *cloud);
  }
  // Or visualize the result
  else
  {
    pcl::console::print_info ("Starting visualizer... Close window to exit.\n");
    pcl::visualization::PCLVisualizer vis;

    // If clustering was performed, display each cluster with a random color
    if (cluster_points)
    {
      for (size_t i = 0; i < cluster_indices.size (); ++i)
      {
        // Extract the i_th cluster into a new cloud
        pcl::PointCloud<pcl::PointXYZ>::Ptr cluster_i (new pcl::PointCloud<pcl::PointXYZ>);
        pcl::copyPointCloud (*cloud, cluster_indices[i], *cluster_i);

        // Create a random color
        pcl::visualization::PointCloudColorHandlerRandom<pcl::PointXYZ> random_color (cluster_i);

        // Create a unique identifier
        std::stringstream cluster_id ("cluster");
        cluster_id << i;

        // Add the i_th cluster to the visualizer with a random color and a unique identifier
        vis.addPointCloud<pcl::PointXYZ> (cluster_i, random_color, cluster_id.str ());
      }
    }
    else
    {
      // If clustering wasn't performed, just display the cloud
      vis.addPointCloud (cloud);
    }
    vis.resetCamera ();
    vis.spin ();
  }

  return (0);
}
示例#17
0
int main()
{
 int exit = 0, i;
 VEC3F pos = vec3f(0.0, 0.0, 0.3), ang = ZERO_VEC3F;
 MAT16F mat;
 VERTEX cube_vertex[8];
 POLY3D cube_poly[12];

 init();

 cube_vertex[0].object = vec3f(-CUBE_SIZE, CUBE_SIZE, -CUBE_SIZE);
 cube_vertex[1].object = vec3f(CUBE_SIZE, CUBE_SIZE, -CUBE_SIZE);
 cube_vertex[2].object = vec3f(CUBE_SIZE, -CUBE_SIZE, -CUBE_SIZE);
 cube_vertex[3].object = vec3f(-CUBE_SIZE, -CUBE_SIZE, -CUBE_SIZE);
 cube_vertex[4].object = vec3f(-CUBE_SIZE, CUBE_SIZE, CUBE_SIZE);
 cube_vertex[5].object = vec3f(CUBE_SIZE, CUBE_SIZE, CUBE_SIZE);
 cube_vertex[6].object = vec3f(CUBE_SIZE, -CUBE_SIZE, CUBE_SIZE);
 cube_vertex[7].object = vec3f(-CUBE_SIZE, -CUBE_SIZE, CUBE_SIZE);

 create_poly3d(&cube_poly[0], random_color(), 3, 0, 1, 2);
 create_poly3d(&cube_poly[1], random_color(), 3, 2, 3, 0);
 create_poly3d(&cube_poly[2], random_color(), 3, 7, 6, 5);
 create_poly3d(&cube_poly[3], random_color(), 3, 5, 4, 7);


/*
 create_poly3d(&cube_poly[1], random_color(), 4, 7, 6, 5, 4);
 create_poly3d(&cube_poly[2], random_color(), 4, 4, 5, 1, 0);
 create_poly3d(&cube_poly[3], random_color(), 4, 6, 7, 3, 2);
 create_poly3d(&cube_poly[4], random_color(), 4, 0, 3, 7, 4);
 create_poly3d(&cube_poly[5], random_color(), 4, 5, 6, 2, 1);
*/
 LOCK_VARIABLE(fps);
 LOCK_VARIABLE(frame_count);
 LOCK_FUNCTION(update_fps);
 install_int(update_fps, 1000);

 while(!exit)
  {
   if(key[KEY_ESC]) { exit = 1; }
   if(key[KEY_LEFT]) { pos.x -= MOTION_SPEED; }
   if(key[KEY_RIGHT]) { pos.x += MOTION_SPEED; }
   if(key[KEY_UP]) { pos.z += MOTION_SPEED; }
   if(key[KEY_DOWN]) { pos.z -= MOTION_SPEED; }

   ang.x += 0.01;
   ang.y += 0.01;
   ang.z += 0.01;

   reset_mat16f(mat);
   rotate_x_mat16f(mat, ang.x);
   rotate_y_mat16f(mat, ang.y);
   rotate_z_mat16f(mat, ang.z);
   translate_mat16f(mat, pos.x, pos.y, pos.z);

   for(i = 0; i < 8; i++)
    {
     transform_vec3f(&cube_vertex[i].trans, cube_vertex[i].object, mat);
     project_vertex(&cube_vertex[i]);
    }

   clear_to_color(buffer, 0);
   clear_to_color(BASE_INT_z_buffer, BASE_INT_z_buffer_precision);

   for(i = 0; i < 4; i++)
    {
     update_poly3d_normal(&cube_poly[i], cube_vertex);
     if(!cull_backface(&cube_poly[i], cube_vertex))
     render_poly3d(&cube_poly[i], cube_vertex);
    }

   textprintf_ex(buffer, font, 10, 10, makecol(255, 255, 255), 0, "FPS: %d", fps);
   blit(buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
   frame_count++;
  }

 for(i = 0; i < 6; i++)
  destroy_poly3d(&cube_poly[i]);

 deinit_engine();
 return 0;
}