void ofxNDCircularGradient(float radius, const ofColor & start, const ofColor & end)
{
    int n = 32; // circular gradient resolution
    static ofMesh _nd_cg_mesh;

    _nd_cg_mesh.clear();
    _nd_cg_mesh.setMode(OF_PRIMITIVE_TRIANGLE_FAN);
    
    ofVec2f center(0,0);
    _nd_cg_mesh.addVertex(center);

    float angleBisector = TWO_PI / (n * 2);
    float smallRadius = radius;
    float bigRadius = smallRadius / cos(angleBisector);
    for(int i = 0; i <= n; i++) {
        float theta = i * TWO_PI / n;
        _nd_cg_mesh.addVertex(center + ofVec2f(sin(theta), cos(theta)) * bigRadius);
    }
    
    _nd_cg_mesh.clearColors();
    _nd_cg_mesh.addColor(start);
    for(int i = 0; i <= n; i++) {
        _nd_cg_mesh.addColor(end);
    }
    
    _nd_cg_mesh.draw();
}
Beispiel #2
0
void faceColorToTexture(ofMesh& mesh, ofImage& image)
{
	vector<ofFloatColor> &color = mesh.getColors();
	int num_face = color.size() / 3;
	
	int tex_size = ofNextPow2(ceil(sqrt(num_face)));
	
	bool arb = ofGetUsingArbTex();
	ofDisableArbTex();
	image.allocate(tex_size, tex_size, OF_IMAGE_COLOR);
	if (arb) ofEnableArbTex();
	
	mesh.clearTexCoords();
	
	image.getPixelsRef().set(0);
	
	float texel_size = (1. / image.getWidth()) * 0.5;
	
	for (int i = 0; i < num_face; i++)
	{
		int u = (i % tex_size);
		int v = (i / tex_size);
		
		ofColor c = color[i * 3];
		
		image.setColor(u, v, c);
		
		float uu = (float)u / image.getWidth() + texel_size;
		float vv = (float)v / image.getHeight() + texel_size;
		
		mesh.addTexCoord(ofVec2f(uu, vv));
		mesh.addTexCoord(ofVec2f(uu, vv));
		mesh.addTexCoord(ofVec2f(uu, vv));
	}
	
	image.update();
	mesh.clearColors();
}