//*************************************************************************
void BeatDetectorApp::NextFile()
{
	roto = 0;
	if(mTrack && mTrack->isPlaying())
	{
		mTrack->enablePcmBuffering(false);
		mTrack->stop();
	}

#ifdef WIN32
	time_t now;
	time(&now);
	int time_int = (int)now;
#else
	timeval now;
	gettimeofday(&now, NULL);
	int time_int = now.tv_sec;
#endif

	Rand r;
	r.seed(time_int);
	int rand_file = r.nextInt(m_FileList.size());
	path my_path = m_FileList[rand_file].path();
	m_CurrentFile = my_path.string();
	
	if(!write_frames)
	{
		mAudioSource = audio::load(m_CurrentFile);
		mTrack = audio::Output::addTrack(mAudioSource, false);
		mTrack->enablePcmBuffering(true);
		mTrack->play();		
	}
	//rot_inc = r.nextFloat(1.5f, 30.0f);
}
示例#2
0
void EditorState::keyDown(ci::app::KeyEvent event)
{
    // XXX duplicate raycast
    Vec2f pos = GG.mouse.getPos();
    Vec3f planeHit = GG.hexRender.raycastHexPlane(pos.x, pos.y);
    HexCoord selectedHex = GG.hexGrid.WorldToHex(planeHit);

    int keycode = event.getCode();

    Vec3f& cameraTo = GG.hexRender.getCameraTo();
    if (keycode == app::KeyEvent::KEY_ESCAPE) {
        mManager.setActiveState("title");
    }
    else if (keycode == app::KeyEvent::KEY_UP) {
        cameraTo += Vec3f(0, 2.0f, 0);
    }
    else if (keycode == app::KeyEvent::KEY_DOWN) {
        cameraTo += Vec3f(0, -2.0f, 0);
    }   
    else if (keycode == app::KeyEvent::KEY_LEFT) {
        cameraTo += Vec3f(-2.0f, 0, 0);
    }
    else if (keycode == app::KeyEvent::KEY_RIGHT) {
        cameraTo += Vec3f(2.0f, 0, 0);
    }
    else if (keycode == app::KeyEvent::KEY_g) {
        //  Generate hex colors
        Vec2i mapSize = GG.hexMap.getSize();
        for (int iy=0; iy < mapSize.y; ++iy) {
            for (int ix=0; ix < mapSize.x; ++ix) {
                HexCell& cell = GG.hexMap.at(HexCoord(ix, iy));
                if (cell.getLand()) {
                    int playerID = random.nextInt(0, 5);
                    cell.setOwner(playerID);
                    cell.setColor(GG.warGame.getPlayers()[playerID].getColor());
                }
            }
        }
    }
    else if (keycode == app::KeyEvent::KEY_DELETE) {
        GG.hexMap.at(selectedHex).setLand(0);
    }
    else if (keycode == app::KeyEvent::KEY_SPACE) {
        mManager.setActiveState(string("game"));
    }
    else if (keycode == app::KeyEvent::KEY_c) {
        vector<HexCoord> connected = GG.hexMap.connected(selectedHex);
        for (vector<HexCoord>::iterator it = connected.begin(); it != connected.end(); ++it) {
            HexCell& cell = GG.hexMap.at(*it);
            Color cellColor = cell.getColor();
            cellColor.r = 0.5f * cellColor.r;
            cellColor.g = 0.5f * cellColor.g;
            cellColor.b = 0.5f * cellColor.b;
            cell.setColor(cellColor);
        }
    }
}
示例#3
0
MyCircle::MyCircle(int x, int y, int radius){
	this->x_ = x;
	this->y_ = y;
	this->child_ = NULL;
	this->anchor_x_ = x;
	this->anchor_y_ = y;
	this->bound_ = 0;
	this->alpha_level_ = 0;

	//make sure the radius isn't too large
	if(radius > 100)
		this->radius_ = 100;
	else
		this->radius_ = radius;

	//make the shape a random color:
	Rand random;
	random.seed(x*y);
	this->color_ = Color8u(random.nextInt(0,256),
		random.nextInt(0,256),random.nextInt(0,256));

	this->work_color_ = color_;
}
示例#4
0
void triangulate( Rand &prng, Graph &graph )
{
	typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
	typedef CGAL::Delaunay_triangulation_2<K>        Triangulation;
	typedef Triangulation::Edge_iterator             Edge_iterator;
	typedef Triangulation::Vertex_handle             Vertex_handle;
	typedef Triangulation::Point                     Point;
	typedef std::map<Vertex_handle, int>             VertexIndexMap;

	const static int minEdgeWeight = 1;
	const static int maxEdgeWeight = 20;

	// create the delaunay triangulation
	Triangulation triangulation;
	VertexIndexMap vertexIndexMap;

	// dump all of the BGL vertices into CGAL
	Graph::vertices_size_type numVertices = boost::num_vertices( graph );
	for ( int idx = 0; idx < numVertices; ++idx ) 
	{
		const VertexInfo &vertexInfo = boost::get( VertexInfoTag(), graph, idx );
		Point position( vertexInfo.position.x, vertexInfo.position.y );
		Vertex_handle handle = triangulation.insert( position );
		vertexIndexMap[ handle ] = idx;
	}

	// edge weight property map
	auto edgeWeightMap = boost::get( boost::edge_capacity, graph );

	// read out the edges and add them to BGL
	EdgeReverseMap edgeReverseMap = boost::get( boost::edge_reverse, graph );
	Edge_iterator ei_end = triangulation.edges_end();
	for (Edge_iterator ei = triangulation.edges_begin(); 
		ei != ei_end; ++ei)
	{
		int idxSourceInFace = ( ei->second + 2 ) % 3;
		int idxTargetInFace = ( ei->second + 1 ) % 3;
		Vertex_handle sourceVertex = ei->first->vertex( idxSourceInFace );
		Vertex_handle targetVertex = ei->first->vertex( idxTargetInFace );
		int idxSource = vertexIndexMap[ sourceVertex ];
		int idxTarget = vertexIndexMap[ targetVertex ];
		EdgeHandle forwardEdge = boost::add_edge( idxSource, idxTarget, graph );
		EdgeHandle backwardEdge = boost::add_edge( idxTarget, idxSource, graph );
		edgeReverseMap[ forwardEdge.first ] = backwardEdge.first;
		edgeReverseMap[ backwardEdge.first ] = forwardEdge.first;
		int edgeWeight = prng.nextInt( 1, 20 );
		edgeWeightMap[ forwardEdge.first ] = edgeWeight;
		edgeWeightMap[ backwardEdge.first ] = edgeWeight;
	}
}
int getRandDir (int gridSize, Rand myRand) {
	int thisDir = myRand.nextInt(4);
	int dirVal = 0;
	switch (thisDir) {
		case 0:
			dirVal = 1;
			break;
		case 1:
			dirVal = -1;
			break;	
		case 2:
			dirVal = gridSize;
			break;
		case 3:
			dirVal = -gridSize;
			break;
		};
	return dirVal;
	};
void P_2_1_3_01App::draw()
{
	// clear out the window with black
	gl::clear( Color( 1, 1, 1 ) );
    
    gl::color(0, 0, 0, 0.5f);
    
    mRand.seed(mRandomSeed);
    
    gl::pushMatrices();
    gl::translate(mTileWidth / 2.0f, mTileHeight / 2.0f);
    
    mCircleCount = mMousePos.x / 30.0f + 1.0f;
    
    mEndSize = lmap(float(mMousePos.x), 0.0f, float(getWindowWidth()), mTileWidth / 2.0f, 0.0f);
    mEndOffset = lmap(float(mMousePos.y), 0.0f, float(getWindowHeight()), 0.0f, (mTileWidth - mEndSize)/2.0f);
    
    for (int gridY = 0; gridY <= mTileCountY; gridY++) {
        for (int gridX = 0; gridX <= mTileCountX; gridX++) {
            gl::pushMatrices();
            gl::translate(mTileWidth * gridX, mTileHeight * gridY);
            gl::scale(Vec2f(1.0f, mTileHeight / mTileWidth));
            
            int toggle = mRand.nextInt(4);
            if (toggle == 0) gl::rotate(-90.0f);
            if (toggle == 1) gl::rotate(0.0f);
            if (toggle == 2) gl::rotate(90.0f);
            if (toggle == 3) gl::rotate(180.0f);
            
            for (int i = 0; i < mCircleCount; i++) {
                float diameter = lmap(float(i), 0.0f, mCircleCount - 1.0f, mTileWidth, mEndSize);
                float offset = lmap(float(i), 0.0f, mCircleCount - 1.0f, 0.0f, mEndOffset);
                gl::drawStrokedCircle(Vec2f(offset, 0.0f), diameter / 2.0f);
            }
            
            gl::popMatrices();
        }
    }
    
    gl::popMatrices();
}
int getSheepDir (int sheepPos, int *theGrid, int gridX, Rand thisRand) {
    // smart sheep will move toward something to eat if it is adjacent.
    // eventually, we might re-introduce tree age; sheep can only eat young trees and
    // must move around old trees.
    // do fires kill sheep?
    //
    int foodDirections[4] = {0,0,0,0};
    int nFoodDirs=0, sheepDir=0;
    //
    if (*(theGrid+1)==1) {
        foodDirections[nFoodDirs]=1;
        nFoodDirs++;
    };
    if (*(theGrid-1)==1) {
        foodDirections[nFoodDirs]=-1;
        nFoodDirs++;
    };
    if (*(theGrid+gridX)==1) {
        foodDirections[nFoodDirs] = gridX;
        nFoodDirs++;
    };
    if (*(theGrid-gridX)==1) {
        foodDirections[nFoodDirs] = -gridX;
        nFoodDirs++;
    };
    //
    if (nFoodDirs>0) {
        // there is something we can eat...
        sheepDir = foodDirections[thisRand.nextInt(nFoodDirs)];
    }
    else {
        sheepDir = getRandDir(gridX, thisRand);
    };
    //
    return sheepDir;
};