예제 #1
0
void init(){
	// White color
	glClearColor(1.0, 1.0, 1.0, 0.0);

	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluOrtho2D(0.0, windowWidth, windowHeight, 0.0);

	// Call random point generator
	inputter();
	switch(pointMode){
		case Spiral:
			generateSpiralPoints();
			break;
		case Random:
			generateRandomPoints();
			break;
		case Grid:
			generateGridPoints();
			break;
		default: break;
	}

	generateVoronoi();

}
예제 #2
0
// Testing random input points.
TEST_F(PointVecTest, TestPointVecCtorRandomPoints)
{
	generateRandomPoints(10000);

	GeoLib::PointVec* point_vec = nullptr;
	ASSERT_NO_THROW(point_vec = new GeoLib::PointVec(name, ps_ptr));

	delete point_vec;
}
예제 #3
0
TEST_F(PointVecTest, TestPointVecCtorRandomPointsLargeEps)
{
	generateRandomPoints(10000);

	GeoLib::PointVec* point_vec = nullptr;
	ASSERT_NO_THROW(point_vec = new GeoLib::PointVec(name, ps_ptr,
					nullptr, GeoLib::PointVec::PointType::POINT, 1e-2));

	delete point_vec;
}
예제 #4
0
//--------------------------------------------------------------
void ofApp::setup(){
    
   //gifEncode setup
    gifEncoder.setup(600,600,.1,255);
    
    
    //rest of setup
    ofSetWindowTitle("ofxVoronoi / example_basic");
    ofBackground(ofColor::fromHsb(ofRandom(255),ofRandom(0,255),220));
    
    ofRectangle bounds = ofRectangle(10, 10, ofGetWidth()-20, ofGetHeight()-20);
    
    int pointCount = ofRandom(200);
    int seed = 33;
    
    scalarPointsVector = generateRandomPoints(pointCount, seed, bounds);
    
    
    voronoi.setBounds(bounds);
    voronoi.setPoints(scalarPointsVector.points);
    
    voronoi.generate();
    
    points.clear();
    
    for(auto cell : voronoi.getCells()) {
        points.push_back(cell.pt);
    }
    
    activateMesh = ofRandom(2);
    diffOrSameColors = ofRandom(3);
    sameSize = ofRandom(3);
    dots = ofRandom(2);
    opCode = ofRandom(11);
    
    cout << "activate Mesh" << activateMesh <<endl;
    
    randColor = ofRandom(255);
    randColor2 = ofRandom(255);
    randSat = ofRandom(255);
    
    counting = 0;
    
    
    

}
예제 #5
0
//--------------------------------------------------------------
void ofApp::setup(){
    ofSetWindowTitle("ofxVoronoi / example_basic");
    ofBackground(255);
    
    ofRectangle bounds = ofRectangle(0, 10, ofGetWidth()-600, ofGetHeight()-20);
    
    int pointCount = 2000;
    int seed = 33;
    
    vector<ofPoint> points = generateRandomPoints(pointCount, seed, bounds);
    
    voronoi.setBounds(bounds);
    voronoi.setPoints(points);
    
    voronoi.generate();
    
    cam.setup(340, 350);
    cam.setDeviceID(0);
    
    
}
예제 #6
0
void init(){



//    glMatrixMode(GL_PROJECTION);
//	glLoadIdentity();
//	gluOrtho2D(0.0, IslandWidth, IslandHeight, 0.0);

	// Call random point generator
	IslandMode = inputter(&pointMode);
	generateRandomPoints(&setPoints, numberofPoints);

	vd = generateVoronoi(&setPoints, numberofPoints);


	// Define elevation
	circlePointCt = terrainInput(elevation, biomesInformation, circleVertices, circleColors, perlinOffsets, pointMode, IslandMode);

	perlinArray = convertToArray(perlinOffsets);

	idx = VoronoiVerticesColors(vd, &voronoiPoints, &voronoiColors);


	// Adjust voronoi points
	voronoiVertices = adjustVoronoi(&voronoiPoints, &voronoiColors, elevation, circleColors, idx);

	// Find coords
	voronoiCoords = findCoords(&voronoiPoints, idx);

	// Find normals
	voronoiNormals = findNormals(voronoiVertices, idx);

	// Initialize shaders
	initShadersVAOS();

}
예제 #7
0
int terrainInput(double elevation[IslandWidth][IslandHeight], Biome biomesInformation[IslandWidth][IslandHeight], double * circleVertices, glm::vec3 circleColor[IslandWidth][IslandHeight], glm::vec3 perlinOffsets[IslandWidth][IslandHeight], Mode pointMode, bool IslandMode){

	int waterIdx;
	int waterLocCount = 15;
	terrain  waterLocations[waterLocCount];
	for(waterIdx = 0; waterIdx < waterLocCount; waterIdx++){
		waterLocations[waterIdx].x = (rand() % (int) IslandWidth) + 1;
//		waterLocations[waterIdx].x = 700;
		waterLocations[waterIdx].y = (rand() % (int) IslandHeight) + 1;
//		waterLocations[waterIdx].y = 600;
		waterLocations[waterIdx].waterValue = 1.0f;
	}


	int circleIdx;

	int * circleLocations;
	int circlesCt;
	double xpos0, xpos1, ypos0, ypos1, r, rmax, myPow;
	rmax = 100; // for circles
	r = 160;

	switch(pointMode){
		case Spiral:
			circlesCt = 180;
			if(IslandMode) circlesCt = 300;
			generateSpiralPoints(&circleLocations, circlesCt);
			break;
		case Random:
			circlesCt = 100;
			if(IslandMode) circlesCt = 300;
			generateRandomPoints(&circleLocations, circlesCt);
			break;
		case Grid:
			circlesCt = 80;
//			r = 100;
			if(IslandMode) circlesCt = 300;
			generateGridPoints(&circleLocations, circlesCt);
			break;
		default: break;
	}
	terrain allIntensity[circlesCt];

	int heightRand;
	int maxHeight = 500;
	int i =0;
	for(circleIdx = 0; circleIdx < circlesCt; circleIdx++){
//		allIntensity[circleIdx].x = (rand() % (int) IslandWidth) + 1;
		allIntensity[circleIdx].x = circleLocations[i++];
//		allIntensity[circleIdx].y = (rand() % (int) IslandHeight) + 1;
		allIntensity[circleIdx].y = circleLocations[i++];
		i++;
		heightRand = (rand() % maxHeight);
		// allIntensity[circleIdx].intensity = 0.2f;
		allIntensity[circleIdx].intensity = ((double) heightRand / maxHeight) * 0.4f;
	}


	double theta = 0;
	int vi = 0, coli = 0;

	double rrand = (rand() % (int) r);

	int x,y;
	i = 0;
	glm::vec2 center;
	glm::vec2 loc;
	center.x = IslandWidth /2;
	center.y = IslandHeight /2;
	double dIslandCtr;

	double distFromCenter;
	for(x = 0; x < IslandWidth; x++){
		for(y = 0; y < IslandHeight; y++){
			loc.x = x;
			loc.y = y;
			dIslandCtr = glm::length(loc -center);
			dIslandCtr /= glm::length(center);
			for(i = 0; i < circlesCt; i++){
//				r = (rand() % (int) (rmax)) + rmax /2;

				distFromCenter = sqrt( (double) pow(allIntensity[i].x - x, 2) + (double) pow(allIntensity[i].y - y, 2));
				distFromCenter = ((distFromCenter / r) > 1) ? 1.0f : (distFromCenter / r);
//				distFromCenter = ((distFromCenter / (r + rrand) ) > 1) ? 1.0f : (distFromCenter / r + rrand);

				if(distFromCenter <= 1.000000f){
					// the further you are, the less intensity, lower elevation

					if((1.0 - distFromCenter) < (1.0 /3.0)){
						myPow = 2;
					} else if((1.0 - distFromCenter) < (2.0 * 1.0 /3.0)){
						myPow = 1;
					} else {
						myPow = 0.5;
					}

					if(IslandMode){
						elevation[x][y] +=  allIntensity[i].intensity * pow(1.0 - distFromCenter, myPow) * pow(1.0 - dIslandCtr, 3);
					} else{
						elevation[x][y] +=  allIntensity[i].intensity * pow(1.0 - distFromCenter, myPow);
					}
				}
				else {
					elevation[x][y] +=  0.0f;
				}
			}

		}
	}


	// Perlin, may or may not be needed
	generatePerlinNoise(perlinOffsets, elevation);

	biomesGeneration(circleColor, elevation, waterLocations, waterLocCount, biomesInformation, IslandMode);

	return IslandWidth * IslandHeight;

}