How to color a shape created manually with curves?

Hi everyone,

First, sorry for my bad English :slight_smile:

I have a question about a code I actually write.

I need to create some kinds of forms with curves. I stored all points necessary to draw my curve in a vector and I use the ofDrawCurve() function to draw on the screen. I have this code :


Where vec = vector with points for each curve and i = index to get the curve in the vector.

This code seems to work perfectly and draw curves at the screen, but I need to color the generate shape. I try to use ofSetColor(), but it doesn’t work. Only contour lines are colored with the selected value, but the created shape is not filled. I don’t use ofNoFill() function, so I’m a little bit confused.

Any help will be greatly appreciated.

Thanks in advance!

Hey Antineta,

It looks like you’re confusing two different ways of drawing curves. ofDrawCurve() will draw a curve based on the 4 XY pairs you pass to it. That method doesn’t need the ofBeginShape()/ofEndShape().

What you want to do is use either ofCurveVertex() or ofBezierVertex() in between the begin/end shape calls. They draw a little differently but the bezier one uses control points similar to ofDrawCurve(). Then you can call ofEndShape(true) to specify the shape as closed. Not sure if this will just close the shape or actually fill it so try it out.

Alternatively you can use the ofPolyline or ofPath classes. Great for doing this kind of thing and has lots of extra features built in on top of being similar to the begin/addVertex/end workflow. Definitely the better choice.

Thanks, I will try this!