Exemple #1
0
/*
 * use the de Casteljau algorithm to subdivide the Bezier curve divisions times,
 * then add the lines connecting the control points to the module.
 */
void module_bezierCurve(Module *m, BezierCurve *b, int divisions){
	Line tempLine;
	Point deCast[7];
	BezierCurve tempbez;
	if(!m || !b){
		printf("Null passed to module_bezierCurve\n");
		return;
	}
	
	// base case, add six lines to module
	if(divisions == 0){
		line_set(&tempLine, b->c[0], b->c[1]);
		module_line(m, &tempLine);
		line_set(&tempLine, b->c[1], b->c[2]);
		module_line(m, &tempLine);
		line_set(&tempLine, b->c[2], b->c[3]);
		module_line(m, &tempLine);
		return;
	}
	
	// compute all avg points for 3 orders, down to just one point 3rd order
	deCasteljau(&(deCast[0]), &(b->c[0]));
	// left half
	bezierCurve_set(&tempbez, &(deCast[0]));
	module_bezierCurve(m, &tempbez, divisions-1);
	// right half
	bezierCurve_set(&tempbez, &(deCast[3]));
	module_bezierCurve(m, &tempbez, divisions-1);
}
Exemple #2
0
int main( int argc, char ** argv )
{
	line_t * ptr;
	int sz;

	char * lines[3] = {
		"goober",
		"",
		"Looks like a real line.\n"
	};
	for(int i=0; i < 3; i++)
	{
		ptr = line_new();
		line_set(ptr , lines[i]);	
		sz = line_size( ptr );
		printf("ptr size: %d\n", sz );
		printf("ptr data: %s\n", line_get(ptr) );
		printf("ends in newline: %s\n", line_has_newline( ptr ) ? "Yes" : "No"  );	
		printf("null terminated: %s\n", line_null_terminated( ptr ) ? "Yes" : "No" );	
		line_free( ptr );
		printf("line after free is null? %s\n", ptr == NULL ? "Yes" : "No" );	
	}

	return 0;
}
static void __exit i2c_parport_exit(void)
{
    /* Un-init if needed (power off...) */
    if (adapter_parm[type].init.val)
        line_set(0, &adapter_parm[type].init);

    i2c_del_adapter(&parport_adapter);
    release_region(base, 3);
}
Exemple #4
0
static void i2c_parport_attach (struct parport *port)
{
	struct i2c_par *adapter;
	
	adapter = kmalloc(sizeof(struct i2c_par), GFP_KERNEL);
	if (adapter == NULL) {
		printk(KERN_ERR "i2c-parport: Failed to kmalloc\n");
		return;
	}
	memset(adapter, 0x00, sizeof(struct i2c_par));

	pr_debug("i2c-parport: attaching to %s\n", port->name);
	adapter->pdev = parport_register_device(port, "i2c-parport",
		NULL, NULL, NULL, PARPORT_FLAG_EXCL, NULL);
	if (!adapter->pdev) {
		printk(KERN_ERR "i2c-parport: Unable to register with parport\n");
		goto ERROR0;
	}

	/* Fill the rest of the structure */
	adapter->adapter = parport_adapter;
	adapter->algo_data = parport_algo_data;
	if (!adapter_parm[type].getscl.val)
		adapter->algo_data.getscl = NULL;
	adapter->algo_data.data = port;
	adapter->adapter.algo_data = &adapter->algo_data;

	if (parport_claim_or_block(adapter->pdev) < 0) {
		printk(KERN_ERR "i2c-parport: Could not claim parallel port\n");
		goto ERROR1;
	}

	/* Reset hardware to a sane state (SCL and SDA high) */
	parport_setsda(port, 1);
	parport_setscl(port, 1);
	/* Other init if needed (power on...) */
	if (adapter_parm[type].init.val)
		line_set(port, 1, &adapter_parm[type].init);

	parport_release(adapter->pdev);

	if (i2c_bit_add_bus(&adapter->adapter) < 0) {
		printk(KERN_ERR "i2c-parport: Unable to register with I2C\n");
		goto ERROR1;
	}

	/* Add the new adapter to the list */
	adapter->next = adapter_list;
	adapter_list = adapter;
        return;

ERROR1:
	parport_unregister_device(adapter->pdev);
ERROR0:
	kfree(adapter);
}
static int __devexit i2c_parport_remove(struct platform_device *pdev)
{
	i2c_del_adapter(&parport_adapter);

	/* Un-init if needed (power off...) */
	if (adapter_parm[type].init.val)
		line_set(0, &adapter_parm[type].init);

	return 0;
}
Exemple #6
0
static int __devexit i2c_parport_remove(struct platform_device *pdev)
{
	i2c_del_adapter(&parport_adapter);

	
	if (adapter_parm[type].init.val)
		line_set(0, &adapter_parm[type].init);

	return 0;
}
static int __devinit i2c_parport_probe(struct platform_device *pdev)
{
	int err;

	/* Reset hardware to a sane state (SCL and SDA high) */
	parport_setsda(NULL, 1);
	parport_setscl(NULL, 1);
	/* Other init if needed (power on...) */
	if (adapter_parm[type].init.val)
		line_set(1, &adapter_parm[type].init);

	parport_adapter.dev.parent = &pdev->dev;
	err = i2c_bit_add_bus(&parport_adapter);
	if (err)
		dev_err(&pdev->dev, "Unable to register with I2C\n");
	return err;
}
Exemple #8
0
static int __devinit i2c_parport_probe(struct platform_device *pdev)
{
	int err;

	
	parport_setsda(NULL, 1);
	parport_setscl(NULL, 1);
	
	if (adapter_parm[type].init.val)
		line_set(1, &adapter_parm[type].init);

	parport_adapter.dev.parent = &pdev->dev;
	err = i2c_bit_add_bus(&parport_adapter);
	if (err)
		dev_err(&pdev->dev, "Unable to register with I2C\n");
	return err;
}
static int __init i2c_parport_init(void)
{
    if (type < 0) {
        printk(KERN_WARNING "i2c-parport: adapter type unspecified\n");
        return -ENODEV;
    }

    if (type >= ARRAY_SIZE(adapter_parm)) {
        printk(KERN_WARNING "i2c-parport: invalid type (%d)\n", type);
        return -ENODEV;
    }

    if (base == 0) {
        printk(KERN_INFO "i2c-parport: using default base 0x%x\n", DEFAULT_BASE);
        base = DEFAULT_BASE;
    }

    if (!request_region(base, 3, "i2c-parport"))
        return -ENODEV;

    if (!adapter_parm[type].getscl.val)
        parport_algo_data.getscl = NULL;

    /* Reset hardware to a sane state (SCL and SDA high) */
    parport_setsda(NULL, 1);
    parport_setscl(NULL, 1);
    /* Other init if needed (power on...) */
    if (adapter_parm[type].init.val)
        line_set(1, &adapter_parm[type].init);

    if (i2c_bit_add_bus(&parport_adapter) < 0) {
        printk(KERN_ERR "i2c-parport: Unable to register with I2C\n");
        release_region(base, 3);
        return -ENODEV;
    }

    return 0;
}
Exemple #10
0
static void i2c_parport_detach (struct parport *port)
{
	struct i2c_par *adapter, *prev;

	/* Walk the list */
	for (prev = NULL, adapter = adapter_list; adapter;
	     prev = adapter, adapter = adapter->next) {
		if (adapter->pdev->port == port) {
			/* Un-init if needed (power off...) */
			if (adapter_parm[type].init.val)
				line_set(port, 0, &adapter_parm[type].init);
				
			i2c_bit_del_bus(&adapter->adapter);
			parport_unregister_device(adapter->pdev);
			if (prev)
				prev->next = adapter->next;
			else
				adapter_list = adapter->next;
			kfree(adapter);
			return;
		}
	}
}
Exemple #11
0
int main(void)
{ 
	PATTEN mode;
	
	System_Init();  
	read_books();
	delay_ms(5000);   
    mode = line_set();	//放书时间
	TIM_SetCompare1(TIM4,900);         //PWM脉冲占空比调节
    TIM_SetCompare2(TIM4,900);
	F_Straight();
	delay_ms(1500);
	
	if(mode==PATTEN1) move_1();
	else if(mode == PATTEN2) move_2();
	else              move_3(); 
	
	while(1){
	   GPIO_ResetBits(GPIOF,GPIO_Pin_9 | GPIO_Pin_10);
       delay_ms(500);
       GPIO_SetBits(GPIOF,GPIO_Pin_9 | GPIO_Pin_10);
	   delay_ms(500);
	}
}
Exemple #12
0
/*
* Sourced from coursework file test6b.c (Bruce Maxwell)
*/
void module_cone( Module *mod, int sides, int fill, int size, float x, float y, float z) {
	Polygon p;
	Point xtop, xbot;
	Element *e;
	Line l;
	double x1, x2, z1, z2;
	int i;

	if(!mod){
		printf("Null md passed to module_cylinder\n");
		return;
	}

	// set cone parameters
    module_scale(mod, (int)size, (int)size, (int)size);
	module_translate(mod, (float)x, (float)y, (float)z);
	printf("parameters set\n");

	polygon_init( &p );
	point_set3D( &xtop, 0, 1.0, 0.0 );
	point_set3D( &xbot, 0, 0.0, 0.0 );

	if (fill == 1){
		// make a fan for the top and bottom sides
		// and quadrilaterals for the sides
		for(i=0;i<sides;i++) {
			Point pt[6];

			x1 = cos( i * M_PI * 2.0 / sides );
			z1 = sin( i * M_PI * 2.0 / sides );
			x2 = cos( ( (i+1)%sides ) * M_PI * 2.0 / sides );
			z2 = sin( ( (i+1)%sides ) * M_PI * 2.0 / sides );

			point_copy( &pt[0], &xbot );
			point_set3D( &pt[1], x1, 0.0, z1 );
			point_set3D( &pt[2], x2, 0.0, z2 );

			polygon_set( &p, 3, pt );
			e = element_init(ObjPolygon, &p);
			module_insert(mod, e);

			point_set3D( &pt[3], x1, 0.0, z1 );
			point_set3D( &pt[4], x2, 0.0, z2 );
			point_copy( &pt[5], &xtop);

			polygon_set( &p, 3, &pt[3] );
			e = element_init(ObjPolygon, &p);
			module_insert(mod, e);
		}
	} else{
		// make a fan for the top and bottom sides
		// and quadrilaterals for the sides
		for(i=0;i<sides;i++) {
			Point pt[8];

			x1 = cos( i * M_PI * 2.0 / sides );
			z1 = sin( i * M_PI * 2.0 / sides );
			x2 = cos( ( (i+1)%sides ) * M_PI * 2.0 / sides );
			z2 = sin( ( (i+1)%sides ) * M_PI * 2.0 / sides );

			point_copy( &pt[0], &xbot );
			point_set3D( &pt[1], x1, 0.0, z1 );
			point_set3D( &pt[2], x2, 0.0, z2 );

			line_set( &l, pt[0], pt[1] );
			e = element_init(ObjLine, &l);
			module_insert(mod, e);
			line_set( &l, pt[1], pt[2] );
			e = element_init(ObjLine, &l);
			module_insert(mod, e);
			line_set( &l, pt[2], pt[0]);
			e = element_init(ObjLine, &l);
			module_insert(mod, e);

			point_set3D( &pt[3], x1, 0.0, z1 );
			point_set3D( &pt[4], x2, 0.0, z2 );
			point_set3D( &pt[5], x2, 1.0, z2 );
			point_set3D( &pt[6], x1, 1.0, z1 );
			point_copy( &pt[7], &xtop);

			line_set( &l, pt[0], pt[7] );
			e = element_init(ObjLine, &l);
			module_insert(mod, e);
			line_set( &l, pt[1], pt[7] );
			e = element_init(ObjLine, &l);
			module_insert(mod, e);
			line_set( &l, pt[2], pt[7]);
			e = element_init(ObjLine, &l);
			module_insert(mod, e);
			line_set( &l, pt[3], pt[7]);
			e = element_init(ObjLine, &l);
			module_insert(mod, e);
		}
	}
	polygon_clear( &p );
}
Exemple #13
0
static void parport_setscl(void *data, int state)
{
	line_set((struct parport *) data, state, &adapter_parm[type].setscl);
}
Exemple #14
0
int
gen_setup()
{
	extern char *v_yes[];
	WINDOW *g_win, *newwin();
	int i, num, ret_code;
	char c, *ans, *str_prompt(), *menu_prompt(), chr_prompt();
	char *str_rep();
	void line_set();
	static char *v_abort[3] = {"KEEP", "DELETE", NULL};

	g_win = newwin(23, 80, 0, 0);

	horizontal(g_win, 0, 0, 32);
	mvwattrstr(g_win, 0, 33, A_BOLD, "General Setup");
	horizontal(g_win, 0, 47, 32);
	mvwprintw(g_win, 3, 22, "1) Default log file ....... %s", param->logfile);
	mvwprintw(g_win, 4, 22, "2) Screen dump file ....... %s", param->dumpfile);
	mvwprintw(g_win, 6, 22, "3) Strip high bit  ........ %s", param->strip);
	mvwprintw(g_win, 8, 22, "4) Pause character ........ %c", param->pause_char);
	mvwprintw(g_win, 9, 22, "5) CR character ........... %c", param->cr_char);
	mvwprintw(g_win, 10, 22, "6) CTRL character ......... %c", param->ctrl_char);
	mvwprintw(g_win, 11, 22, "7) ESC character .......... %c", param->esc_char);
	mvwprintw(g_win, 12, 22, "8) Break character ........ %c", param->brk_char);
	mvwprintw(g_win, 14, 22, "9) Aborted downloads ...... %s", param->abort);
	mvwprintw(g_win, 16, 21, "10) Connect delay (sec) .... %d", param->c_delay);
	mvwprintw(g_win, 17, 21, "11) Redial delay (sec) ..... %d", param->r_delay);
	horizontal(g_win, 19, 0, 80);
	mvwattrstr(g_win, 20, 0, A_BOLD, "OPTION ==> ");
	mvwaddstr(g_win, 20, 58, "Press <ESC> to return");
	wmove(g_win, 20, 12);
	touchwin(g_win);
	wrefresh(g_win);
					/* get the option number */
	ret_code = 0;
	while ((i = get_num(g_win, 2)) != -1) {
		switch (i) {
			case 1:
				if ((ans = str_prompt(g_win, 3, 50, "Default log file", "")) != NULL) {
					param->logfile = str_rep(param->logfile, ans);
					ret_code++;
				}
				break;
			case 2:
				if ((ans = str_prompt(g_win, 4, 50, "Default screen dump file", "")) != NULL) {
					param->dumpfile = str_rep(param->dumpfile, ans);
					ret_code++;
				}
				break;
			case 3:
				if ((ans = menu_prompt(g_win, 6, 50, "Strip high bit?", v_yes)) != NULL) {
					param->strip = str_rep(param->strip, ans);
					line_set();
					ret_code++;
				}
				break;
			case 4:
				if ((c = chr_prompt(g_win, 8, 50, "Pause character", "1 second")) != '\0') {
					param->pause_char = c;
					ret_code++;
				}
				break;
			case 5:
				if ((c = chr_prompt(g_win, 9, 50, "CR character", "(carriage return)")) != '\0') {
					param->cr_char = c;
					ret_code++;
				}
				break;
			case 6:
				if ((c = chr_prompt(g_win, 10, 50, "CTRL character", "(control)")) != '\0') {
					param->ctrl_char = c;
					ret_code++;
				}
				break;
			case 7:
				if ((c = chr_prompt(g_win, 11, 50, "ESC character", "(escape)")) != '\0') {
					param->esc_char = c;
					ret_code++;
				}
				break;
			case 8:
				if ((c = chr_prompt(g_win, 12, 50, "Break character", "")) != '\0') {
					param->brk_char = c;
					ret_code++;
				}
			case 9:
				if ((ans = menu_prompt(g_win, 14, 50, "Aborted downloads", v_abort)) != NULL) {
					param->abort = str_rep(param->abort, ans);
					ret_code++;
				}
				break;
			case 10:
				if ((num = num_prompt(g_win, 16, 50, "Connect delay time", "(in seconds)")) != -1) {
					if (num > MAX_CDELAY || num < MIN_CDELAY) {
						beep();
					/* some reasonable range of values */
						if (num < MIN_CDELAY)
							num = MIN_CDELAY;
						else
							num = MAX_CDELAY;
						mvwaddstr(g_win, 16, 50, "   ");
						wrefresh(g_win);
						mvwattrnum(g_win, 16, 50, A_BOLD, num);
						wrefresh(g_win);
					}
					param->c_delay = num;
					ret_code++;
				}
				break;
			case 11:
				if ((num = num_prompt(g_win, 17, 50, "Redial delay time", "(in seconds)")) != -1) {
					if (num > MAX_PAUSE || num < MIN_PAUSE) {
						beep();
					/* some reasonable range */
						if (num < MIN_PAUSE)
							num = MIN_PAUSE;
						else
							num = MAX_PAUSE;
						mvwaddstr(g_win, 17, 50, "    ");
						wrefresh(g_win);
						mvwattrnum(g_win, 17, 50, A_BOLD, num);
						wrefresh(g_win);
					}
					param->r_delay = num;
					ret_code++;
				}
				break;
			default:
				beep();
		}
		mvwaddstr(g_win, 20, 12, "  ");
		clear_line(g_win, 21, 0, FALSE);
		clear_line(g_win, 22, 0, FALSE);
		wmove(g_win, 20, 12);
		wrefresh(g_win);
	}
	delwin(g_win);
	return(ret_code);
}
Exemple #15
0
// makes 3 X-wing fighters in a loose formation
int main(int argc, char *argv[]) {
  int i, j; //loop variables

  Image *src;
  Module* wall;
  Module* ray;
  Module* ray2;
  Module *scene1;
  Module* scene2;
  Polygon p;
  Line l;
  Point point[4];
  Point point2[2];
  View3D view;
  Matrix vtm, gtm;
  DrawState *ds;
  char filename[100];
  Color Flame = { { 1.0, 0.7, 0.2 } };
  Color Red =  { { 1.0, 0.2, 0.1 } };
  Color Grey =  { { 0.745, 0.745, 0.745} };
  Color Blue = {{0.117647, 0.564706, 1}};
  // Color Grey = {{1, 1, 1}};


  // set up the view
  point_set3D( &(view.vrp), 4, 4, 4 );
  vector_set( &(view.vpn), -view.vrp.val[0], -view.vrp.val[1], -view.vrp.val[2] );
  vector_set( &(view.vup), 0, 1, 0 );

  view.d = 1;
  view.du = 1.6;
  view.dv = 0.9;
  view.f = 1;
  view.b = 50;
  view.screenx = 640;
  view.screeny = 360;

  matrix_setView3D( &vtm, &view );
  matrix_identity( &gtm );

  // //wall
  wall = module_create();
  module_color(wall, &Red);
  polygon_init(&p);
  point_set3D(&point[0], 1,1,2);
  point_set3D(&point[1], 1,0,2);
  point_set3D(&point[2], 0,0,2);
  point_set3D(&point[3], 0,1,2);
  polygon_set(&p, 4, &point[0]);
  module_polygon(wall, &p);

//ray
  ray = module_create();
  module_color(ray, &Blue);
  for(i=0; i< 5; i++){
  point_set3D(&point2[0], -1+0.01*i, -1, 1);
  point_set3D(&point2[1], 1+0.01*i, 1, 1);
  line_set(&l, point2[0], point2[1]);
  module_line(ray, &l);
 }

 //ray2

  ray2 = module_create();
  module_color(ray2, &Red);
  for(i=0; i< 5; i++){
  point_set3D(&point2[0], -1+0.01*i, 1, -1);
  point_set3D(&point2[1], 1+0.01*i, -1, -1);
  line_set(&l, point2[0], point2[1]);
  // line_zBuffer(&l, 0);
  module_line(ray2, &l);
 }



//scene
    // scene = module_create();
    // module_module(scene, wall);
    // module_module(scene, ray);
    // module_module(scene, ray2);
    // module_module(scene, wall);
    



    

for(i=0; i< 36; i++){

	//scene
    scene1 = module_create();
    scene2 = module_create();
    module_rotateZ(scene1, cos(i*10 * M_PI/180), sin(i*10 * M_PI/180));
    module_scale( scene1, 3, 1, 2 );
    module_color( scene1, &Blue );
    module_cube( scene1, 1);


    module_scale(scene2, 0.5, 0.5, 0.5);
    module_cylinder(scene2, 30);
	// create the image and drawstate
	src = image_create( 360, 640 );
	ds = drawstate_create();
  drawstate_setAlpha(ds, 1);
	ds->shade = ShadeDepth;

	// draw into the scene
  // module_draw( scene1, &vtm, &gtm, ds, src );
  drawstate_setAlpha(ds, 1 );
	module_draw( scene1, &vtm, &gtm, ds, src );

	// write out the scene
	sprintf(filename, "frame_%.2d.ppm", i);
	image_write( src, filename );
	module_delete( scene1);

}
	 


	//free the polygon data
	// polygon_clear( &p );

	// free the modules
	// module_delete( scene);
	// module_delete( wall );


	// free the drawstate
	free(ds);

	// free the image
	image_free( src );

	return(0);
}
Exemple #16
0
int main( int argc, char *argv[]){
  //set up the images
  Image *src; 
  Image *myImage;

  //set up the modules!!
  Module *basket;

  Module *connector;
  Module *connector1;
  Line l;
  Point pts[2];

  Module *circle;
  Module *hotAirBalloon;
  Module *teamOfBalloons; 
  Module *scene; 

  //pick the colors
  Color colors[6]; 
  Color brown;
  Color blue;
  Color green;
  Color grey; 

  //set up view stuff, and image file stuff
  Matrix vtm, gtm; 
  int rows; 
  int cols; 
  View3D view; 
  DrawState *ds;
  char filename[256];

  int i, j, k, m, n; 

  //Set the colors up
  color_set(&brown, 0.2, 0.1, 0.0);
  color_set(&blue, 0.6, 0.8, 1.0);
  color_set(&green, 0.1, 0.4, 0.0);
  color_set(&grey, 0.3, 0.3, 0.3);
  color_set(&colors[0], 1.0, 0.0, 0.0);//Red
  color_set(&colors[1],1.0, 0.5, 0.0);//orange
  color_set(&colors[2],1.0, 1.0, 0.1);//yellow
  color_set(&colors[3], 0.0, 1.0, 0.0);//green
  color_set(&colors[4], 0.0, 0.0, 1.0);//blue
  color_set(&colors[5], 0.4, 0.0, 0.8);//purple
  
  //if you want to supply a background image you can, otherwise I set a default sky blue background!
  if(argc>1){
    printf("you supplied an image\n");
    myImage = image_read(argv[1]);
    rows = myImage->rows;
    cols = myImage->cols;
    printf("%d %d\n", rows, cols);
  }else{
    printf("We are giving your image a default size!\n");
    rows = 500;
    cols = 500;
    myImage = image_create(rows, cols); 
    for(m = 0; m< rows; m++){
      for(n = 0; n<cols; n++){
	image_setColor(myImage, m, n, blue);
      }
    }
  }

  //Loop over the scene 300 times moving the scene around!! 
  for(k = 0; k<300; k++){
    //Set up the view
    point_set( &(view.vrp), 150, 100, 200, 1.0);
    vector_set( &(view.vpn), -view.vrp.val[0], -view.vrp.val[1], -view.vrp.val[2]);
    vector_set( &(view.vup), 0, 1.0, 0);
    view.d = 20; 
    view.du = 10; 
    view.dv = view.du* (float)rows/cols;
    view.f = 0; 
    view.b = 5; 
    view.screenx = rows; 
    view.screeny = cols; 

    matrix_setView3D( &vtm, &view); 
    matrix_identity( &gtm ); 

    // basket: cube (will need 1 in hot air balloon module)
    basket = module_create(); 
    module_color(basket, &brown);
    module_cube(basket, 1); 

    //connectors: lines need 4
    connector = module_create();
    point_set3D(&pts[0],1,1,1 );
    point_set3D(&pts[1],2,4.2,1);
    line_set(&l, pts[0], pts[1]);
    module_line(connector, &l);

    connector1 = module_create();
    point_set3D(&pts[0], 1,1 , 1);
    point_set3D(&pts[1], 0,4.2 ,1 );
    line_set(&l, pts[0], pts[1]);
    module_line(connector1, &l);

    // balloon: circles nested on top of eachother 
    circle = module_create();
    module_color(circle, &colors[0]);
    module_rotateX(circle, 0, 1);
    module_translate2D(circle, 0, 3);
    module_circle(circle, 1);

    module_color(circle, &colors[1]);
    module_rotateX(circle, 1, 0);
    module_translate2D(circle, 0, 1);
    module_circle(circle, 2.5);

    module_color(circle, &colors[2]);
    module_rotateX(circle, 1, 0);
    module_translate2D(circle, 0, 1);
    module_circle(circle, 3);

    module_color(circle, &colors[3]);
    module_rotateX(circle, 1, 0);
    module_translate2D(circle, 0, 1);
    module_circle(circle, 4);

    module_color(circle, &colors[4]);
    module_rotateX(circle, 1, 0);
    module_translate2D(circle, 0, 1);
    module_circle(circle, 5);

    module_color(circle, &colors[5]);
    module_rotateX(circle, 1, 0);
    module_translate2D(circle, 0, 1);
    module_circle(circle, 6);

    module_color(circle, &colors[0]);
    module_rotateX(circle, 1,0);
    module_translate2D(circle, 0, 1);
    module_circle(circle, 7);

    module_color(circle, &colors[1]);
    module_rotateX(circle, 1, 0);
    module_translate2D(circle, 0, 1);
    module_circle(circle, 7);

    module_color(circle, &colors[2]);
    module_rotateX(circle, 1, 0);
    module_translate2D(circle, 0,1);
    module_circle(circle, 7);

    module_color(circle, &colors[3]);
    module_rotateX(circle, 1, 0);
    module_translate2D(circle, 0, 1);
    module_circle(circle, 7);

    module_color(circle, &colors[4]);
    module_rotateX(circle, 1, 0);
    module_translate2D(circle, 0, 1);
    module_circle(circle, 6);

    module_color(circle, &colors[5]);
    module_rotateX(circle, 1, 0);
    module_translate2D(circle, 0, 1);
    module_circle(circle, 5);

    module_color(circle, &colors[0]);
    module_rotateX(circle, 1, 0);
    module_translate2D(circle, 0, 1);
    module_circle(circle, 4);

    module_color(circle, &colors[1]);
    module_rotateX(circle, 1, 0);
    module_translate2D(circle, 0, 0.5);
    module_circle(circle, 3);

    module_color(circle, &colors[2]);
    module_rotateX(circle, 1, 0);
    module_translate2D(circle, 0, 0.5);
    module_circle(circle, 2);

    //hotAirBalloon: put the above parts together
    hotAirBalloon = module_create();
    module_module(hotAirBalloon, basket);
    module_module(hotAirBalloon, connector);
    module_translate(hotAirBalloon, -2,0 ,0 );
    module_module(hotAirBalloon, connector1);
    module_translate(hotAirBalloon, 0, 0, -2);
    module_module(hotAirBalloon, connector1);
    module_translate(hotAirBalloon, 2, 0, 0);
    module_module(hotAirBalloon, connector);
    module_module(hotAirBalloon, circle);


    //make a team of balloons
    teamOfBalloons = module_create();
    module_translate(teamOfBalloons, 0,-30,-15);
    module_module(teamOfBalloons, hotAirBalloon);
    module_translate(teamOfBalloons, 0, 0+(k*0.1),15);
    module_module(teamOfBalloons, hotAirBalloon);
    module_translate(teamOfBalloons, 0, 0+(k*0.1),15);
    module_module(teamOfBalloons, hotAirBalloon);


    //make a scene of balloons
    scene = module_create(); 
    module_translate(scene, -40, 10+(k*0.1), 10);
    module_module(scene, teamOfBalloons);
    module_translate(scene, 140, 10, 55);
    module_module(scene, teamOfBalloons);
    module_translate(scene, -50, 10+(k*0.1), -40);
    module_module(scene, teamOfBalloons);
    module_translate(scene, 30, 10+(k*0.2) , -55);
    module_module(scene, teamOfBalloons);

    //set up the image
    src = image_create(rows, cols); 

    //Either draw the background image you supplied or use my default background
    for (i = 0; i<rows; i++){
      for (j = 0; j<cols; j++){
	  blue = image_getColor(myImage, i, j);
	  image_setColor(src,i, j, blue);
      }
    }

    //set up the draw state if you want filled polygons need to use ShadeConstant instead of ShadeFrame
    ds = drawstate_create();
    ds->shade = ShadeFrame; 

    //draw the modules!
    module_draw( scene, &vtm, &gtm, ds, NULL, src); 

    //put the files in the right place with the right name!! 
    sprintf(filename, "/export/home/vedwards/Desktop/Graphics/images/hotAirBalloons3/frame-%04d.ppm", k );
    printf("Writing image\n");
    image_write( src, filename );
  }

  //Clean up, delete all of the modules, images, and drawState
  module_delete(basket);
  module_delete(connector);
  module_delete(connector1);
  module_delete(circle);
  module_delete(hotAirBalloon);
  module_delete(teamOfBalloons);

  free(ds);
  image_free( src );
  image_free( myImage );
  return(0);
}
Exemple #17
0
static void test_term_line_ops(void) {
        term_line *l;
        term_attr attr_regular = { };
        term_attr attr_bold = { .bold = true };
        term_attr attr_italic = { .italic = true };

        assert_se(term_line_new(&l) >= 0);
        line_resize(l, 8, NULL, 0);
        assert_se(l->n_cells == 8);

        LINE_ASSERT(l, "| | | | | | | | |", 0);

        term_line_write(l, 4, TERM_CHAR_NULL, 0, NULL, TERM_AGE_NULL, 0);
        LINE_ASSERT(l, "| | | | | | | | |", 5);

        term_line_write(l, 1, PACK1('A'), 1, NULL, TERM_AGE_NULL, 0);
        LINE_ASSERT(l, "| |A| | | | | | |", 5);

        term_line_write(l, 8, PACK2('A', 'B'), 1, NULL, TERM_AGE_NULL, 0);
        LINE_ASSERT(l, "| |A| | | | | | |", 5);

        term_line_write(l, 7, PACK2('A', 'B'), 1, &attr_regular, 10, 0);
        LINE_ASSERT(l, "| |A| | | | | | 10 AB |", 8);

        term_line_write(l, 7, PACK2('A', 'B'), 1, &attr_bold, 10, 0);
        LINE_ASSERT(l, "| |A| | | | | | 10 *AB* |", 8);

        term_line_reset(l, NULL, TERM_AGE_NULL);

        LINE_ASSERT(l, "|   |   |          |          |          |   |   |   |", 0);
        line_set(l, 2, "*wxyz* 8", 0);
        line_set(l, 3, "/wxyz/ 8", 0);
        LINE_ASSERT(l, "|   |   | *wxyz* 8 | /wxyz/ 8 |          |   |   |   |", 4);
        line_set(l, 2, "*abc* 9", true);
        LINE_ASSERT(l, "|   |   | *abc* 9  | *wxyz* 9 | /wxyz/ 9 | 9 | 9 | 9 |", 5);
        line_set(l, 7, "*abc* 10", true);
        LINE_ASSERT(l, "|   |   | *abc* 9  | *wxyz* 9 | /wxyz/ 9 | 9 | 9 | *abc* 10 |", 8);

        term_line_erase(l, 6, 1, NULL, 11, 0);
        LINE_ASSERT(l, "|   |   | *abc* 9  | *wxyz* 9 | /wxyz/ 9 | 9 | 11 | *abc* 10 |", 8);
        term_line_erase(l, 6, 2, &attr_italic, 12, 0);
        LINE_ASSERT(l, "|   |   | *abc* 9  | *wxyz* 9 | /wxyz/ 9 | 9 | 12 // | 12 // |", 6);
        term_line_erase(l, 7, 2, &attr_regular, 13, 0);
        LINE_ASSERT(l, "|   |   | *abc* 9  | *wxyz* 9 | /wxyz/ 9 | 9 | 12 // | 13 |", 6);
        term_line_delete(l, 1, 3, &attr_bold, 14);
        LINE_ASSERT(l, "|   | /wxyz/ 14 | 14 | 14 // | 14 | 14 ** | 14 ** | 14 ** |", 3);
        term_line_insert(l, 2, 2, &attr_regular, 15);
        LINE_ASSERT(l, "|   | /wxyz/ 14 | 15 | 15 | 15 | 15 // | 15 | 15 ** |", 5);

        assert_se(!term_line_free(l));
}

int main(int argc, char *argv[]) {
        test_term_char_misc();
        test_term_char_packing();
        test_term_char_allocating();

        test_term_line_misc();
        test_term_line_ops();

        return 0;
}
Exemple #18
0
/*
 * insert a pyramid into the module
 */
void module_pyramid(Module *md, int solid, float size, float x, float y, float z){

	if(!md){
		printf("Null md passed to module_pyramid\n");
		return;
	}
	Polygon side;
	Point tv[3];
    Point v[5];
    Line l;
    Element *e;
    int i;

    polygon_init(&side);

    // corners of the pyramid
    point_set3D(&v[0], -1, -1, -1 );
    point_set3D(&v[1],  1, -1, -1 );
    point_set3D(&v[2],  1,  -1, 1 );
    point_set3D(&v[3], -1,  -1, 1 );
    point_set3D(&v[4], 0, 0, 0);
    //printf("points created\n");

    // set pyramid parameters
    module_scale(md, (int)size, (int)size, (int)size);
	module_translate(md, (float)x, (float)y, (float)z);
	//printf("parameters set\n");

    if (solid == 0){
    	// add only lines
    	// foundation
		for(i=0;i<3;i++){
			line_set( &l, v[i], v[i+1] );
			e = element_init(ObjLine, &l);
			module_insert(md, e);
		}
		line_set( &l, v[3], v[0] );
		e = element_init(ObjLine, &l);
		module_insert(md, e);
		
		// connecting lines
		line_set( &l, v[4], v[0] );
		e = element_init(ObjLine, &l);
		module_insert(md, e);
		line_set( &l, v[1], v[4] );
		e = element_init(ObjLine, &l);
		module_insert(md, e);
		line_set( &l, v[2], v[4] );
		e = element_init(ObjLine, &l);
		module_insert(md, e);
		line_set( &l, v[3], v[4] );
		e = element_init(ObjLine, &l);
		module_insert(md, e);

		//printf("successfully passed to module\n");
    } else{

    	// front side
	    point_copy(&tv[0], &v[0]);
	    point_copy(&tv[1], &v[1]);
	    point_copy(&tv[2], &v[4]);
	    polygon_set(&side, 3, tv);
	    e = element_init(ObjPolygon, &side);
		module_insert(md, e);

	    // back side
	    point_copy(&tv[0], &v[3]);
	    point_copy(&tv[1], &v[2]);
	    point_copy(&tv[2], &v[4]);
	    polygon_set(&side, 3, tv);
	    e = element_init(ObjPolygon, &side);
		module_insert(md, e);

	    // bottom side
	    polygon_set(&side, 4, &(v[0]));
	    e = element_init(ObjPolygon, &side);
		module_insert(md, e);

	    // left side
	    point_copy(&tv[0], &v[0]);
	    point_copy(&tv[1], &v[3]);
	    point_copy(&tv[2], &v[4]);
	    polygon_set(&side, 3, tv);
	    e = element_init(ObjPolygon, &side);
		module_insert(md, e);

	    // right side
	    point_copy(&tv[0], &v[1]);
	    point_copy(&tv[1], &v[2]);
	    point_copy(&tv[2], &v[4]);
	    polygon_set(&side, 3, tv); 
		e = element_init(ObjPolygon, &side);
		module_insert(md, e);

		//printf("successfully passed to module\n");
    }

    polygon_clear(&side);
}
Exemple #19
0
/*
 * Adds a unit cube, axis-aligned and centered on zero to the Module. 
 * If solid is zero, add only lines. If solid is non-zero, use polygons. 
 * Make sure each polygon has surface normals defined for it.
 */
void module_cube(Module *md, int solid){
	if(!md){
		printf("Null md passed to module_cube\n");
		return;
	}
	Element *e;
 	Polygon p;
	Point v[8];
	Point tv[4];
	Line l;
	int i;
	
	// initialize polygon
	polygon_init( &p );
  
	// corners of a cube, centered at (0, 0, 0)
	point_set3D( &v[0], -0.5, -0.5, -0.5 );
	point_set3D( &v[1],  0.5, -0.5, -0.5 );
	point_set3D( &v[2],  0.5,  0.5, -0.5 );
	point_set3D( &v[3], -0.5,  0.5, -0.5 );
	point_set3D( &v[4], -0.5, -0.5,  0.5 );
	point_set3D( &v[5],  0.5, -0.5,  0.5 );
	point_set3D( &v[6],  0.5,  0.5,  0.5 );
	point_set3D( &v[7], -0.5,  0.5,  0.5 );
		
	if(solid == 0){
		// add only lines ( 12 of them )
		
		// front face lines
		for(i=0;i<3;i++){
			line_set( &l, v[i], v[i+1] );
			e = element_init(ObjLine, &l);
			module_insert(md, e);
		}
		line_set( &l, v[3], v[0] );
		e = element_init(ObjLine, &l);
		module_insert(md, e);
		
		// back face lines
		for(i=4;i<7;i++){
			line_set( &l, v[i], v[i+1] );
			e = element_init(ObjLine, &l);
			module_insert(md, e);
		}
		line_set( &l, v[7], v[4] );
		e = element_init(ObjLine, &l);
		module_insert(md, e);
		
		// connecting lines
		line_set( &l, v[2], v[6] );
		e = element_init(ObjLine, &l);
		module_insert(md, e);
		line_set( &l, v[3], v[7] );
		e = element_init(ObjLine, &l);
		module_insert(md, e);
		line_set( &l, v[0], v[4] );
		e = element_init(ObjLine, &l);
		module_insert(md, e);
		line_set( &l, v[1], v[5] );
		e = element_init(ObjLine, &l);
		module_insert(md, e);
	}
	else{
	 	// use polygons ( 6 of them )
		// front side
		polygon_set( &p, 4, &(v[0]) );
		e = element_init(ObjPolygon, &p);
		module_insert(md, e);

		// back side
		polygon_set( &p, 4, &(v[4]) );
		e = element_init(ObjPolygon, &p);
		module_insert(md, e);

		// top side
		point_copy( &tv[0], &v[2] );
		point_copy( &tv[1], &v[3] );
		point_copy( &tv[2], &v[7] );
		point_copy( &tv[3], &v[6] );

		polygon_set( &p, 4, tv );
		e = element_init(ObjPolygon, &p);
		module_insert(md, e);

		// bottom side
		point_copy( &tv[0], &v[0] );
		point_copy( &tv[1], &v[1] );
		point_copy( &tv[2], &v[5] );
		point_copy( &tv[3], &v[4] );

		polygon_set( &p, 4, tv );
		e = element_init(ObjPolygon, &p);
		module_insert(md, e);

		// left side
		point_copy( &tv[0], &v[0] );
		point_copy( &tv[1], &v[3] );
		point_copy( &tv[2], &v[7] );
		point_copy( &tv[3], &v[4] );

		polygon_set( &p, 4, tv );
		e = element_init(ObjPolygon, &p);
		module_insert(md, e);

		// right side
		point_copy( &tv[0], &v[1] );
		point_copy( &tv[1], &v[2] );
		point_copy( &tv[2], &v[6] );
		point_copy( &tv[3], &v[5] );

		polygon_set( &p, 4, tv );
		e = element_init(ObjPolygon, &p);
		module_insert(md, e);
	}
	
	// clean up
	polygon_clear(&p);
}
Exemple #20
0
/*
 * use the de Casteljau algorithm to subdivide the Bezier surface divisions times,
 * then draw either the lines connecting the control points, if solid is 0, 
 * or draw triangles connecting the surface.
 */
void module_bezierSurface(Module *m, BezierSurface *b, int divisions, int solid){
	int i, j, k, l;
	Line tempLine;
	Point grid[7][7];
	Point controls[7];
	Point deCast[7];
	Point surfacePoints[16];
	BezierSurface tempBezSurf;
	Polygon *temptri = polygon_create();
	if(!m || !b){
		printf("Null passed to module_bezierSurface\n");
		return;
	}
	
	// base case
	if(divisions == 0){
		// lines
		if(solid == 0){
			for(i=0;i<4;i++){
				for(j=0;j<3;j++){
					line_set(&tempLine, b->c[i][j], b->c[i][j+1]);
					module_line(m, &tempLine);
					line_set(&tempLine, b->c[j][i], b->c[j+1][i]);
					module_line(m, &tempLine);
				}
			}
		} 
		// triangles
		else {
			controls[0] = b->c[0][0];
			controls[1] = b->c[0][3];
			controls[2] = b->c[3][3];
			controls[3] = b->c[3][0];
			controls[4] = b->c[0][0];
			polygon_set(temptri, 3, &(controls[0]));
			module_polygon(m, temptri);
			polygon_set(temptri, 3, &(controls[2]));
			module_polygon(m, temptri);
		}
	}
	
	// divide and recurse
	else {

		// compute all avg points for 3 orders, down to just one point 3rd order
		// do for each of the four bezier curves
		for(i=0;i<4;i++){
			deCasteljau(&(deCast[0]), &(b->c[i][0]));
			for(j=0;j<7;j++){
				grid[2*i][j] = deCast[j];
			}
		}

		// now traverse the other direction, populating grid
		for(i=0;i<7;i++){
			for(j=0;j<4;j++){
				controls[j] = grid[2*j][i];
			}
			deCasteljau(&(deCast[0]), &(controls[0]));
			for(j=0;j<7;j++){
				grid[j][i] = deCast[j];
			}
		}

		// now make the four new bezier surfaces by subdividing across
		for(i=0;i<2;i++){
			for(j=0;j<2;j++){
				for(k=0;k<4;k++){
					for(l=0;l<4;l++){
						surfacePoints[4*k+l] = grid[k+3*i][l+3*j];
					}
				}
				bezierSurface_set(&tempBezSurf, &(surfacePoints[0]));
				// recursive call
				module_bezierSurface(m, &tempBezSurf, divisions-1, solid);
			}
		}
	}
	
	// clean up
	polygon_free(temptri);
}
static void parport_setsda(void *data, int state)
{
	line_set(state, &adapter_parm[type].setsda);
}
Exemple #22
0
int main(int argc, char *argv[]) {
  Point start[NUMLINES], end[NUMLINES];
  Color color[NUMLINES];
  Image *src;
  Line line;
  long i,j;
  Color white;
  double tstart, tend;
  long numLines;
  double sum, dx, dy;
  struct timeb tp;

  color_set( &white, 1.0, 1.0, 1.0);

  // allocate an image ROWS by COLS
  src = image_create(ROWS, COLS);
  if(!src) {
    fprintf(stderr, "unable to allocate memory\n");
    exit(0);
  }

  // Initialize the image to all white
  for(i=0;i<src->rows;i++) {
    for(j=0;j<src->cols;j++) {
      image_setColor(src, i, j, white );
    }
  }

  // Pre-calculate the line endpoints and colors so we don't have to
  // call the random() function inside the main drawing loop.
  sum = 0.0;
  for(i=0;i<NUMLINES;i++) {
    int tsx, tsy, tex, tey;
    tsx = (int)(drand48() * COLS);
    tsy = (int)(drand48() * ROWS);
    tex = (int)(drand48() * COLS);
    tey = (int)(drand48() * ROWS);
    point_set2D(&(start[i]), tsx, tsy );
    point_set2D(&(end[i]), tex, tey );
    color[i].c[0] = drand48();
    color[i].c[1] = drand48();
    color[i].c[2] = drand48();

    dx = tsx - tex;
    dy = tsy - tey;
    sum += sqrt(dx * dx + dy * dy);
  }
  sum /= NUMLINES;
  printf("Average line length = %.1lf\n", sum);

  // Start drawing lines
  ftime( &tp );
  tstart = tp.time + tp.millitm / 1000.0;

  for(i=0,numLines=0; numLines < 5000000;numLines++, i++) {
    i = i % NUMLINES;
    line_set(&line, start[i], end[i]);
    line_draw(&line, src, color[i]);
  }

  ftime( &tp );
  tend = tp.time + tp.millitm / 1000.0;

  // print out the result
  printf("%.2lf lines per second\n", numLines / (tend - tstart) );

  // write out the image
  image_write(src, "lines.ppm");

  // free the image data
  image_free(src);

  return(0);
}