📄 colourwheel.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 Sections 60 /* sections to simulate a circle */#define dTheta (360.0/Sections)/* angular width of each piece */#define BoldSansSerif -6 /* text font number */#define deg *3.1415926535897932384/180main() /* file "ColourWheel.c" */{ Pint WorkstnID = 1; /* workstation identifier */ Pint ConnID; /* connection identifier */ Pint WorkstnType = POIDDX; /* out/in, dir, dbl bfr, X */ Pint Direct = 0; /* sent to "pescape_u250" */ Pint Structure = 1; /* structure ID */ Pvertex3_set VertexSet; /* set of vertex lists */ Pvertex3_list VertexList; /* list of vertices w/ data */ Ppoint3 Vertices[3]; /* do "circle" w/ triangles*/ Pcolr_rep Colour, HSVRGB[360]; /* for defining colour map */ Pcolr_rep Colours[3]; /* triangle vertex colours */ static char Labels[6][8] = { /* for labelling the wheel */ "0/6,6/6", "1/6", "2/6", "3/6", "4/6", "5/6"}; static Ptext_align CenterHalf = {PHOR_CTR, PVERT_HALF}; Pmatrix3 xform; /* for transformations */ Pvec3 Vec; /* for translations, etc. */ Ppoint Loc; /* for placing text */ Pint Error; /* error-return variable */ Pfloat Theta; /* loop control variable */ Pint I; /* loop control variable */ popen_phigs((char *) stderr, 0); /* errors go to "stderr" */ pescape_u4("/dev/screen/phigs_window", &ConnID); popen_ws(WorkstnID, (void *) ConnID, WorkstnType); pescape_u250(WorkstnID, Direct); /* set colour environment */ /*--- calculate RGB representations of HSV colours ---------------------*/ for (I = 0, Theta = 0.0; I < Sections; I++, Theta += dTheta) { pset_colr_model(WorkstnID, PMODEL_HSV); Colour.hsv.hue = Theta/360.0; /* \ */ Colour.hsv.satur = 1.0; /* > fully saturated, */ Colour.hsv.value = 1.0; /* / luminous colour */ pset_colr_rep(WorkstnID, 2, &Colour); /* set HSV colour */ pset_colr_model(WorkstnID, PCOLR_RGB); pinq_colr_rep(WorkstnID, 2, /* retrieve the colour just */ PINQ_REALIZED, &Error, &Colour); /* set, but now it's RGB */ HSVRGB[I] = Colour; } /*=== define the color-wheeel structure ================================*/ popen_struct(Structure); pset_int_style(PSTYLE_SOLID); pset_int_shad_method(PINT_SHAD_METHOD_COLR); /*--- draw the piece-of-pie-shaped segments ----------------------------*/ Vertices[0].x = Vertices[0].y = Vertices[0].z = 0.0;/* point 1: center */ Colours[0].rgb.red = Colours[0].rgb.green = Colours[0].rgb.blue = 1.0; VertexSet.num_lists = 1; VertexSet.vertices = &VertexList; VertexList.num_vertices = 3; VertexList.num_data_per_vertex = 0; VertexList.vertex_points = Vertices; VertexList.vertex_colrvs.colr_reps.rgb = (void *) Colours; VertexList.vertex_norms = NULL; VertexList.vertex_data = NULL; for (I = 0, Theta = 0.0; I < Sections; I++, Theta += dTheta) { Vertices[1].x = cos((90-Theta) deg); /* \ point 2: */ Vertices[1].y = sin((90-Theta) deg); /* > on the */ Vertices[1].z = 0.0; /* / perimeter */ Colours[1] = HSVRGB[I]; /* use pre-calculated colour */ Vertices[2].x = cos((90-(Theta + dTheta)) deg); /* \ point 3: */ Vertices[2].y = sin((90-(Theta + dTheta)) deg); /* > also on */ Vertices[2].z = 0.0; /* / perimeter */ if (I < Sections - 1) Colours[2] = HSVRGB[I + 1]; /* next calculated colour */ else Colours[2] = HSVRGB[0]; /* first calculated colour */ Vec.delta_x = Vec.delta_y = Vec.delta_z = 0.45; pscale3(&Vec, &Error, xform); pset_local_tran3(xform, PTYPE_REPLACE); Vec.delta_x = Vec.delta_y = Vec.delta_z = 0.5; ptranslate3(&Vec, &Error, xform); pset_local_tran3(xform, PTYPE_POSTCONCAT); pfill_area_set3_data(PCOLR_RGB, NULL, NULL, &VertexSet); } /*--- do the labels around the perimeter of the wheel ------------------*/ pset_text_font(BoldSansSerif); pset_char_ht(0.05); pset_text_align(&CenterHalf); for (I = 0; I < 6; I++) { Loc.x = 1.08 * cos((90 - I * 60) deg); Loc.y = 1.08 * sin((90 - I * 60) deg); ptext(&Loc, Labels[I]); } pclose_struct(); ppost_struct(WorkstnID, Structure, 1.0); pclose_ws(WorkstnID); pclose_phigs();}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -