Previous Next Up Title Contents General Index Functions Index Bookshelf

1.7.5. TRACÉ D'UN CERCLE ET 2 AXES LINÉAIRES, ET CRÉATION D'UN FICHIER POSTSCRIPT

#include <phigure.h>
main () {
	Pfloat zoom=0.8, circle_radius = 5.0;
	Pint ws_id = 1, PostScript_id = 2, view_ind = 1,
	scene_id = 10, circle_id = 11, x_axis_id=12, y_axis_id=13;
	Tcircle circle;
	static Plimit viewport = {0.,1., 0., 1.}, domain = {10., 20., 10., 20. };
	static Ppoint circle_center = {15., 15.}, view_center = {0.5, 0.5};
	static Ppoint3 axis_orig = {10.0,10.0,0.0};
	static Pint struct_ids[3];
	static Pint_list struct_id_list = {3, struct_ids};

/* ouverture de PHIGURE et d'un poste de travail de type X-Window (8887) */
	topen_phigure (PDEF_ERR_FILE);
	topen_ws (ws_id, PDEF_ERR_FILE, 8887);

/* définition du domaine */
	tdomain (&domain);

/* construction d'un cercle */
	circle.type = TCENTER_RADIUS;
	circle.geometry.cr.r = circle_radius;
	circle.geometry.cr.c = circle_center;
	tcircle (circle_id, &circle);

/* attribut label pour l'axe X */
	tset_axis_label (x_axis_id, TVISIBILITY_ON, TLABEL_AT_END, TPATH_RIGHT, 0.0, "X-axis");

/* construction des 2 axes */
	txy_linear_axis (x_axis_id, &axis_orig, 20.0, 0.0);
	tyx_linear_axis (y_axis_id, &axis_orig, 20.0, 0.0);

/* insertion d'un attribut PHIGS type de ligne dans la structure x_axis_id */
	tset_linetype (x_axis_id, -1, PLINE_DASH);

/* définition de la scène */
	struct_ids[0] = circle_id;
	struct_ids[1] = x_axis_id;
	struct_ids[2] = y_axis_id;
	tscene (scene_id, &struct_id_list, view_ind);

/* définition d'une vue centrée 2D */
	tview2_center (ws_id, view_ind, &view_center, zoom, &viewport);

/* affichage de la scène sur le poste de travail */
	ppost_struct (ws_id, scene_id, 1.0);
	predraw_all_structs (ws_id, PFLAG_ALWAYS);

/* fermeture du poste de travail */
	tclose_ws (ws_id);

/* génération d'un fichier PostScript */
	topen_ws (PostScript_id,"PostScript_file",80791);
	tview2_center (PostScript_id,view_ind,&view_center,zoom,&viewport);
	ppost_struct(PostScript_id,scene_id,1.);
	predraw_all_structs(PostScript_id,PFLAG_ALWAYS);
	tclose_ws (PostScript_id);

/* fermeture de PHIGURE */
	tclose_phigure ();
}

Pour générer un fichier PostScript correspondant à l'image précédente, il suffit d'utiliser un poste de travail de type PostScript (8079x) et suivre les règles suivantes :

définir un deuxième identificateur de poste de travail PostScript_id

ouvrir le poste de travail PostScript topen_ws (PostScript_id, ...)

définir une vue sur ce poste tview2_center (par exemple)

poster les structures à voir ppost_struct (PostScript_id, ...)

tracer les structures postées predraw_all_structs (PostScript_id, ...)

fermer le fichier généré tclose_ws (PostScript_id, ...)

En général, si le fichier PostScript doit correspondre exactement à l'image obtenu par un premier poste de travail ws_id, il suffit de dupliquer tous les appels dont le premier paramètre est ws_id .


Previous Next Up Title Contents General Index Functions Index Bookshelf