コード例 #1
0
ファイル: mandelbrot.c プロジェクト: qbein/mandelbrot
int main(int argc, char *argv[]) {
    int sy, sx;
    
    if(argc != 4) {
      usage(argv[0]);
      return 1;
    }

    Config conf = { atoi(argv[1]), atoi(argv[2]), atoi(argv[3]) };

    if(conf.screenX == 0 || conf.screenY == 0 || conf.iterations == 0) {
      usage(argv[0]);
      return 1;
    }

    Color palette[COLORS];
    palette_generate(palette);
    init_ppm(conf);
   
    float xrange = MAX_X - MIN_X;
    float yrange = MAX_Y - MIN_Y;
    
    for(sy = 1; sy <= conf.screenY; sy++) {
        for(sx = 1; sx <= conf.screenX; sx++) {
            float x, y;
            x = 0.0;
            y = 0.0;
            
            float x0 = sx / (float)conf.screenX * xrange + MIN_X; 
            float y0 = sy / (float)conf.screenY * yrange + MIN_Y; 
        
            int i = 0;
            while(((x*x - y*y) < (2*2)) && i < conf.iterations) {
                float xtmp;
                xtmp = x*x - y*y + x0;
                y = 2*x*y + y0;
                x = xtmp;
                i++;
            }
            
            Color c = { 0, 0, 0 };
            if((x*x + y*y) > (2*2)) {
                c = palette[i % COLORS];
            }
            plot(sx, sy, c);
        }

        printf("\n");
    }
    
    return 0;
}
コード例 #2
0
ファイル: timers.cpp プロジェクト: Weanuts/ersky9x
void setupPulses(unsigned int port)
{
  heartbeat |= HEART_TIMER_PULSES ;
#ifdef REV9E
	SuCount += 1 ;
//	progress( 0xA000 + port + ( SuCount << 4 ) ) ;
//	return ;
#endif
	
	if ( port == 0 )
	{
  	if ( s_current_protocol[0] != g_model.protocol )
  	{
  	  switch( s_current_protocol[0] )
  	  {	// stop existing protocol hardware
  	    case PROTO_PPM:
					disable_main_ppm() ;
  	    break;
  	    case PROTO_PXX:
					disable_pxx(0) ;
  	    break;
	//      case PROTO_DSM2:
	//				disable_ssc() ;
	//      break;
	//      case PROTO_PPM16 :
	//				disable_main_ppm() ;
	//      break ;
  	  }
		
  	  s_current_protocol[0] = g_model.protocol ;
  	  switch(s_current_protocol[0])
  	  { // Start new protocol hardware here
  	    case PROTO_PPM:
					init_main_ppm() ;
  	    break;
  	    case PROTO_PXX:
					init_pxx(0) ;
  	    break;
		    case PROTO_OFF:
					init_no_pulses( INTERNAL_MODULE ) ;
  	  	break;
	//      case PROTO_DSM2:
	//				init_main_ppm( 5000, 0 ) ;		// Initial period 2.5 mS, output off
	//				init_ssc() ;
	//      break;
	//      case PROTO_PPM16 :
	//				init_main_ppm( 3000, 1 ) ;		// Initial period 1.5 mS, output on
	//      break ;
  	  }
  	}

	// Set up output data here
		switch(s_current_protocol[0])
  	{
		  case PROTO_PPM:
  	    setupPulsesPpm();		// Don't enable interrupts through here
  	  break;
  		case PROTO_PXX:
  	    setupPulsesPXX(0);
  	  break;
	//	  case PROTO_DSM2:
	////      sei() ;							// Interrupts allowed here
	//      setupPulsesDsm2(6); 
	//    break;
	//  	case PROTO_PPM16 :
	//      setupPulsesPPM();		// Don't enable interrupts through here
	////      // PPM16 pulses are set up automatically within the interrupts
	////    break ;
  	}
	}
	else
	{
  	if ( s_current_protocol[1] != g_model.xprotocol )
  	{
  	  switch( s_current_protocol[1] )
  	  {	// stop existing protocol hardware
  	    case PROTO_PPM:
					disable_ppm(EXTERNAL_MODULE) ;
  	    break;
  	    case PROTO_PXX:
					disable_pxx(EXTERNAL_MODULE) ;
  	    break;
	      case PROTO_DSM2:
					disable_dsm2(EXTERNAL_MODULE) ;
	      break;
#ifdef ASSAN
	      case PROTO_ASSAN :
					disable_assan(EXTERNAL_MODULE) ;
	      break;
#endif
	//      case PROTO_PPM16 :
	//				disable_main_ppm() ;
	//      break ;
  	  }
		
  	  s_current_protocol[1] = g_model.xprotocol ;
  	  switch(s_current_protocol[1])
  	  { // Start new protocol hardware here
  	    case PROTO_PPM:
				  setupPulsesPpmx() ;
					init_ppm(EXTERNAL_MODULE) ;
  	    break;
  	    case PROTO_PXX:
					init_pxx(EXTERNAL_MODULE) ;
  	    break;
		    case PROTO_OFF:
					init_no_pulses( EXTERNAL_MODULE ) ;
  	  	break;
	      case PROTO_DSM2:
					init_dsm2(EXTERNAL_MODULE) ;
	      break;
#ifdef ASSAN
	      case PROTO_ASSAN :
					init_assan(EXTERNAL_MODULE) ;
	      break;
#endif
	//      case PROTO_PPM16 :
	//				init_main_ppm( 3000, 1 ) ;		// Initial period 1.5 mS, output on
	//      break ;
  	  }
  	}

	// Set up output data here
		switch(s_current_protocol[1])
  	{
		  case PROTO_PPM:
  	    setupPulsesPpmx();		// Don't enable interrupts through here
  	  break;
  		case PROTO_PXX:
  	    setupPulsesPXX(1);
  	  break;
		  case PROTO_DSM2:
	//      sei() ;							// Interrupts allowed here
	      setupPulsesDsm2(6); 
	    break;
#ifdef ASSAN
	    case PROTO_ASSAN :
	      setupPulsesDsm2(g_model.xppmNCH) ; 
	    break;
#endif
	//  	case PROTO_PPM16 :
	//      setupPulsesPPM();		// Don't enable interrupts through here
	////      // PPM16 pulses are set up automatically within the interrupts
	////    break ;
  	}
	}
}
コード例 #3
0
ファイル: mandelbrot.c プロジェクト: marwi509/TDDD56
void
init_mandelbrot(struct mandelbrot_param *param)
{
	// Initialize the picture container, but not its buffer
	param->picture = ppm_alloc(0, 0);
	param->picture->height = param->height;
	param->picture->width = param->width;

#if GLUT != 1
	// GLUT will do it when creating or resizing its window
	init_ppm(param);
#endif
	// initialize the color vector
	update_colors(param);

#if NB_THREADS > 0
	// Thread-based variant

	pthread_attr_t thread_attr;
	int i;

	// Initialise thread poll / master thread synchronisation
	pthread_barrier_init(&thread_pool_barrier, NULL, NB_THREADS + 1);
	pthread_barrier_init(&thread_para_barrier, NULL, NB_THREADS);

	// Initialize attributes
	pthread_attr_init(&thread_attr);
	pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_JOINABLE);

	// Enables thread running
	thread_stop = 0;

#ifdef MEASURE
	// Measuring record structures
	timing = malloc(sizeof(struct timing*) * NB_THREADS);
#endif

	// Create a thread pool
	for (i = 0; i < NB_THREADS; i++)
	{
		thread_data[i].id = i;

#ifdef MEASURE
		timing[i] = &thread_data[i].timing;
#endif

		// Check the good behavior or pthread_create; must be disabled while measuring for performance reasons
#ifdef DEBUG
		assert(pthread_create(&thread[i], &thread_attr, &run_thread, &thread_data[i]) == 0);
#else
		pthread_create(&thread[i], &thread_attr, &run_thread, &thread_data[i]);
#endif
	}

	// Wait for the thread to be fully spawned before returning
	pthread_barrier_wait(&thread_pool_barrier);
#else
#ifdef MEASURE
	// Measuring record structures
	timing = malloc(sizeof(struct timing*));
	timing[0] = &sequential;
#endif
#endif
}
コード例 #4
0
ファイル: ppm.c プロジェクト: lhhunghimself/week4
ppm* init_ppm_read(char filename, FILE *fp){
 ppm *p=init_ppm();
	read_ppm(p,filename,fp);
	return p;
}