void placeKey() { for (int x = 0; x < 4; x++) { for (int y = 0; y < 4; y++) { if (key.t[x*4+y] == 1) { if (key.r+x <=4) gameOver(); matrix[key.r+x][key.c+y] = 1; colorMatrix[key.r+x][key.c+y] = key.color; } } } checkForScore(); key.t = next.t; key.color = next.color; key.r = 0; key.c = 3; int nextType = qran_range(0,7); int *n; n = tetriminos[nextType]; next.t = n; next.color = colors[nextType]; drawMatrix(); setNextPiece(next); droppedYet = 0; }
void GrDrawPathRangeBatch::onDraw(GrBatchFlushState* state, const SkRect& bounds) { const Draw& head = *fDraws.head(); SkMatrix drawMatrix(this->viewMatrix()); drawMatrix.preScale(fScale, fScale); drawMatrix.preTranslate(head.fX, head.fY); SkMatrix localMatrix; localMatrix.setScale(fScale, fScale); localMatrix.preTranslate(head.fX, head.fY); SkAutoTUnref<GrPathProcessor> pathProc(GrPathProcessor::Create(this->color(), this->overrides(), drawMatrix, localMatrix)); if (fDraws.count() == 1) { const InstanceData& instances = *head.fInstanceData; state->gpu()->pathRendering()->drawPaths(*this->pipeline(), *pathProc, this->stencilPassSettings(), fPathRange.get(), instances.indices(), GrPathRange::kU16_PathIndexType, instances.transformValues(), instances.transformType(), instances.count()); } else { int floatsPerTransform = GrPathRendering::PathTransformSize(this->transformType()); SkAutoSTMalloc<4096, float> transformStorage(floatsPerTransform * fTotalPathCount); SkAutoSTMalloc<2048, uint16_t> indexStorage(fTotalPathCount); int idx = 0; for (DrawList::Iter iter(fDraws); iter.get(); iter.next()) { const Draw& draw = *iter.get(); const InstanceData& instances = *draw.fInstanceData; memcpy(&indexStorage[idx], instances.indices(), instances.count() * sizeof(uint16_t)); pre_translate_transform_values(instances.transformValues(), this->transformType(), instances.count(), draw.fX - head.fX, draw.fY - head.fY, &transformStorage[floatsPerTransform * idx]); idx += instances.count(); // TODO: Support mismatched transform types if we start using more types other than 2D. SkASSERT(instances.transformType() == this->transformType()); } SkASSERT(idx == fTotalPathCount); state->gpu()->pathRendering()->drawPaths(*this->pipeline(), *pathProc, this->stencilPassSettings(), fPathRange.get(), indexStorage, GrPathRange::kU16_PathIndexType, transformStorage, this->transformType(), fTotalPathCount); } }
void GrStencilAndCoverTextContext::TextRun::draw(GrContext* ctx, GrDrawContext* dc, GrPipelineBuilder* pipelineBuilder, GrColor color, const SkMatrix& viewMatrix, SkScalar x, SkScalar y, const SkIRect& clipBounds, GrTextContext* fallbackTextContext, const SkPaint& originalSkPaint) const { SkASSERT(fDraw); SkASSERT(pipelineBuilder->getRenderTarget()->isStencilBufferMultisampled() || !fFont.isAntiAlias()); if (fDraw->count()) { pipelineBuilder->setState(GrPipelineBuilder::kHWAntialias_Flag, fFont.isAntiAlias()); GR_STATIC_CONST_SAME_STENCIL(kStencilPass, kZero_StencilOp, kKeep_StencilOp, kNotEqual_StencilFunc, 0xffff, 0x0000, 0xffff); *pipelineBuilder->stencil() = kStencilPass; SkAutoTUnref<GrPathRange> glyphs(this->createGlyphs(ctx)); if (fLastDrawnGlyphsID != glyphs->getUniqueID()) { // Either this is the first draw or the glyphs object was purged since last draw. glyphs->loadPathsIfNeeded(fDraw->indices(), fDraw->count()); fLastDrawnGlyphsID = glyphs->getUniqueID(); } SkMatrix drawMatrix(viewMatrix); drawMatrix.preTranslate(x, y); drawMatrix.preScale(fTextRatio, fTextRatio); SkMatrix& localMatrix = fLocalMatrixTemplate; localMatrix.setTranslateX(x); localMatrix.setTranslateY(y); dc->drawPathsFromRange(pipelineBuilder, drawMatrix, localMatrix, color, glyphs, fDraw, GrPathRendering::kWinding_FillType); } if (fFallbackTextBlob) { SkPaint fallbackSkPaint(originalSkPaint); fStroke.applyToPaint(&fallbackSkPaint); if (!fStroke.isFillStyle()) { fallbackSkPaint.setStrokeWidth(fStroke.getWidth() * fTextRatio); } fallbackTextContext->drawTextBlob(dc, pipelineBuilder->getRenderTarget(), pipelineBuilder->clip(), fallbackSkPaint, viewMatrix, fFallbackTextBlob, x, y, nullptr, clipBounds); } }
//-------------------------------------------------------------- //Draw should always be as fast as possible, so any heavy computations // should be done in update. //----- void testApp::draw(){ //Draw the two matrices drawMatrix(5,5+24+5+24+5,260,260,randCounts, 0, experimentsDone/26); drawMatrix(260+10,5+24+5+24+5,260,260,shuffleCounts,0,experimentsDone/26); //Draw info about how long we have been running //Draw text in black ofSetColor(0); ostringstream stringBuilder; stringBuilder << experimentsDone << " experiments done" << flush; double strWidth = arial24.stringWidth(stringBuilder.str()); double strX = (ofGetWidth() - strWidth)/2; arial24.drawString(stringBuilder.str(), strX, 260+5+24+5+24+24+5); //Clear out the string buffer for re-use stringBuilder.clear(); stringBuilder.str(""); //Calculate the p value for true random, and print it stringBuilder << "p < " << pValue(randCounts) << flush; strWidth = arial24.stringWidth(stringBuilder.str()); strX = 5 + (260 - strWidth)/2; arial24.drawString(stringBuilder.str(), strX, 130+5+24+5+24+24+5); //Clear out the string buffer for re-use stringBuilder.clear(); stringBuilder.str(""); //Calculate the p value for shuffle, and print it stringBuilder << "p < " << pValue(shuffleCounts) << flush; strWidth = arial24.stringWidth(stringBuilder.str()); strX = 10 + 260 + (260 - strWidth)/2; arial24.drawString(stringBuilder.str(), strX, 130+5+24+5+24+24+5); //Clear out the string buffer for re-use stringBuilder.clear(); stringBuilder.str(""); //Calculate the p value for shuffle, and print it stringBuilder << "If shuffle is truly random, what is chance\nof this outcome? (small is bad)" << flush; strWidth = arial24.stringWidth(stringBuilder.str()); strX = (ofGetWidth() - strWidth)/2; arial24.drawString(stringBuilder.str(), strX, 24); }
char* initialize ( char* cmdline ) { // Get comnmand line std::string str = cmdline; std::vector<std::string> args; while ( str.length() > 0) { args.push_back ( strSplit ( str, " " ) ); } fileName = ""; for (int n=0; n < args.size(); n++ ) { if ( args[n].compare ( "-f" ) == 0 ) { startFrame = strToI ( args[n+1] ); } if ( args[n].compare ( "-d" ) == 0 ) { // max_draw maxDraw = strToI ( args[n+1] ); } if ( args[n].find_first_of ( "." ) != std::string::npos ) { fileName = args[n]; } } if ( fileName.length()== 0 || args.size()==0 ) { app_printf ( "USAGE: state_view [-f #] [-d #] filename.raw\n\n" ); app_printf ( " -f # Start at frame \n" ); app_printf ( " -d # Maximum number of draw calls to read \n" ); _getch(); exit(-1); } for (int n=0; n < 10; n++ ) bShow[n] = true; // Initialize camera cam.setPos ( 0, 0, 1 ); cam.setToPos ( -window_width*3/8, -window_height*3/8, 1 ); cam.updateMatricies (); // Initialize bin and call names setup_bins (); // Load trace file char fname[256]; strcpy ( fname, fileName.c_str() ); load_trace_raw ( fname ); // required init functions init2D ( "arial_12" ); // specify font file (.bin/tga) setText ( 1.0, -0.5 ); // scale by 0.5, kerning adjust -0.5 pixels setview2D ( window_width, window_height ); // draw visualization layer drawMatrix (); PERF_INIT ( false ); // Enable CPU perf (do not require nv-perfmarker DLL) PERF_SET ( false, 2, false, "" ); // Perf CPU?, CPU level, NV Perfmarkers, Log filename return "NVIDIA State Viewer, by Rama Hoetzlein"; // Return Window title }
void plotCovMatrix(TString file, TString label1, TString label2) { ModTDRStyle(); gStyle->SetPaintTextFormat(".3g"); TFile f(file); TH2D *h_cov1 = (TH2D*)gDirectory->Get(label1+"_h_cov"); TH2D *h_cov2 = (TH2D*)gDirectory->Get(label2+"_h_cov"); TH2D *h_cor1 = (TH2D*)gDirectory->Get(label1+"_h_cor"); TH2D *h_cor2 = (TH2D*)gDirectory->Get(label2+"_h_cor"); // TH2D *h_cov3 = (TH2D*)h_cov1->Clone("syst_h_cov"); // h_cov3->Add(h_cov2, -1); // TH2D *h_cor3 = (TH2D*)h_cov3->Clone("syst_h_cor"); // for (int i = 1; i <= h_cov3->GetNbinsX(); ++i) { // for (int j = 1; j <= h_cov3->GetNbinsY(); ++j) { // int n = h_cov3->GetNbinsX(); // int bx = TranslateToX(i, j, n); // int by = TranslateToY(i, j, n); // h_cor3->SetBinContent(bx, by, h_cov3->GetBinContent(bx, by) / ( // TMath::Sqrt(h_cov3->GetBinContent(TranslateToX(i, i, n), TranslateToY(i, i, n))) // * TMath::Sqrt(h_cov3->GetBinContent(TranslateToX(j, j, n), TranslateToY(j, j, n))))); // } // } drawMatrix(h_cov1, label1+"_cov"); drawMatrix(h_cov2, label2+"_cov"); drawMatrix(h_cor1, label1+"_cor"); drawMatrix(h_cor2, label2+"_cor"); // drawMatrix(h_cov3, "syst_cov"); // drawMatrix(h_cor3, "syst_cor"); printErrors(h_cov1, h_cov2); }
void PostscriptDumper<T>::recursiveDrawing(const void * tree, ofstream& f, int depth) const { const HMatrix<T> * m = castToHMatrix(tree); if (!m->isLeaf()) { for (int i = 0; i < m->nrChild(); i++) { const HMatrix<T> * child = m->getChild(i); if (child) { recursiveDrawing(child, f, depth + 1); } } } if (depth == 0) drawRectangle(m, f, "emptyrectangle", 30-depth); drawMatrix(tree, f, depth); }
int main(int argc, char *argv[]){ MATRIX *mat; if( argc < 2 ){ mat = loadMatrix("test.mat"); }else{ mat = loadMatrix(argv[1]); } if( mat == NULL ){ fprintf(stderr, "test_matrix: return NULL\n"); return 1; } rs_initscr(); drawMatrix(0, 0, mat); refresh(); sleep(3); freeMatrix(mat); rs_endwin(); return 0; }
//the core loop of the application keep running until the user types q void run(void) { _generation = 0; char input; do { printTitle(); drawMatrix(); input = getchar(); clearScreen(); update(); _generation++; } while (input != 'q' && input != 'Q'); }
void main() { struct Matrix game_view; game_view.elements = (char *) malloc(sizeof(char *) * 9); int x = 0; for (x = 0;x < 9;x++) { game_view.elements[x] = ' '; } jmp: if (getElementsCount(game_view) < 9) { int game_state = checkState(game_view); if (game_state == 1) { Sleep(1000); system("cls"); printf("You won the game!"); Sleep(1000); exit(0); } else if (game_state == 2) { Sleep(1000); system("cls"); printf("You lost the game!!"); Sleep(1000); exit(0); } if (kbhit()) { if (!processInput(game_view, getch())) { printf("\nWrong Input..."); Sleep(500); } } drawMatrix(game_view); Sleep(1000); } else { int game_state = checkState(game_view); if (game_state == 1) { Sleep(1000); system("cls"); printf("You won the game!"); Sleep(1000); exit(0); } else if (game_state == 2) { Sleep(1000); system("cls"); printf("You lost the game!!"); Sleep(1000); exit(0); } else { system("cls"); printf("Game draw!!"); Sleep(1000); exit(0); } } goto jmp; }
void drawTransform(const Transform &t) { drawMatrix(t.getGlobalTransform() * Matrix3::scale({ 30,30 })); }