void Mouse::Update(void) { // Update Pos POINT MousePos = Manager::GetInput()->GetMousePos(); m_MouseEffect->SetPos(D3DXVECTOR3((float)MousePos.x, (float)MousePos.y, 0.0f)); // Random Color std::random_device Random; // 非決定的な乱数生成器を生成 std::mt19937 MT(Random()); // メルセンヌ・ツイスタの32ビット版、引数は初期シード値 std::uniform_int_distribution<> RandomColor(0, 100); // m_MouseEffect->SetCol(D3DXCOLOR(RandomColor(MT) * 0.01f, RandomColor(MT) * 0.01f, RandomColor(MT) * 0.01f, 1.0f)); }
// Show a label map. labelNum: how many number of random colors used for show, use default colors if is -1 Mat CmShow::Label(CMat& label1i, CStr& title, int labelNum, bool showIdx) { bool useRandom = labelNum > 0; labelNum = useRandom ? labelNum : COLOR_NU_NO_GRAY; vector<Vec3b> colors(labelNum); if (useRandom) for (size_t i = 0; i < colors.size(); i++) colors[i] = RandomColor(); else for (size_t i = 0; i < colors.size(); i++) colors[i] = gColors[i]; Mat showImg = Mat::zeros(label1i.size(), CV_8UC3); for (int y = 0; y < label1i.rows; y++) { Vec3b* showD = showImg.ptr<Vec3b>(y); const int* label = label1i.ptr<int>(y); for (int x = 0; x < label1i.cols; x++) if (label[x] >= 0) { showD[x] = colors[label[x] % labelNum]; if (showIdx) showD[x][2] = (byte)(label[x]); } } SaveShow(showImg, title); return showImg; }
/* Render a scene */ static void Render(void) { int NumBoxes = 100; int i; InitGL(); glClearColor(0.2, 0.2, 0.9, 0.0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); for (i=0;i<NumBoxes;i++) { float tx = -2.0 + 4.0 * Random(); float ty = -2.0 + 4.0 * Random(); float tz = 4.0 - 16.0 * Random(); float sx = 0.1 + Random() * 0.4; float sy = 0.1 + Random() * 0.4; float sz = 0.1 + Random() * 0.4; float rx = Random(); float ry = Random(); float rz = Random(); float ra = Random() * 360.0; glPushMatrix(); glTranslatef(tx, ty, tz); glRotatef(ra, rx, ry, rz); glScalef(sx, sy, sz); RandomColor(); drawBox(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0, GL_POLYGON); glPopMatrix(); } glFinish(); }
void RandomizedFill() { int x, y; int min = '!', max = '~', range = max - min; char ch; SDL_Color fg, bg; // Fill the screen with random whatever characters and random colors for(y=0; y < TERMINAL_ROWS; y++) { for(x=0; x < TERMINAL_COLS; x++) { ch = (rand() % range) + min; fg = RandomColor(), bg = RandomColor(); DrawCharacterAtPos(ch, y, x, &fg, &bg, 1); } } SDL_RenderPresent(render); }
void MakeBigText(char *text, uint x_offset, uint y_offset) { int len = strlen(text); if(len == 0) return; else if(len > TERMINAL_COLS / pbm_font->width) { fprintf(stderr, "Sorry, bro, your text is too long for the terminal!"); return; } int i; SDL_Color fg, bg; for(i=0; i < len; i++) { fg = RandomColor(), bg = RandomColor(); MakeBigLetter(text[i], x_offset, y_offset, &fg, &bg); x_offset += pbm_font->width; } }
void RandomKnot::assignColors(void) { // Initialize the color indices; -1 indicates an as-yet-unknown color. int color = mPrefs.technicolor() ? -1 : 0; for (int y = 0; y < mVSections; ++y) { for (int x = 0; x < mHSections; ++x) { mpSectionColors[BOT][y * mHSections + x] = color; mpSectionColors[TOP][y * mHSections + x] = color; } } ++color; // Assign colors to the sections by tracing all the 'strands' in the knot. for (int y = 0; y < mVSections; ++y) { for (int x = 0; x < mHSections; ++x) { if (mpSectionColors[TOP][y * mHSections + x] < 0) { // Assign a color to the top strand. if (traceColor(color, TOP, x, y, 0, 0)) { ++color; } } if (mpSectionColors[BOT][y * mHSections + x] < 0) { // Assign a color to the bottom strand. switch (mpSectionTypes[y * mHSections + x]) { case D: case H: if (traceColor(color, BOT, x, y, 0, 1)) { ++color; } break; case V: if (traceColor(color, BOT, x, y, 1, 0)) { ++color; } break; case N: break; } } } } // Generate the random colors. mpColors = new RandomColor[color]; int hue = randomInteger(360); const int gamut = 90 + randomInteger(270); const int shift = gamut / color; for (int i = 0; i < color; ++i) { mpColors[i] = RandomColor(0.4, 0.9, 0.6, 1.0, 1.0, 1.0, hue); hue = (hue + shift) % 360; } }
csRef<iLight> WalkTestLights::CreateRandomLight (const csVector3& pos, iSector* where, float dyn_radius) { csRef<iLight> dyn; float r, g, b; RandomColor (r, g, b); dyn = walktest->Engine->CreateLight ("", pos, dyn_radius, csColor(r, g, b), CS_LIGHT_DYNAMICTYPE_DYNAMIC); where->GetLights ()->Add (dyn); dynamic_lights.Push (dyn); return dyn; }
//-------------------------------------------------------------------- // Name: PickTetrad() // Desc: Picks a tetrad //-------------------------------------------------------------------- void CTetris::PickTetrad( ) { float color = RandomColor(); m_CurrentTet = CTetris::m_Tetrads[m_nNextTetName]; m_nCurrentTetName = m_nNextTetName; m_nNextTetName = RandomTetrad(); //m_NextTet = CTetris::m_Tetrads[m_nNextTetName]; for(int i=0; i<BLOCKS_PER_TET; i++) m_CurrentTet.tet[i].r = m_CurrentTet.tet[i].g = m_CurrentTet.tet[i].b = color; TranslateCurrTet(m_nNumofCols/2,1); }
bool WalkTestLights::HandleDynLight (iLight* dyn) { LightStruct* ls = (LightStruct*)(WalkDataObject::GetData(dyn->QueryObject ())); switch (ls->type) { case DYN_TYPE_MISSILE: { MissileStruct* ms = (MissileStruct*)(WalkDataObject::GetData( dyn->QueryObject ())); csVector3 v (0, 0, 2.5); csVector3 old = dyn->GetMovable()->GetPosition (); v = old + ms->dir.GetT2O () * v; iSector* s = dyn->GetMovable()->GetSectors()->Get(0); bool mirror = false; csVector3 old_v = v; s = s->FollowSegment (ms->dir, v, mirror); if (ABS (v.x-old_v.x) > SMALL_EPSILON || ABS (v.y-old_v.y) > SMALL_EPSILON || ABS (v.z-old_v.z) > SMALL_EPSILON) { v = old; if (ms->sprite) { ms->sprite->GetMovable ()->ClearSectors (); Sys->Engine->GetMeshes ()->Remove (ms->sprite); } csRef<WalkDataObject> ido ( CS::GetChildObject<WalkDataObject>(dyn->QueryObject())); dyn->QueryObject ()->ObjRemove (ido); if (ms->snd) { ms->snd_stream->Pause(); } delete ms; if (Sys->mySound) { if (Sys->wMissile_boom) { csRef<iSndSysStream> st = Sys->mySound->CreateStream ( Sys->wMissile_boom->GetData (), CS_SND3D_ABSOLUTE); csRef<iSndSysSource> sndsource = Sys->mySound-> CreateSource (st); if (sndsource) { csRef<iSndSysSource3D> sndsource3d = scfQueryInterface<iSndSysSource3D> (sndsource); sndsource3d->SetPosition (v); sndsource->SetVolume (1.0f); st->SetLoopState (CS_SNDSYS_STREAM_DONTLOOP); st->Unpause (); } } } ExplosionStruct* es = new ExplosionStruct; es->type = DYN_TYPE_EXPLOSION; es->radius = 2; es->dir = 1; WalkDataObject* esdata = new WalkDataObject (es); dyn->QueryObject ()->ObjAdd (esdata); esdata->DecRef (); WalkTestParticleDemos::Explosion (Sys, dyn->GetMovable ()->GetSectors ()->Get (0), dyn->GetMovable ()->GetPosition (), "explo"); return false; } else ms->dir.SetOrigin (v); iSector* sector = dyn->GetMovable ()->GetSectors ()->Get (0); if (sector != s) { dyn->IncRef (); sector->GetLights ()->Remove (dyn); s->GetLights ()->Add (dyn); dyn->DecRef (); } dyn->GetMovable ()->SetPosition (v); if (ms->sprite) move_mesh (ms->sprite, s, v); if (Sys->mySound && ms->snd) { csRef<iSndSysSource3D> sndsource3d = scfQueryInterface<iSndSysSource3D> (ms->snd); sndsource3d->SetPosition (v); ms->snd->SetVolume (1.0f); } break; } case DYN_TYPE_EXPLOSION: { ExplosionStruct* es = (ExplosionStruct*)(WalkDataObject::GetData( dyn->QueryObject ())); if (es->dir == 1) { es->radius += 3; if (es->radius > 6) es->dir = -1; } else { es->radius -= 2; if (es->radius < 1) { csRef<WalkDataObject> ido ( CS::GetChildObject<WalkDataObject>(dyn->QueryObject())); dyn->QueryObject ()->ObjRemove (ido); delete es; iSector* sector = dyn->GetMovable ()->GetSectors ()->Get (0); sector->GetLights ()->Remove (dyn); return true; } } dyn->SetCutoffDistance (es->radius); break; } case DYN_TYPE_RANDOM: { RandomLight* rl = (RandomLight*)(WalkDataObject::GetData( dyn->QueryObject ())); rl->dyn_move += rl->dyn_move_dir; if (rl->dyn_move < 0 || rl->dyn_move > 2) rl->dyn_move_dir = -rl->dyn_move_dir; if (ABS (rl->dyn_r1-dyn->GetColor ().red) < .01 && ABS (rl->dyn_g1-dyn->GetColor ().green) < .01 && ABS (rl->dyn_b1-dyn->GetColor ().blue) < .01) RandomColor (rl->dyn_r1, rl->dyn_g1, rl->dyn_b1); else dyn->SetColor (csColor ((rl->dyn_r1+7.*dyn->GetColor ().red)/8., (rl->dyn_g1+7.*dyn->GetColor ().green)/8., (rl->dyn_b1+7.*dyn->GetColor ().blue)/8.)); dyn->GetMovable()->SetPosition (dyn->GetMovable()->GetPosition () + csVector3 (0, rl->dyn_move_dir, 0)); dyn->GetMovable()->UpdateMove(); break; } } return false; }
void Ball::RandomColor() { RandomColor((int)Ball::Count); }
int main( int argc, char* argv[] ) { srand(time(nullptr)); LabData lab( 31, 31 ); // Setup SDL related stuff SDL_Init( SDL_INIT_VIDEO ); atexit( SDL_Quit ); atexit( IMG_Quit ); size_t hwin = 17; size_t wwin = 16; Term::SDL::Context term( wwin, hwin ); term.Tilemap( "tileset.png" ); SDL_Surface* screen = SDL_SetVideoMode( term.Framebuffer().Width() * term.TileWidth(), term.Framebuffer().Height() * term.TileHeight(), 32, SDL_SWSURFACE ); term.RenderTarget( screen ); Term::Char clearChar('\0'); clearChar.PriColor( Term::Color::Black ); clearChar.SecColor( Term::Color::Black ); term.Framebuffer().ClearChar( clearChar ); SDL_EnableKeyRepeat( 100, 100 ); // Basically the movementspeed of the player. Term::TTY tty( term.Framebuffer() ); GenerateLabyrinth( lab ); MakePrettySymbols( lab ); bool running = true; while(running) { SDL_Event event; while( SDL_PollEvent(&event) ) switch( event.type ) { case SDL_QUIT: running = false; break; case SDL_KEYDOWN: switch( event.key.keysym.sym ) { case SDLK_ESCAPE: running = false; break; case SDLK_UP: MovePlayer( lab, 0, -1 ); break; case SDLK_DOWN: MovePlayer( lab, 0, 1 ); break; case SDLK_LEFT: MovePlayer( lab, -1, 0 ); break; case SDLK_RIGHT: MovePlayer( lab, 1, 0 ); break; default: break; } break; } if( lab.win ) { std::string winstr( "!!!WIN!!!" ); int x = rand() % (term.Framebuffer().Width()+winstr.length()) - winstr.length(); int y = rand() % (term.Framebuffer().Height()+winstr.length()) - winstr.length(); tty.PriColor( RandomColor() ); tty.SecColor( RandomColor() ); tty.Place(x,y).Put( winstr ); } else { term.Framebuffer().Clear(); term.Framebuffer().Copy( lab.symbuf, 0, 1, -(term.Framebuffer().Width()/2) + lab.xplayer, -(term.Framebuffer().Height()/2) + lab.yplayer, term.Framebuffer().Width(), term.Framebuffer().Height() ); tty.Place( term.Framebuffer().Width()/2, term.Framebuffer().Height()/2+1 ); tty.PriColor( Term::Color::White ); tty.SecColor( Term::Color::Black ); tty.Put( 1 ); for( auto itoken : lab.tokens ) { tty.Place( (itoken % lab.width) +(term.Framebuffer().Width())/2 - lab.xplayer , (itoken / lab.width) +(term.Framebuffer().Height()/2) - lab.yplayer +1 ); tty.Put( 9 ); } tty.Place(0,0).PriColor( Term::Color::Black ).SecColor( Term::Color::White ); if( lab.door == 0 ) { tty.Put( "Tokens left: " ); std::stringstream ss; ss << lab.tokens.size(); tty.Put( ss.str() ); } else { tty.Put( "Find the door!" ); tty.Place( lab.door % lab.width + term.Framebuffer().Width()/2 - lab.xplayer, lab.door / lab.width + term.Framebuffer().Height()/2 + 1 - lab.yplayer ); tty.Put( 239 ); } } term.Print(); SDL_Flip(screen); SDL_Delay(50); } }
int main (int argc, char **argv) { srand(time(NULL)); int i, j, k; float minSize = 10000, maxSize = 1.0, minPeriod = 0.1, minStable = 0.1; PStack im2Regions = NewPStack(100); Image im2 = ReadPGMFile(argv[1]); Image out = ConvertImage1(CopyImage(im2)); fprintf(stderr,"Read in image %s with dimensions %d %d\n",argv[1],im2->rows,im2->cols); FindMSERegions(im2,im2Regions,minSize,maxSize,1,2,FALSE,TRUE); PStack dc = NewPStack(10); for(i=0;i<im2Regions->stacksize;i++) { Region re = im2Regions->items[i]; float area = PolygonArea(re->border); float numberOfSections = area / 44000; if ( numberOfSections >= 1 && numberOfSections < 5 ) { PolygonACD(re->border,0.06,dc); } } Region cc = im2Regions->items[i]; //DrawPolygon(cc->border,out,PIX3(0,255,0)); for(i=0;i<dc->stacksize;i++) { Polygon border = dc->items[i]; int area = PolygonArea(border); if ( area < 44000 || area > 44000 * 1.6 ) continue; PolygonVertexEvolution(border,4); int color = RandomColor(150); for(j=0;j<border->numberOfVertices;j++) { Ellipse e = NewEllipse(border->vertices[j].x,border->vertices[j].y,5,5,0); DrawEllipse(e,out,color); free(e); } DrawPolygon(border,out,color); } WritePPM("sections.ppm",out); //RegionsToSIFTDescriptors(im1Regions,im1Descriptors,4,8,41); //fprintf(stderr,"Created %d descriptors from %d regions in %2.2f seconds\n",im1Descriptors->stacksize,im1Regions->stacksize,CPUTIME-t0); //PrintSIFTDescriptors("csift1",im1Descriptors); /* PStack im2Regions = NewPStack(100); PStack im2Descriptors = NewPStack(100); t0 = CPUTIME; Image im2 = ReadPGMFile(argv[2]); FindMSERegions(im2,im2Regions,minSize,maxSize,minPeriod,minStable); RegionsToSIFTDescriptors(im2Regions,im2Descriptors,4,8,41); fprintf(stderr,"Created %d descriptors from %d regions in %2.2f seconds\n",im2Descriptors->stacksize,im2Regions->stacksize,CPUTIME-t0); PStack matches = NewPStack(100); double **transform = AllocDMatrix(3,3,0,0); FindMatches(im1Descriptors,im2Descriptors,matches,10); fprintf(stderr,"Found %d initial matches.\n",matches->stacksize); ScreenMatches(matches,transform); fprintf(stderr,"A1 = [ "); for(k=0;k<3;k++)fprintf(stderr,"%f %f %f;",transform[k][0],transform[k][1],transform[k][2]); fprintf(stderr,"]\n"); Image im3 = CreateImage(im1->rows,im1->cols); AffineTransformImage(im2,im3,NULL,transform); for (i=0;i<im1->rows;i++) { for (j=0;j<im1->cols;j++) { int rv = MAX(0,im1->pixels[i][j]); int bv = MAX(0,im3->pixels[i][j]); im3->pixels[i][j] = PIX3(rv,0,bv); }} WritePPM("affine.ppm",im3); */ return 0; }
void GenerateRandomHouse(int i) { HOUSE *house = &houses[i]; house->size = RandomInt(MIN_HOUSE_SIZE, MAX_HOUSE_SIZE); house->x_pos = RandomInt(house->size, (NU_SCREENWIDTH - house->size * 2)); house->y_pos = RandomInt(house->size, (NU_SCREENHEIGHT - house->size * 2)); house->color_body = RandomColor(); house->color_roof = RandomColor(); house->color_door = RandomColor(); house->speed = SPEED_B - SPEED_M * house->size; house->x_dir = rand() % 1 ? GO_LEFT : GO_RIGHT; house->y_dir = RandomInt(0,1) ? GO_DOWN : GO_UP; }