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

📄 bicycle.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 */#include <math.h>			/* link with library "-lm" */#define	 Spokes		30		/* number of spokes, sides on rim */#define	 pi		3.1415926535897#define	 dTheta		(2*pi/Spokes)	/* angle between spokes */#define	 dX		-0.003		/* speed of moving bike */#define	 deg		*pi/180.	/* convert degrees to radians */main()					/* file "Bicycle.c" */{    Pint	WorkstnID = 1;		/* workstation identifier */    Pint	ConnID;			/* connection identifier */    Pint	WorkstnType = POIDDX;	/* out/in, direct, dbl bfr, Xwindow */    Pint	Bike = 1, Wheel = 2, Frame = 3;	/* structure IDs */    float	WheelAngle;		/* current rotation of wheels */    float	Xpos;			/* current position of bike */    static Ppoint FramePoints[] = {		-0.95,-1.03, -0.87,-1.05, -0.60,-0.33,	/* fork */		-0.05,-1.05,  1.00,-1.05,  0.55, 0.00,	/* rear triangle */		 0.50,-0.10,  0.85,-0.95,  0.08,-0.95, 0.60, 0.10,		 0.70, 0.10,  0.73, 0.15,  0.70, 0.20,	/* seat */		 0.37, 0.20,  0.34, 0.15,  0.51, 0.13,		-0.01,-0.92, -0.56,-0.20, -0.52,-0.10,	/* front triangle */		 0.40,-0.10,  0.44, 0.00, -0.51, 0.00,		-0.45, 0.15, -0.10, 0.15, -0.10, 0.20,	/* handlebars */		-0.50, 0.20};    static Ppoint_list FrameData = {26, FramePoints};    Ppoint	SpokeData[2], RimData[Spokes + 1];    Ppoint_list	Spoke, Rim;    static Ppoint LocalOrigin = {0.0, 0.0};	/* for rotation/scaling */    static Pvec	TransF = {-0.9, -1.0};		/* front wheel translation */    static Pvec	TransR = { 0.9, -1.0};		/* rear wheel translation */    static Pvec Scale = {0.5, 0.5};		/* reduce to half size */    Ppoint	TempLoc;			/* for text only */    Pvec	TempScale;			/* for text only */    Pvec	TempTrans;			/* for text only */    /*--- transformation matrix variables ----------------------------------*/    Pmatrix	Translation, Scaling;		/* transformation matrices */    Pmatrix	Matrix;				/* temporary matrix */    Pint	Error;				/* error-return variable */    int		I;				/* loop control variable */    float	Theta;				/* temporary variable */    popen_phigs((char *) stderr, 0);		/* errors go to "stderr" */    pescape_u4("/dev/screen/phigs_window", &ConnID);    popen_ws(WorkstnID, (void *) ConnID, WorkstnType);    ppost_struct(WorkstnID, Bike, 1.0);		/* mark struct. for display */    /*=== define all CSS structures ========================================*/    /*--- define the "Frame" structure -------------------------------------*/    popen_struct(Frame);    pfill_area(&FrameData);    pbuild_tran_matrix(&LocalOrigin, &TransF, 0.0, &Scale, &Error, Matrix);    pset_local_tran(Matrix, PTYPE_REPLACE);    pexec_struct(Wheel);    pset_local_tran(Matrix, PTYPE_REPLACE);    pexec_struct(Wheel);    pclose_struct();    /*--- define the "Wheel" structure -------------------------------------*/    popen_struct(Wheel);    Rim.points = RimData;    for (I = 0; I <= Spokes; I++) {	Theta = I * dTheta;			/* calculate required angle */	Rim.points[I].x = cos(Theta);		/* x=r*cos(Theta) where r=1 */	Rim.points[I].y = sin(Theta);		/* y=r*sin(Theta) where r=1 */    }    Rim.num_points = Spokes + 1;    ppolyline(&Rim);    Spoke.num_points = 2;    Spoke.points = SpokeData;    for (I = 0; I < Spokes; I++) {	Theta = I * dTheta;			/* calculate required angle */	Spoke.points[0].x = 0.0;		/* \  start defining each */	Spoke.points[0].y = 0.0;		/*  \ spoke from the center */	Spoke.points[1].x = cos(Theta);		/*  / and proceed */	Spoke.points[1].y = sin(Theta);		/* /  rimward. */	ppolyline(&Spoke);    }    pclose_struct();    /*--- define the "Bike" structure --------------------------------------*/    popen_struct(Bike);    pset_char_ht(0.04);    TempLoc.x = 0.1, TempLoc.y = 0.8;    ptext(&TempLoc, "Joe's Olde Bike Shoppe");    TempScale.delta_x = TempScale.delta_y = 0.25;    pscale(&TempScale, &Error, Scaling);    TempTrans.delta_x = TempTrans.delta_y = 0.6;    ptranslate(&TempTrans, &Error, Translation);    pcompose_matrix(Translation, Scaling, &Error, Matrix);    pset_local_tran(Matrix, PTYPE_REPLACE);    pexec_struct(Frame);    pclose_struct();    /*=== display the stucture =============================================*/    ppost_struct(WorkstnID, Bike, 1.0);    pset_edit_mode(PEDIT_REPLACE);    Xpos = 1.4;					/* first location for bike */    WheelAngle = 0.0;				/* first angle for wheels */    for (Xpos = 1.4; Xpos > -0.36; Xpos += dX) {	/*--- first, open "Bike" structure and move the frame --------------*/	popen_struct(Bike);	pset_elem_ptr(3);			/* bike xform is element #3 */	TempTrans.delta_x = Xpos, TempTrans.delta_y = 0.6;	ptranslate(&TempTrans, &Error, Translation);	pcompose_matrix(Translation, Scaling, &Error, Matrix);	pset_local_tran(Matrix, PTYPE_REPLACE);	pclose_struct();	/*--- next, open the "Frame" structure and rotate the wheels -------*/	popen_struct(Frame);	pbuild_tran_matrix(&LocalOrigin, &TransR, WheelAngle deg, &Scale,	  &Error, Matrix);	pset_elem_ptr(2);			/* fr. wheel xform is ele 2 */	pset_local_tran(Matrix, PTYPE_REPLACE);	pbuild_tran_matrix(&LocalOrigin, &TransF, (WheelAngle + 5) deg, &Scale,	  &Error, Matrix);	pset_elem_ptr(4);			/* bk. wheel xform is ele 4 */	pset_local_tran(Matrix, PTYPE_REPLACE);	WheelAngle -= dX * 3000 / (2 * pi);	/* increment wheel angle */	pclose_struct();	pupd_ws(WorkstnID, PFLAG_PERFORM);    }    pclose_ws(WorkstnID);    pclose_phigs();}

⌨️ 快捷键说明

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