Unique Color Per Vertex ofPath / ofPolyline?

Hey, I just got my RGB ILDA laser and want to start programming for it. At the moment I want to be able to use an ofPath or ofPolyline to define my shapes and colours to then upload as an ILDA frame.

My problem is, I need to be able to define a unique color per vertex. See below code for an example…

void ofApp::setup(){

path.moveTo(20,20);
path.setStrokeColor(ofColor::blue);
path.lineTo(40,20);
path.setStrokeColor(ofColor::red);
path.lineTo(40,40);
path.setStrokeColor(ofColor::green);
path.lineTo(20,40);
path.setStrokeColor(ofColor::yellow);
path.close();
path.setFilled(false);
path.setStrokeWidth(2);
path.scale(10, 10);

}

void ofApp::draw(){
path.draw();

}

What I hoped this would do would colour each vertex a separate color but instead all vertices are coloured yellow in this example. In Cinder there is a class called ColouredShape2d that looks very similar to ofPath that lets you achieve this type of functionality. Is there any way to achieve this in oF.

I realise I can do this with an ofMesh and shaders etc but I need it to stay in ofPolyline / ofPath land in order to use the ofxILDA laser addon. Any tips would be greatly appreciated.

Thanks.

Hi there.

I’m not able to help you, but I remembered that a few days ago, arturo mentioned that ofPath does not support gradients, in relation to a cairo issue. Source follows:

yes, we don’t have support for color coordinates yet in ofPath. a quick hack i guess would be to have a vector of ofPath and continue from one into another by using moveTo in the next path and adding new paths as you need new colors. Having the possibility to add colors to each primitive would be great though. I imagine we can have versions of each command with an aditional color variable and ofPath could have an additional method for each primitive with one more argument for the color. then when decomposing or tesselating we would add the colors to the ofMesh as color coordinates or set the correct color for each polyline

Thanks Hubris and Arturo… I figured this might have been the case. Can imagine it would be super handy to be able to color each vertex of an ofPath but using a vector of ofPath’s or ofPolylines seems to be a work around for now while allowing me achieve the functionality i’m after. Time to keep hacking my laser :smiling_imp:

Is this different in 0.9.7? Trying to apply a taper to a ofPolyline but can’t seem to figure out the appropriate way.

no it’s still the same, there’s no direct way to use different colors per vertex when drawing a polyline or path, the easiest is probably to get the vertices, put them in an ofMesh/ofVboMesh and add the diferent colors in the mesh, one per vertex

Hi @arturo
I am having trouble with this. I am trying to get a coloured curved mesh of the pixels from a videograbber.
How would you assign the colours of the indices

here is one of the things I’ve tried so far. This one crashes with this error
::new((void*)__p) _Up(_VSTD::forward<_Args>(__args)...); (which I believe relates to the memory access?)

for (int y=0; y<h; y+=dist) {
        for (int x=0; x<w; x+=dist) {

            poly.curveTo(x-gap*co, y-gap*si, 100*br );
            mesh.addVertex(poly.getVertices()[y*x]);
            mesh.addColor(ofColor(r,g,b));

  }
}

I’ve also tried this code here but gets a bad access to the index.

for (int y=0; y<h; y+=dist) {
            for (int x=0; x<w; x+=dist) {

                mesh.addVertex(x-gap*co, y-gap*si, 100*br);
                mesh.addColor(ofColor(r,g,b));
                poly.curveTo(x-gap*co, y-gap*si, 100*br );
      }
    }

    meshB.addVertices(poly.getVertices());
    for (int i = 0; i<meshB.getNumVertices(); i++) {
        meshB.setIndex(i, mesh.getIndex(i));
        meshB.addColor(mesh.getColor(i));
    }

Any hint for this?

Thank you!