コード例 #1
0
ファイル: ui_snow.cpp プロジェクト: BackupTheBerlios/ppracer
void
init_ui_snow()
{
    for(int i=0; i<num_particles; i++){
		make_particle(i, frand(), frand());
    }
    push_position = ppogl::Vec2d(0.0, 0.0);
}
コード例 #2
0
ファイル: ui_snow.cpp プロジェクト: BackupTheBerlios/ppracer
void
make_ui_snow(const ppogl::Vec2d& pos)
{
    if(num_particles < MAX_NUM_PARTICLES){
		make_particle( num_particles, pos.x()/GameMode::resolution.x(),
				(double(GameMode::resolution.y())-pos.y())/GameMode::resolution.y());
		num_particles++;
    }
}
コード例 #3
0
ファイル: fireworks-13.c プロジェクト: Choino/school
void spawn_particle(int i)
{
  SHAPE cur;
  NOZZLE *cur_nozzle;

  cur_nozzle = &nozzles[i];
  make_cube_smart(&cur, .1);
  make_particle(&particles[i], colors[RED], colors[BLACK], 1, colors[RED], colors[BLACK], 0, 0, cur, 0, .05, 0);
  real_translation(&(particles[i].shape), cur_nozzle->x, cur_nozzle->y + .1, 0);
}
コード例 #4
0
ファイル: ui_snow.c プロジェクト: Jisby/TuxRacer-SDL2
void init_ui_snow( void )
{
    int i;

	num_particles=orig_num_particles=PARTICLE_DENSITY*getparam_x_resolution()*getparam_y_resolution();

    for( i=0; i<num_particles; i++) {
	make_particle( i, frand(), frand() );
    }
    push_position = make_point2d( 0.0, 0.0 );
}
コード例 #5
0
ファイル: ui_snow.c プロジェクト: Jisby/TuxRacer-SDL2
void
make_ui_snow( point2d_t pos ) {
    scalar_t xres, yres;

    xres = getparam_x_resolution();
    yres = getparam_y_resolution();

    if ( num_particles < MAX_NUM_PARTICLES ) {
	make_particle( num_particles, pos.x/xres, pos.y/yres );
	num_particles++;
    }
}
コード例 #6
0
ファイル: ui_snow.cpp プロジェクト: gonium/fc-extremetuxracer
void
make_ui_snow( pp::Vec2d pos ) {
    double xres, yres;

    xres = getparam_x_resolution();
    yres = getparam_y_resolution();

    if ( num_particles < MAX_NUM_PARTICLES ) {
	make_particle( num_particles, pos.x/xres, pos.y/yres );
	num_particles++;
    }
}
コード例 #7
0
ファイル: particle_effects.c プロジェクト: rcorre/alecs
void spawn_particles(particle_generator *gen, double time, double density,
    vector source_velocity) {
  generator_data *data = gen->data;
  double spawn_count = gen->_spawn_counter + data->spawn_rate * density * time;
  // place excess in spawn counter
  gen->_spawn_counter = spawn_count - (int)spawn_count;
  // spawn a whole number of particles
  for (int i = 0; i < (int)spawn_count; i++) {
    // create particle and copy data to node's storage
    particle *p = make_particle(gen->data, gen->position, gen->angle);
    p->velocity = vector_add(p->velocity, source_velocity);
    list_push(particle_list, p);
  }
}
コード例 #8
0
void ParticleGenerator::advance(float dt)
{
    std::cout << "particles: " << particles.size() << std::endl;

    particles.push_back(make_particle());

    for (auto itr = particles.begin(); itr != particles.end(); /*in loop*/)
    {
        Particle& p = *itr;

        // position integration
        p.x += dt * p.vx;
        p.y += dt * p.vy;
        p.z += dt * p.vz;

        // add gravity
        p.vy += dt * (-9.8f);

        // add drag (air resistance)
        p.vx *= 0.99f;
        p.vy *= 0.99f;
        p.vz *= 0.99f;

        // reduce brightness
        p.brightness += dt * (-0.2f);

        // bounce off table, losing energy
        if (p.y < 0)
        {
            p.vy = -p.vy * 0.8f;
        }

        if (p.brightness < 0)
        {
            particles.erase(itr++);
        }
        else
        {
            itr++;
        }
    }
}
コード例 #9
0
ファイル: pilot.c プロジェクト: callaa/luola
/* Make sweatdrops appear around pilot's head */
static void make_sweatdrops(const struct Pilot *pilot) {
    struct Particle *sweatdrop;
    int r;
    for (r = 0; r < 6; r++) {
        sweatdrop =
            make_particle (pilot->walker.physics.x + (8 - rand () % 16),
                           pilot->walker.physics.y-pilot->sprite[0]->h *(2.0/3) - rand () % 12, 2);
        sweatdrop->color[0] = 220;
        sweatdrop->color[1] = 220;
        sweatdrop->color[2] = 255;
#ifdef HAVE_LIBSDL_GFX
        sweatdrop->rd = 0;
        sweatdrop->bd = 0;
        sweatdrop->gd = 0;
        sweatdrop->ad = -255 / 2;
#else
        sweatdrop->rd = -220 / 2;
        sweatdrop->gd = -220 / 2;
        sweatdrop->bd = -255 / 2;
#endif
        sweatdrop->vector.x = 0;
        sweatdrop->vector.y = 0;
    }
}
コード例 #10
0
std::shared_ptr<Particle> ParticleSystem::make_particle() {
    return make_particle(1.0f, ci::Vec2f::zero());
}
コード例 #11
0
ファイル: fireworks-24.c プロジェクト: Zaxcoding/fireworks
// quantity needs to be a square number
void make_explosion(EXPLOSION *po, GLfloat radius, GLfloat density, 
                          int quantity, GLfloat cube_size, int after_counter,
                          short shape, SOUND sound, GLfloat start_x, GLfloat start_y) {
  int i, j, k;
  int count = 0;
  short solid = rand()%5;
  GLfloat color[3];
  GLfloat other_color[3];
  
  if(shape ==0){
  		solid =2;
  }
  if(solid){
  		for(i=0;i<3;++i){
  			color[i] =(float)((rand() % (100)))/100.;			//randomize color
  			
  		}
  		
  		if(solid<3){
  			other_color[0] =color[0];
  			other_color[1] = color[1];
  			other_color[2] = color[2];
  		}
  		else{
  			for(i=0;i<3;++i){
  				other_color[i] =(float)((rand() % (100)))/100.;			//randomize color
  			
  			}
  		}
  }
  
  else{
  	 	for(i=0;i<3;++i){
  			color[i] =0;
  		}
  
  }
  	
  SHAPE cur;
  GLfloat trans_x, trans_y, trans_z;
  GLfloat ray = cube_size;
  
  start_y +=(float)((rand() % (7)) - 3)/10.;
  start_x +=(float)((rand() % (11)) - 5)/100.;

  po -> radius = radius;
  po -> density = density;
  po -> quantity = quantity;
  po -> cube_size = cube_size;
  po -> shape = shape;
  po -> sound = sound;
  po -> counter = 0;
  po -> start_x = start_x;
  po -> start_y = start_y;
  po -> after_counter = after_counter + radius;
  po -> fizz=0;
  po -> particles = malloc(quantity*sizeof(PARTICLE));

  k = sqrt(quantity)/2;

  // draw the top half
  for (i = 0; i <= k; i++) {
    for (j = 0; j <= k; j++) {

      make_cube_smart(&cur, ray);
      real_translation(&cur, start_x, start_y, 0);

      int t = (360.0/(float)(k) * j);    // theta
      int p = (180.0/(float)(k) * i); // phi

      GLfloat theta = (t * M_PI/180.); // theta angle
      GLfloat phi = (p * M_PI/180.);  // phi angle
      


      trans_x = ray * cos(phi) * cos(theta) + (float)((rand() % (3)) - 1)/80.;
      trans_y = ray * sin(phi) + (float)((rand() % (3)) - 1)/80.;
      trans_z = -ray * cos(phi) * sin(theta) + (float)((rand() % (3)) - 1)/80.;
    
      make_particle(&(po->particles[i*4 + j]), color, solid, 1000, cur, trans_x, trans_y, trans_z);
      count++;
    }
  }
  // draw the bottom half
  for (i = 0; i <= k; i++) {
    for (j = 0; j <= k; j++) {

      make_cube_smart(&cur, ray);
      real_translation(&cur, start_x, start_y, 0);

      int t = (360.0/(float)(k) * j);    // theta
      int p = (180.0/(float)(k) * i - 180); // phi

      GLfloat theta = (t * M_PI/180.); // theta angle
      GLfloat phi = (p * M_PI/180.);  // phi angle
      
      trans_x = ray * cos(phi) * cos(theta) + (float)((rand() % (3)) - 1)/100.;;
      trans_y = ray * sin(phi) + (float)((rand() % (3)) - 1)/100.;;
      trans_z = -ray * cos(phi) * sin(theta) + (float)((rand() % (3)) - 1)/100.;;
    
      make_particle(&(po->particles[count - 1 + i*4 + j]), other_color, solid,1000, cur, trans_x, trans_y, trans_z);
    }
  }
}
コード例 #12
0
ファイル: fireworks-30.c プロジェクト: Choino/school
void make_fuse(FUSE *po, int hangtime, GLfloat *init_color, GLfloat trans_x,
                      GLfloat trans_y, GLfloat trans_z,
                      GLfloat ray, GLfloat start_x, GLfloat start_y)
{

  int i;
  double divisor;
  PARTICLE *cur_po;
  SHAPE cur;
  GLfloat a;
  GLfloat color_changed[3];
  GLfloat color_used[3];

  for(i=0;i<3;i++){
  	 	a =(float)((rand() % (10)))/500.;
  	 	color_used[i] =a;
  
  }
  
  if(start_y==-1){
  		po->trail_size=rand() % 20 + 45;
  		divisor = 100;
  		trans_y=0;
  }
  else{
  		po->trail_size=25;
  		divisor = 500;
  		
  }
  
  for(i=0;i<3;i++){
  	 	a =(float)((rand() % (10)))/divisor;
  	 	color_used[i] =a;
  
  }
  po->trail = malloc(po->trail_size*sizeof(PARTICLE));

  for (i = 0; i < po->trail_size; i++) {
    cur_po = &(po->trail[i]);
    make_cube_smart(&cur, ray);
    real_translation(&cur, start_x, start_y + i*ray, 0);
	
    color_changed[0] = color_used[0]*i;
    color_changed[1] = color_used[1]*i;
    color_changed[2] = color_used[2]*i;
    

    make_particle(cur_po, color_changed, 1, cur, trans_x, trans_y, trans_z);

  }

  hangtime = (rand() % 20) + 15;
  
  ////FOR INTRO TEXT
  if(intro_flag_1){
  		hangtime=26;
  }
  else if(intro_flag_2){
  		hangtime=26;
  }
  else if(intro_flag_3){
  		hangtime =17;
  }
  else if(intro_flag_4){
  		hangtime =14;
  
  }

  po -> hangtime = hangtime;
  po -> counter = 0;
  po -> start_x = start_x;
  po -> start_y = start_y;

}
コード例 #13
0
ファイル: fireworks-30.c プロジェクト: Choino/school
// quantity needs to be a square number
void make_explosion(EXPLOSION *po, GLfloat radius, GLfloat density, 
                          int quantity, GLfloat cube_size, int after_counter,
                          short shape, SOUND sound, GLfloat start_x, GLfloat start_y,
                          short is_sparkler, short is_screamer) {
  int i, j, k;
  int count = 0;
  short solid = rand()%5;
  GLfloat color[3];
  GLfloat other_color[3];
  
  if(shape ==0){
  		solid =2;
  }
  if(solid){
  		for(i=0;i<3;++i){
  			color[i] =(float)((rand() % (100)))/100.;			//randomize color
  			
  		}
  		
  		if(solid<3){
  			other_color[0] =color[0];
  			other_color[1] = color[1];
  			other_color[2] = color[2];
  		}
  		else{
  			for(i=0;i<3;++i){
  				other_color[i] =(float)((rand() % (100)))/100.;			//randomize color
  			
  			}
  		}
  }
  
  else{
  	 	for(i=0;i<3;++i){
  			color[i] =0;
  		}
  
  }
  	
  SHAPE cur;
  GLfloat trans_x, trans_y, trans_z;
  GLfloat ray = cube_size;
  
  start_x +=(float)((rand() % (11)) - 5)/100.;

  po -> radius = radius;
  po -> density = density;
  po -> quantity = quantity;
  po -> cube_size = cube_size;
  po -> shape = shape;
  po -> sound = sound;
  po -> counter = 0;
  po -> start_x = start_x;
  po -> start_y = start_y;
  po -> after_counter = after_counter + radius;
  po -> fizz=0;
  po -> particles = malloc(quantity*sizeof(PARTICLE));


  double scale_x=.025;
  double scale_y=.025;
  if(shape==0||shape ==1){
  	  k = sqrt(quantity)/2;

	  // draw the top half
	  for (i = 0; i <= k; i++) {
		for (j = 0; j <= k; j++) {
	
		  make_cube_smart(&cur, ray);
		  real_translation(&cur, start_x, start_y, 0);
	
		  int t = (360.0/(float)(k) * j);    // theta
		  int p = (180.0/(float)(k) * i); // phi
	
		  GLfloat theta = (t * M_PI/180.); // theta angle
		  GLfloat phi = (p * M_PI/180.);  // phi angle
		  
	
	
		  trans_x = ray * cos(phi) * cos(theta) + (float)((rand() % (3)) - 1)/80.;
		  trans_y = ray * sin(phi) + (float)((rand() % (3)) - 1)/80.;
		  trans_z = -ray * cos(phi) * sin(theta) + (float)((rand() % (3)) - 1)/80.;
		
		  make_particle(&(po->particles[i*4 + j]), color, solid, cur, trans_x, trans_y, trans_z);
		  (&(po -> particles[i*4 + j])) -> is_sparkler = is_sparkler; 
      count++;
		}
	  }
	  // draw the bottom half
	  for (i = 0; i <= k; i++) {
		for (j = 0; j <= k; j++) {
	
		  make_cube_smart(&cur, ray);
		  real_translation(&cur, start_x, start_y, 0);
	
		  int t = (360.0/(float)(k) * j);    // theta
		  int p = (180.0/(float)(k) * i - 180); // phi
	
		  GLfloat theta = (t * M_PI/180.); // theta angle
		  GLfloat phi = (p * M_PI/180.);  // phi angle
		  
		  trans_x = ray * cos(phi) * cos(theta) + (float)((rand() % (3)) - 1)/100.;;
		  trans_y = ray * sin(phi) + (float)((rand() % (3)) - 1)/100.;;
		  trans_z = -ray * cos(phi) * sin(theta) + (float)((rand() % (3)) - 1)/100.;;
		
		  make_particle(&(po->particles[count - 1 + i*4 + j]), other_color, solid, cur, trans_x, trans_y, trans_z);
      (&(po -> particles[i*4 + j])) -> is_sparkler = is_sparkler; 

    }
	  }
  
  }
  else if(shape ==2){
  		
  		make_heart(po,scale_x,scale_y,0,0);
  		make_heart(po,scale_x*1.7,scale_y*1.7,1,28);
  		po->after_counter =100;
  		po->radius =20;
  }
  
  else if(shape ==-1){		  ////FOR INTRO TEXT
  		make_b(po,scale_x*4,scale_y*4,1,0);
  		make_y(po,scale_x*4,scale_y*4,1,19);
  		intro_flag_1=0;
  		po->after_counter =100;
  		po->radius =18;
  }
  else if(shape ==-2){			  ////FOR INTRO TEXT
  		make_z(po,scale_x*3,scale_y*3,1,0);
  		make_a(po,scale_x*3,scale_y*2,1,40);
  		make_c(po,scale_x*2.4,scale_y*2.4,1,58);
  		make_h(po,scale_x*3,scale_y*3,1,71);
  		intro_flag_2=0;
  		po->after_counter =100;
  		po->radius =20;
  }
  else if(shape ==-3){			  ////FOR INTRO TEXT
  
  		make_a(po,scale_x*2,scale_y*2,2,0);
  		make_n(po,scale_x*1.2,scale_y*1.2,1,18);
  		make_d(po,scale_x*2,scale_y*2,1,43);
  		intro_flag_3=0;
  		po->after_counter =100;
  		po->radius =30;
  }
  else if(shape ==-4){			  ////FOR INTRO TEXT
  		make_a(po,scale_x*2,scale_y*2,3,0);
  		make_n(po,scale_x*1.2,scale_y*1.2,0,18);
  		make_d(po,scale_x*2,scale_y*2,0,43);
  		make_y(po,scale_x*2.1,scale_y*2.1,0,65);
  		intro_flag_4=0;
  		po->after_counter =100;
  		po->radius =30;
  		
  }
  
}
コード例 #14
0
ファイル: waves.cpp プロジェクト: sellibitze/LEDparticles
int main() {
    // The physical computations run at about 1500 Hz. 30 consecutive
    // time steps are mixed into a frame buffer for motion blur. But
    // this is not only about motion blur. This higher temporal resolution
    // is necessary to avoid discretization errors to grow too large and
    // to keep the whole thing "stable".
    //
    // The framebuffer is "oversampled" (higher resolution) for
    // anti-aliasing.
    const int num_particles = 10;
    const int substeps = 30; // temporal oversampling
    const int sover = 5; // spatial oversampling

    std::srand(std::time(0));
    std::vector<particle> ps;
    ps.push_back( // bottom border particle that is not moving
        make_particle(
            make_random_color(),
            -1
        )
    );
    for (int i = 0; i < num_particles; ++i) {
        ps.push_back( // almost equidistantly spaced particles
            make_particle(
                make_random_color(),
                (i + 0.9f + 0.2f * uniform_random()) / (1 + num_particles) * (num_leds + 1) - 1
            )
        );
    }
    ps.push_back( // top border particle that is not moving
        make_particle(
            make_random_color(),
            num_leds
        )
    );

    std::vector<int> framebuff (num_leds * 3 * sover);
    std::vector<unsigned char> scratch;
    int time = -1;
    int period = 10000; // time steps until next impulse
    int part_change_color_index = 1;
    color part_change_color_new = {{0}}, part_change_color_old = {{0}};
#ifdef WRITE_PPM
    const int iters = 500; // for debugging purposes
    write_binary_ppm_header(num_leds, iters, std::cout);
    for (int i = 0; i < iters; ++i) {
#else
    for (;;) {
#endif
        // blank frame buffer (black)
        std::fill(framebuff.begin(), framebuff.end(), 0);
        for (int s = 0; s < substeps; ++s) {
            render_frame(ps, sover, substeps, framebuff);
            time = (time + 1) % period;
            if (time <= 1000) { // impulse phase
                if (time == 0) {
                    period = 5000 + std::rand() % 10000;
                    part_change_color_index = (std::rand() % num_particles) + 1;
                    part_change_color_old = ps[part_change_color_index].col;
                    part_change_color_new = make_random_color();
                }
                float s1 = squared(std::sin(time * (3.14159265 / 2000)));
                float s2 = squared(std::sin(time * (3.14159265 / 1000)));
                ps[0].pos = s2 * 15 - 1; // move bottom particle around
                // also change the color of a random particle once in a while
                ps[part_change_color_index].col = fade(
                    part_change_color_old,
                    part_change_color_new, s1);
            }
            update_accels(ps);
            progress(ps);
        }
        write_frame(framebuff, 1.0f/substeps, sover, scratch, std::cout);
#ifndef WRITE_PPM
        usleep(20000); // wait 20 ms (=> about 50 frames/sec)
#endif
    }
    return 0;
}
コード例 #15
0
ファイル: fireworks-13.c プロジェクト: Choino/school
// quantity needs to be a square number
void make_explosion(EXPLOSION *po, GLfloat radius, GLfloat density, 
                          int quantity, GLfloat cube_size,
                          short shape, SOUND sound, GLfloat start_x, GLfloat start_y) {
  int i, j, k;
  int count = 0;
  int count1 = 0;
  SHAPE cur;
  GLfloat trans_x, trans_y, trans_z;
  GLfloat ray = cube_size;

  po -> radius = radius;
  po -> density = density;
  po -> quantity = quantity;
  po -> cube_size = cube_size;
  po -> shape = shape;
  po -> sound = sound;
  po -> counter = 0;
  po -> start_x = start_x;
  po -> start_y = start_y;

  po -> particles = malloc(quantity*sizeof(PARTICLE));

  k = sqrt(quantity)/2;

  // draw the top half
  for (i = 0; i <= k; i++) {
    for (j = 0; j <= k; j++) {

      make_cube_smart(&cur, ray);
      real_translation(&cur, start_x, start_y, 0);

      int t = (360.0/(float)(k) * j);    // theta
      int p = (180.0/(float)(k) * i); // phi

      GLfloat theta = (t * M_PI/180.); // theta angle
      GLfloat phi = (p * M_PI/180.);  // phi angle
      printf("theta is %f, phi is %f\ncos(theta) is %f, cos(phi) is %f\n\n", theta, phi, cos(theta), cos(phi));
      
      trans_x = ray * cos(phi) * cos(theta);
      trans_y = ray * sin(phi);
      trans_z = -ray * cos(phi) * sin(theta);
    
      make_particle(&(po->particles[i*4 + j]), colors[RED], colors[BLACK], 1, colors[RED],
                   colors[BLACK], 1, 1000, cur, trans_x, trans_y, trans_z);
      count++;
    }
  }
  // draw the bottom half
  for (i = 0; i <= k; i++) {
    for (j = 0; j <= k; j++) {

      make_cube_smart(&cur, ray);
      real_translation(&cur, start_x, start_y, 0);

      int t = (360.0/(float)(k) * j);    // theta
      int p = (180.0/(float)(k) * i - 180); // phi

      GLfloat theta = (t * M_PI/180.); // theta angle
      GLfloat phi = (p * M_PI/180.);  // phi angle
      printf("theta is %f, phi is %f\ncos(theta) is %f, cos(phi) is %f\n\n", theta, phi, cos(theta), cos(phi));
      
      trans_x = ray * cos(phi) * cos(theta);
      trans_y = ray * sin(phi);
      trans_z = -ray * cos(phi) * sin(theta);
    
      make_particle(&(po->particles[count - 1 + i*4 + j]), colors[RED], colors[BLACK], 1, colors[RED],
                   colors[BLACK], 1, 1000, cur, trans_x, trans_y, trans_z);
      count1++;
    }
  }

  printf("Count is %d\n", count + count1 - 1);

}