/* initGui must be called to initialize the structures used by the GUI */ int initGUI(int level) { int i; int n = CARD_NUMBER; char cardName[50]; if (i_initGUI) return(-1); /* check the flag of GUI initialized*/ markIndex = 0; /* mark color index*/ for (i=0; i<n; i++) { if (i<10) sprintf(cardName, "%s/0%1d.xpm", xpmdir, i); else sprintf(cardName, "%s/%2d.xpm", xpmdir, i); read_cmap(cardName, &(mycard[i])); } initLayout(level); rootColor = NULL; doColorTable(mycard, 0, n); initGraphics(); setBlack(& mycard[ EMPTY_CARD ]); initColors(); remapColor(mycard, 0, CARD_NUMBER-1); initWindow(); initImages(mycard, 0, CARD_NUMBER-1); drawMenu(); /* printf(" Nex Graphics done \n"); */ i_initGUI = 1; /* set the flag of GUI initialized*/ return(0); }
void insertItem(const Key& k, const Element& e) { // insert (key,element) BTPosition z = inserter(k, e); // insert in base tree if (BST::T.isRoot(z)) setBlack(z); // root is always black else remedyDoubleRed(z); // rebalance if needed }
ColorsSelecter::ColorsSelecter(QWidget *parent) : QLabel(parent) { lastButton = Qt::NoButton; front = TC::Black; back = TC::White; image = 0; reprintImage(); m_useAlpha = false; setPixmap(QPixmap::fromImage(image->scaled(34, 26, Qt::KeepAspectRatio/*, Qt::SmoothTransformation*/))); setFixedSize(34,26); actionWhite = new QAction(QIcon(QPixmap::fromImage(colorIcon(TC::White))), QString(), 0); actionLightGray = new QAction(QIcon(QPixmap::fromImage(colorIcon(TC::LightGray))), QString(), 0); actionDarkGray = new QAction(QIcon(QPixmap::fromImage(colorIcon(TC::DarkGray))), QString(), 0); actionBlack = new QAction(QIcon(QPixmap::fromImage(colorIcon(TC::Black))), QString(), 0); actionTransp = new QAction(QIcon(QPixmap::fromImage(colorIcon(TC::Transparency))), QString(), 0); connect(actionWhite, SIGNAL(triggered()), this, SLOT(setWhite())); connect(actionLightGray, SIGNAL(triggered()), this, SLOT(setLightGray())); connect(actionDarkGray, SIGNAL(triggered()), this, SLOT(setDarkGray())); connect(actionBlack, SIGNAL(triggered()), this, SLOT(setBlack())); connect(actionTransp, SIGNAL(triggered()), this, SLOT(setTransparency())); }
/*RGB Animations*/ void blinkGreen(int times) { for (int i = 0; i < times; i++) { setGreen(); delay(250); setBlack(); delay(250); } }
void remedyDoubleRed(const BTPosition& z) { // fix double-red z BTPosition v = BST::T.parent(z); // v is z's parent if (BST::T.isRoot(v) || isBlack(v)) return; // v is black, all ok // z, v are double-red if (isBlack(BST::T.sibling(v))) { // Case 1: restructuring v = BST::T.restructure(z); setBlack(v); // top vertex now black setRed(BST::T.leftChild(v)); setRed(BST::T.rightChild(v)); // children are red } else { // Case 2: recoloring setBlack(v); // make v black setBlack(BST::T.sibling(v)); // ..and its sibling BTPosition u = BST::T.parent(v); // u is v's parent if (BST::T.isRoot(u)) return; setRed(u); // make u red remedyDoubleRed(u); // may need to fix u now } }
void drawCircle(FILE * f, int x, int y, float diameter) { setBlack(f); fprintf(f, "%d %d %f 0 360 arc closepath\n", x, y, diameter + 0.5); fprintf(f, "fill\n"); fprintf(f, "stroke\n"); setRGBColor(f, 1, 1, 1); fprintf(f, "%d %d %f 0 360 arc closepath\n", x, y, diameter); fprintf(f, "fill\n"); fprintf(f, "stroke\n"); }
void removeElement(const Key& k) // remove using key throw(NonexistentElementException) { BTPosition u = finder(k, BST::T.root()); // find the node if (u.isNull()) // not found? throw NonexistentElementException("Remove nonexistent element"); BTPosition r = remover(u); // remove u if (BST::T.isRoot(r) || isRed(r) || wasParentRed(r)) setBlack(r); // fix by color change else // r, parent both black remedyDoubleBlack(r); // fix double-black r }
void remedyDoubleBlack(const BTPosition& r) { // fix double-black r BTPosition x, y, z; x = BST::T.parent(r); y = BST::T.sibling(r); if (isBlack(y)) { if (hasRedChild(y)) { // Case 1: restructuring z = redChild(y); Color oldColor = color(x); // save top vertex color z = BST::T.restructure(z); // restructure x,y,z setColor(z, oldColor); setBlack(r); // fix colors setBlack(BST::T.leftChild(z)); setBlack(BST::T.rightChild(z)); } else { // Case 2: recoloring setBlack(r); setRed(y); // r=black, y=red if (isBlack(x) && !BST::T.isRoot(x)) remedyDoubleBlack(x); // fix double-black x setBlack(x); } } else { // Case 3: adjustment if (y == BST::T.rightChild(x)) z = BST::T.rightChild(y); // z is the grandchild else z = BST::T.leftChild(y); // ...on same side as y BST::T.restructure(z); // restructure x,y,z setBlack(y); setRed(x); // y=black, x=red remedyDoubleBlack(r); // fix by Case 1 or 2 } }
void fillCircle(FILE * f, int x, int y, float diameter, float r, float g, float b) { if (r + g + b < 1.5) { setWhite(f); } else { setBlack(f); } fprintf(f, "%d %d %f 0 360 arc closepath\n", x, y, diameter + 0.5); fprintf(f, "fill\n"); fprintf(f, "stroke\n"); setRGBColor(f, r, g, b); fprintf(f, "%d %d %f 0 360 arc closepath\n", x, y, diameter); fprintf(f, "fill\n"); fprintf(f, "stroke\n"); }
/*Arduino Methods*/ void doRGBPOST() { for (int i = 0; i < 5; i++) { setWhite(); delay(500); setBlack(); delay(500); } setRed(); delay(1000); setGreen(); delay(1000); setBlue(); delay(1000); setWhite(); }
int main(int argc, char* argv[]) { // ensure proper usage if (argc != 3) { printf("Usage: ./copy infile outfile\n"); return 1; } // remember filenames char* infile = argv[1]; char* outfile = argv[2]; // open input file FILE* inptr = fopen(infile, "r"); if (inptr == NULL) { printf("Could not open %s.\n", infile); return 2; } // open output file FILE* outptr = fopen(outfile, "w"); if (outptr == NULL) { fclose(inptr); fprintf(stderr, "Could not create %s.\n", outfile); return 3; } // read infile's BITMAPFILEHEADER BITMAPFILEHEADER bf; fread(&bf, sizeof(BITMAPFILEHEADER), 1, inptr); // read infile's BITMAPINFOHEADER BITMAPINFOHEADER bi; fread(&bi, sizeof(BITMAPINFOHEADER), 1, inptr); // ensure infile is (likely) a 24-bit uncompressed BMP 4.0 if (bf.bfType != 0x4d42 || bf.bfOffBits != 54 || bi.biSize != 40 || bi.biBitCount != 24 || bi.biCompression != 0) { fclose(outptr); fclose(inptr); fprintf(stderr, "Unsupported file format.\n"); return 4; } // write outfile's BITMAPFILEHEADER fwrite(&bf, sizeof(BITMAPFILEHEADER), 1, outptr); // write outfile's BITMAPINFOHEADER fwrite(&bi, sizeof(BITMAPINFOHEADER), 1, outptr); // determine padding for scanlines int padding = (4 - (bi.biWidth * sizeof(RGBTRIPLE)) % 4) % 4; // iterate over infile's scanlines for (int i = 0, biHeight = abs(bi.biHeight); i < biHeight; i++) { // iterate over pixels in scanline for (int j = 0; j < bi.biWidth; j++) { // temporary storage RGBTRIPLE triple; // read RGB triple from infile fread(&triple, sizeof(RGBTRIPLE), 1, inptr); if (isRedish(&triple)) { setWhite(&triple); } else { setBlack(&triple); } // write RGB triple to outfile fwrite(&triple, sizeof(RGBTRIPLE), 1, outptr); } // skip over padding, if any fseek(inptr, padding, SEEK_CUR); // then add it back (to demonstrate how) for (int k = 0; k < padding; k++) { fputc(0x00, outptr); } } // close infile fclose(inptr); // close outfile fclose(outptr); // that's all folks return 0; }
//------------------------------------------------------------------------------ void Cloud::doUpdate( float dt ) { m_life += dt; if ( m_size == 0 ) { setBlack( static_cast<Game *>( Engine::instance()->getContext() )->getBlack() ); } updateDamageable( dt ); if ( m_black ) { m_sprite = Engine::rm()->GetSprite( BLACK[m_size] ); } else { m_sprite = Engine::rm()->GetSprite( WHITE[m_size] ); } if ( isDestroyed() ) { if ( m_size > 0 ) { for ( int i = 0; i < 3; ++i ) { Entity* entity = Engine::em()->factory( Cloud::TYPE ); if ( getBlack() ) { entity->setBlack( 0 ); } else { entity->setBlack( 1 ); } entity->setScale( 0.1f ); static_cast< Cloud * >( entity )->setSize( m_size - 1 ); entity->init(); entity->getBody()->SetXForm( m_body->GetPosition(), m_body->GetAngle() ); } } destroy(); } else if ( isHealthy() && m_size < 4 ) { Entity* entity = Engine::em()->factory( Cloud::TYPE ); if ( getBlack() ) { entity->setBlack( 0 ); } else { entity->setBlack( 1 ); } entity->setScale( 0.1f ); static_cast< Cloud * >( entity )->setSize( m_size + 1 ); entity->init(); entity->getBody()->SetXForm( m_body->GetPosition(), m_body->GetAngle() ); destroy(); } if ( getFriend() ) { b2Vec2 velocity( 0.0f, 0.0f ); m_body->SetAngularVelocity( 0.0f ); m_body->SetLinearVelocity( velocity ); } }