⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 clip.c

📁 Intro/: Directory containing introductory examples. HelloWorld.c A simple program that draws a bo
💻 C
字号:
#include <phigs.h>			/* get HP-PHIGS definitions for C */#include <stdio.h>			/* get standard I/O definitions */#define  FALSE			0	/* boolean false is integer 0 */#define	 TRUE			1	/* boolean true is integer 1 */#define	 SimplexSansSerif	-2	/* sent to "pset_text_font" */#define	 BoldSansSerif		-4	/* sent to "pset_text_font" */main()					/* file "Clip.c" */{    Pint	WorkstnID = 1;		/* workstation identifier */    Pint	ConnID;			/* connection identifier */    Pint	WorkstnType = POIDDX;	/* out/in, direct, dbl bfr, Xwindow */    Pint	TheCurve = 1;		/* structure ID (chosen by user) */    Ppoint	LinePts[100];		/* points for the polyline */    Ppoint_list	LineData;		/* data for the polyline */    static Ptext_align	CenterTop =	/* alignment for the main title */		{PHOR_CTR, PVERT_TOP};    static Ptext_align	CenterBottom =	/* alignment for the x-axis title */		{PHOR_CTR, PVERT_BOTTOM};    static Pvec	ToTheLeft = {-1.0, 0.0};/* sent to "pset_char_up_vec" */    Ppoint	Point;			/* one point (for various purposes) */    FILE	*datafile;		/* file pointer */    int		I = 0;			/* loop control variable */    /*=== read data file into the structure array ==========================*/    datafile = fopen("data", "r");	/* open data file (2 numbers/line) */    while (fscanf(datafile, "%f%f", &LinePts[I].x, &LinePts[I].y) != EOF)	I++;    fclose(datafile);    LineData.num_points = I;    LineData.points = LinePts;    /*=== set up HP-PHIGS to plot data =====================================*/    popen_phigs((char *) stderr, 0);	/* errors go to "stderr" */    pescape_u4("/dev/screen/phigs_window", &ConnID);    popen_ws(WorkstnID, (void *) ConnID, WorkstnType);    DefineView(WorkstnID, 1,		/* mapping for view index 1: */      0.0,  1.0,  0.0,  1.0,		/*   window: 0-1, 0-1 */      0.12, 0.98, 0.10, 0.88,		/*   viewport: in a subset */      FALSE);				/*   don't clip at view window */    DefineView(WorkstnID, 2,		/* mapping for view index 2: */      0.0,  1.0,  0.0,  1.0,		/*   window: 0-1, 0-1 */      0.0,  1.0,  0.0,  1.0,		/*   viewport: 0-1, 0-1 */      TRUE);				/*   clip at view window */    DefineView(WorkstnID, 3,		/* mapping for view index 3: */      0.0,  1.0,  0.0,  1.0,		/*   window: 0-1, 0-1 */      0.12, 0.98, 0.10, 0.88,		/*   viewport: in a subset */      TRUE);				/*   clip at view window */    popen_struct(TheCurve);    /*=== create the labels ================================================*/    pset_view_ind(2);    /*--- do main title ----------------------------------------------------*/    pset_text_font(BoldSansSerif);    pset_text_align(&CenterTop);    pset_char_ht(0.05);    Point.x = 0.5, Point.y = 1.0;    ptext(&Point, "VOLTAGE VARIANCE");    /*--- do the x-axis title ----------------------------------------------*/    pset_text_font(SimplexSansSerif);    pset_text_align(&CenterBottom);    pset_char_ht(0.03);    Point.x = 0.5, Point.y = 0.0;    ptext(&Point, "Time (seconds)");    /*--- do the y-axis title ----------------------------------------------*/    pset_char_up_vec(&ToTheLeft);    pset_text_align(&CenterTop);    Point.x = 0.0, Point.y = 0.5;    ptext(&Point, "Voltage");    /*=== graph the data ===================================================*/    pset_view_ind(1);    DefineRectangle(0.0, 1.0, 0.0, 1.0);    ppolyline(&LineData);    /*--- define the tic marks ---------------------------------------------*/    pset_view_ind(3);    DefineTics('X', 0.0, 0.0, 1.0, 0.01, 0.01, 5);    DefineTics('X', 1.0, 0.0, 1.0, 0.01, 0.01, 5);    DefineTics('Y', 0.0, 0.0, 1.0, 0.01, 0.01, 5);    DefineTics('Y', 1.0, 0.0, 1.0, 0.01, 0.01, 5);    pclose_struct();    /*=== post the image and close up shop =================================*/    ppost_struct(WorkstnID, TheCurve, 1.0);    pupd_ws(WorkstnID, PFLAG_PERFORM);	/* (regeneration flag) */    pclose_ws(WorkstnID);    pclose_phigs();}/****************************************************************************/DefineView(WorkstnID, ViewIndex, Wxmin, Wxmax, Wymin, Wymax,  Vxmin, Vxmax, Vymin, Vymax, ClipAtWindow)int	WorkstnID;			/* workstation identifier */int	ViewIndex;			/* the view being defined */float	Wxmin, Wxmax, Wymin, Wymax;	/* view window limits */float	Vxmin, Vxmax, Vymin, Vymax;	/* projection viewport limits */int	ClipAtWindow;			/* window (or display surface?) */{    Pview_map	Mapping;		/* window-onto-viewport mapping */    Pint	ErrorReturn;		/* error return variable */    Pview_rep	ViewRep;		/* complete description of view */    int		I, J;			/* loop control variables */    /*--- define the view orientation matrix as identity -------------------*/    for (I = 0; I < 3; I++)	for (J = 0; J < 3; J++)	    ViewRep.ori_matrix[I][J] = (I == J);    /*--- define view mapping matrix ---------------------------------------*/    Mapping.win.x_min = Wxmin;			/* \			    */    Mapping.win.x_max = Wxmax;			/*  \ put individual values */    Mapping.win.y_min = Wymin;			/*  / into the structure    */    Mapping.win.y_max = Wymax;			/* /			    */    Mapping.proj_vp.x_min = Vxmin;		/* \			    */    Mapping.proj_vp.x_max = Vxmax;		/*  \ put individual values */    Mapping.proj_vp.y_min = Vymin;		/*  / into the structure    */    Mapping.proj_vp.y_max = Vymax;		/* /			    */    peval_view_map_matrix(&Mapping, &ErrorReturn, ViewRep.map_matrix);    if (ErrorReturn != 0) {			/* did we get an error? */        printf("%s %d %s %s\n", "Error", ErrorReturn, "occurred during",          "call to Evaluate View Mapping Matrix.");        exit(1);    }    /*--- define the clip limits -------------------------------------------*/    if (ClipAtWindow)	ViewRep.clip_limit = Mapping.proj_vp;	/* clip at viewport */    else {	ViewRep.clip_limit.x_min = 0.0;		/* \		       */	ViewRep.clip_limit.x_max = 1.0;		/*  \ clip at edges of */	ViewRep.clip_limit.y_min = 0.0;		/*  / display surface  */	ViewRep.clip_limit.y_max = 1.0;		/* /		       */    }    /*--- define clip indicator --------------------------------------------*/    ViewRep.xy_clip = PIND_CLIP;    /*--- set the view representation --------------------------------------*/    pset_view_rep(WorkstnID, ViewIndex, &ViewRep);}/****************************************************************************/DefineRectangle(Xmin, Xmax, Ymin, Ymax)float	Xmin, Xmax, Ymin, Ymax;			/* rectangle's limits */{    Ppoint_list	Rectangle;    Ppoint	Corners[5];          Rectangle.num_points = 5;    Corners[0].x = Xmin, Corners[0].y = Ymin;	/* lower left corner */    Corners[1].x = Xmax, Corners[1].y = Ymin;	/* lower right corner */    Corners[2].x = Xmax, Corners[2].y = Ymax;	/* upper right corner */    Corners[3].x = Xmin, Corners[3].y = Ymax;	/* upper left corner */    Corners[4].x = Xmin, Corners[4].y = Ymin;	/* lower left corner */    Rectangle.points = Corners;    ppolyline(&Rectangle);}/****************************************************************************/DefineTics(Axis, Location, Start, End, Delta, Size, Major)char	Axis;				/* which axis are the tics for? */float	Location;			/* where is this line of tics? */float	Start;				/* where do the tics start? */float	End;				/* where do they end? */float	Delta;				/* draw a tic every how often? */float	Size;				/* how big should the tics be? */int	Major;				/* how often does major tic occur? */{    int		TicNumber = 0;		/* which tic are we on? */    Ppoint_list	Tic;			/* polyline data */    Ppoint	TicPoints[2];		/* both ends of a tic mark */    float	CurrentX, CurrentY;	/* loop control variables */    float	Length;			/* length of current tic mark */    if ((Axis == 'x') || (Axis == 'X')) {	for (CurrentX = Start; CurrentX <= End; CurrentX+=Delta,TicNumber++) {	    Length = Size * (1 + (TicNumber % Major == 0));	    Tic.num_points = 2;	    TicPoints[0].x = CurrentX;		/* x: bottom of tic mark */	    TicPoints[0].y = Location - Length;	/* y: bottom of tic mark */	    TicPoints[1].x = CurrentX;		/* x: top of tic mark */	    TicPoints[1].y = Location + Length;	/* y: top of tic mark */	    Tic.points = TicPoints;	    ppolyline(&Tic);	}    }    else if ((Axis == 'y') || (Axis == 'Y')) {	for (CurrentY = Start; CurrentY <= End; CurrentY+=Delta,TicNumber++) {	    Length = Size * (1 + (TicNumber % Major == 0));	    Tic.num_points = 2;	    TicPoints[0].x = Location - Length;	/* x: bottom of tic mark */	    TicPoints[0].y = CurrentY;		/* y: bottom of tic mark */	    TicPoints[1].x = Location + Length;	/* x: top of tic mark */	    TicPoints[1].y = CurrentY;		/* y: top of tic mark */	    Tic.points = TicPoints;	    ppolyline(&Tic);	}    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -