void Game::DrawSpectators(Point2d corner, int team){ const int columns = 5; int rows = 14; Circle spectator(10, SPECTATOR_CIRCLE_RAY); float randr, randg; for(int i=0; i < columns; ++i){ corner.set(corner.x + SPECTATOR_CIRCLE_RAY*2 + 0.1f, corner.y - SPECTATOR_CIRCLE_RAY*2 + 0.43f); for(int j=0; j < rows; ++j){ if (team == 0){ randr = (float)rand()/(3*RAND_MAX); randg = (float)rand()/RAND_MAX; spectator.SetColor(RGBcolor(randr, randg, 1.0f)); } else if (team == 1){ randg = (float)rand()/RAND_MAX; spectator.SetColor(RGBcolor(1.0f, randg, 0.09f)); } spectator.DrawCircle(m_system, Point2d(corner.x, corner.y - (SPECTATOR_CIRCLE_RAY*2 + 0.1f)*j)); if (team == 0){ spectators1.push_back(spectator.GetObject()); } else { spectators2.push_back(spectator.GetObject()); } } rows--; } }
RGBcolor RGB_DB::XNamedColor_to_RGBcolor(const char * colstr) { XColor screen; XColor exact; if (!XAllocNamedColor(disp, DefaultColormap (disp, 0),colstr, &screen, &exact)) { std::cout << "\ncolor allocation failed for [" << colstr << "], using black"; if (errno == BadColor) std::cout << "(color " << colstr << " not in the rgb database"; return RGBcolor(0,0,0); } return RGBcolor(exact.red/257,exact.green/257,exact.blue/257); }
void GLPolygonTest::draw(Canvas*, const Allocation& a) const { RGBcolor(255, 255, 255); clear(); Coord x_size = a.x_allotment().span(); Coord y_size = a.y_allotment().span(); Coord x_mid = x_size * 0.5; Coord y_mid = y_size * 0.5; RGBcolor(255, 0, 0); triangle( 0.0, 0.0, 0.0, x_mid, y_size, 0.0, x_size, 0.0, 0.0 ); }
RGBcolor convertHSVtoRGB( const HSVcolor &col ) { float hue = col.hue; float sat = col.saturation; float val = col.value; float x = 0, y = 0, z = 0; if( hue == 1 ) hue = 0; else hue *= 6; int i = static_cast<int>( std::floor( hue ) ); float f = hue - i; float p = val * ( 1 - sat ); float q = val* ( 1 - ( sat * f ) ); float t = val* ( 1 - ( sat * ( 1 - f ) ) ); switch( i ) { case 0: x = val; y = t; z = p; break; case 1: x = q; y = val; z = p; break; case 2: x = p; y = val; z = t; break; case 3: x = p; y = q; z = val; break; case 4: x = t; y = p; z = val; break; case 5: x = val; y = p; z = q; break; } return RGBcolor( x, y, z ); }
/* Transform body normals, draw front */ void drawbody(Matrix Rot) { double bodyScale = 1.0/theBodyRadius; register int i, j, k, n; pushmatrix(); scale(bodyScale, bodyScale, bodyScale); for (j=0; j<bodyNFaces; j++) { double dot = Rot[X][Z]*theFaceNormals[j][X] +Rot[Y][Z]*theFaceNormals[j][Y] +Rot[Z][Z]*theFaceNormals[j][Z]; if (dot>0.0) { /* Front-facing polygon, so draw it */ short shadedColor[3]; dot += 0.4; if (dot>1.0) dot = 1.0; shadedColor[0] = dot*theFaceColors[j][0]; shadedColor[1] = dot*theFaceColors[j][1]; shadedColor[2] = dot*theFaceColors[j][2]; n = theFaceVertices[j][0]; RGBcolor(shadedColor[0], shadedColor[1], shadedColor[2]); bgnpolygon(); for (k=1; k<=n; k++) { i = theFaceVertices[j][k]; v4f(thePoints[i]); } endpolygon(); } } popmatrix(); }
bool AsciiProcessor::get_col( const char * buf, RGBcolor & col, const char * & next ) { while ( *buf == ' ' ) { ++buf; } if ( buf == '\0' ) { return false; } unsigned char c[3]; bool res = false; for ( int i = 0; i < 3; ++i ) { if ( buf[0] != '\0' && buf[1] != '\0' ) { char chr[3]; chr[0] = buf[0]; chr[1] = buf[1]; chr[2] = '\0'; char* error_ptr; long tmp_long = strtol( chr, &error_ptr, 16 ); if ( error_ptr != chr + 2 || tmp_long < 0 || tmp_long > 255 ) { //cerr << "\ntmp_long=" << tmp_long; break; } c[i] = ( unsigned char ) tmp_long; buf += 2; if ( i == 2 ) { res = true; } } else { break; } } if ( res == true ) { next = buf; col = RGBcolor( c[0], c[1], c[2] ); return true; } return false; }
/* Adds a line to the score of the team given as a parameter */ void Game::DrawScoreForTeam(int team){ const Point2d SCORE1_POSU(15.0f, 2.0f), SCORE1_POSB(15.0f, 7.0f), SCORE2_POSU(15.0f, -7.0f), SCORE2_POSB(15.0f, -2.0f); if (team == 0){ // We draw the lines depicting the scores in // the upper part of the screen field->SetObjectColor(RGBcolor(0.06f, 0.21f, 1.0f)); switch (score1) { case (1): field->DrawScoreLine(SCORE1_POSU, SCORE1_POSB); break; case (2): field->DrawScoreLine(Point2d(SCORE1_POSU.x + 1.0f, SCORE1_POSU.y), Point2d(SCORE1_POSB.x + 1.0f, SCORE1_POSB.y)); break; case (3): field->DrawScoreLine(Point2d(SCORE1_POSU.x + 2.0f, SCORE1_POSU.y), Point2d(SCORE1_POSB.x + 2.0f, SCORE1_POSB.y)); break; default: break; } } if (team == 1){ field->SetObjectColor(RGBcolor(0.86f, 1.0f, 0.31f)); switch (score2) { case (1): field->DrawScoreLine(SCORE2_POSU, SCORE2_POSB); break; case (2): field->DrawScoreLine(Point2d(SCORE2_POSU.x + 1.0f, SCORE2_POSU.y), Point2d(SCORE2_POSB.x + 1.0f, SCORE2_POSB.y)); break; case (3): field->DrawScoreLine(Point2d(SCORE2_POSU.x + 2.0f, SCORE2_POSU.y), Point2d(SCORE2_POSB.x + 2.0f, SCORE2_POSB.y)); break; default: break; } } }
void InitSGI () { ginit (); /* Initialize the display. */ ginit_done = true; cursoff (); RGBmode (); /* Select RGB mode (24-bit color). */ gconfig (); RGBcolor (0, 0, 0); clear (); qdevice (KEYBD); }
static void draw_twist (void) { int i; toid1_twists[2] = (double) (mx-121) / 8.0; i=3; /* TPTS (1.0, ((double)my) /400.0); TPTS (1.1, 1.1 * ((double)my) / 400.0); */ TPTS (1.0, -((double)(my-121)) /200.0); TPTS (1.1, -1.1 * ((double)(my-121)) / 200.0); #ifdef IBM_GL_32 rotate (230, 'x'); rotate (230, 'y'); scale (1.8, 1.8, 1.8); if (mono_color) { RGBcolor (178, 178, 204); twist_extrusion (NUM_TWIS_PTS, twistation, twist_normal, NULL, NUM_TOID1_PTS, toid1_points, NULL, toid1_twists); } else { twist_extrusion (NUM_TWIS_PTS, twistation, twist_normal, NULL, NUM_TOID1_PTS, toid1_points, toid1_colors, toid1_twists); } #endif #ifdef OPENGL_10 glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); /* set up some matrices so that the object spins with the mouse */ glPushMatrix (); glTranslatef (0.0, 0.0, -80.0); glRotated (43.0, 1.0, 0.0, 0.0); glRotated (43.0, 0.0, 1.0, 0.0); glScaled (1.8, 1.8, 1.8); gleTwistExtrusion (NUM_TWIS_PTS, twistation, twist_normal, NULL, NUM_TOID1_PTS, toid1_points, NULL, toid1_twists); glPopMatrix (); glutSwapBuffers (); #endif }
/* We'll override the plot function to make pixels with very * disparate subsample values darker. This produces a i * really cool effect when used with an otherwise bright * colormap. */ virtual int plot() { assert( screen_init ); percent_counter pc(screen->h * screen->w); if (verbosity > 0) pc.start(); for (int y = 0; y < screen->h; ++y) { for (int x = 0; x < screen->w; ++x) { if (!working) return 1; color cval = RGBcolor(0, 0, 0); for (int k = 0; k < sres; ++k) { for (int j = 0; j < sres; ++j) { double sx = (k+0.5)/sres; double sy = (j+0.5)/sres; cval += color_func(to_plane(x+sx, y+sy)); } } cval /= sres * sres; /* Here's the change: basically, set * the value to the saturation. */ double b = min(min(cval.r, cval.g), cval.b); cval.r -= b; cval.g -= b; cval.b -= b; set_pixel(x, y, cval.r, cval.g, cval.b); if (verbosity > 0) pc.count(); } } working = false; update(); return 0; }
void ldCmap() { float r,g,b; long i,c; for(i=0;i<1024;i++) { r = (float)i/1023; g = (float)i/1023; b = (float)i/1023; // g=b=0; //r = 1.0;g=b=0; r = 1-r; b = 1-b; g = 1-g; c = RGBcolor(r,g,b); Cmap[i] = c; //printf("c %d\n",c); } }
RGBcolor TestRGBColor() { return RGBcolor(170, 66, 200); }
RGBcolor RandomRGBColor() { return RGBcolor(255.0f*ci::Rand::randFloat(), 255.0f*ci::Rand::randFloat(), 255.0f*ci::Rand::randFloat()); }
/* The game is Initialized here: the players and the field. */ void Game::Init(){ float xball, yball; ball = new Circle(10, BALL_CIRCLE_RAY); // Positions of player1 player1_pos.push_back(Point2d(0.0f, 15.0f)); player1_pos.push_back(Point2d(7.8f, 13.0f)); player1_pos.push_back(Point2d(-5.7f, 3.5f)); player1_pos.push_back(Point2d(-0.3f, 1.3f)); player1_pos.push_back(Point2d(-7.0f, -8.0f)); player1_pos.push_back(Point2d(7.5f, -11.0f)); std::vector<Point2d>::iterator it; for(it = player1_pos.begin(); it != player1_pos.end(); ++it){ // We have to keep every circle we create in a vector // to be able to make transformations with them later Circle circle(10, PLAYER_CIRCLE_RAY); circle.SetColor(RGBcolor(0.06f, 0.21f, 1.0f)); circle.SetArmsColor(RGBcolor(0.2f, 0.40f, 1.0f)); circle.DrawArms(m_system, *it); circle.DrawCircle(m_system, *it); player1.push_back(circle); } // Positions of player2 player2_pos.push_back(Point2d(0.0f, -14.5f)); player2_pos.push_back(Point2d(-7.8f, -13.0f)); player2_pos.push_back(Point2d(4.5f, -3.5f)); player2_pos.push_back(Point2d(-0.3f, -1.3f)); player2_pos.push_back(Point2d(7.0f, 8.0f)); player2_pos.push_back(Point2d(-7.8f, 11.0f)); for(it = player2_pos.begin(); it != player2_pos.end(); ++it){ // Same as earlier on player1 Circle circle(10, PLAYER_CIRCLE_RAY); circle.SetColor(RGBcolor(0.86f, 1.0f, 0.31f)); circle.SetArmsColor(RGBcolor(0.89f, 0.54f, 0.05f)); circle.DrawArms(m_system, *it); circle.DrawCircle(m_system, *it); player2.push_back(circle); } // Initialize the ball ball->SetColor(RGBcolor(0.0f, 0.0f, 0.0f)); // Pick randomly the team and the player which holds the ball srand((unsigned int)time(NULL)); m_team = rand() % 2; m_player = rand() % 6; if (m_team == 0){ xball = player1_pos[m_player].x; yball = player1_pos[m_player].y - PLAYER_CIRCLE_RAY - BALL_CIRCLE_RAY; } else if (m_team == 1){ xball = player2_pos[m_player].x; yball = player2_pos[m_player].y + PLAYER_CIRCLE_RAY + BALL_CIRCLE_RAY; } ball_position.set(xball, yball); ball->DrawCircle(m_system, ball_position); DrawSpectators(); // Draw also the field field = new Field(m_system); field->DrawField(); state = HOLD; }