Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@andrewfb
Created February 20, 2012 23:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewfb/1872308 to your computer and use it in GitHub Desktop.
Save andrewfb/1872308 to your computer and use it in GitHub Desktop.
Convert a cinder::Shape2d into C++ code that generates its equivalent
void outputCinderCode( const Shape2d &shape, const std::string &name )
{
app::console() << "Shape2d " << name << ";" << std::endl;
for( vector<Path2d>::const_iterator pathIt = shape.getContours().begin(); pathIt != shape.getContours().end(); ++pathIt ) {
app::console() << name << ".appendContour( Path2d() );" << std::endl;
size_t pt = 0;
app::console() << name << ".getContours().back().moveTo( " << pathIt->getPoints()[0].x << ", " << pathIt->getPoints()[0].y << " );" << std::endl;
pt++;
for( std::vector<Path2d::SegmentType>::const_iterator segIt = pathIt->getSegments().begin(); segIt != pathIt->getSegments().end(); ++segIt ) {
if( *segIt == Path2d::CLOSE )
app::console() << name << ".getContours().back().close();" << std::endl;
else if( *segIt == Path2d::LINETO )
app::console() << name << ".getContours().back().lineTo( " << pathIt->getPoints()[pt].x << ", " << pathIt->getPoints()[pt].y << " );" << std::endl;
else if( *segIt == Path2d::QUADTO )
app::console() << name << ".getContours().back().quadTo( " << pathIt->getPoints()[pt].x << ", " << pathIt->getPoints()[pt].y << ", " <<
pathIt->getPoints()[pt+1].x << ", " << pathIt->getPoints()[pt+1].y << " );" << std::endl;
else if( *segIt == Path2d::CUBICTO )
app::console() << name << ".getContours().back().curveTo( " << pathIt->getPoints()[pt].x << ", " << pathIt->getPoints()[pt].y << ", " <<
pathIt->getPoints()[pt+1].x << ", " << pathIt->getPoints()[pt+1].y << ", " <<
pathIt->getPoints()[pt+2].x << ", " << pathIt->getPoints()[pt+2].y << " );" << std::endl;
pt += Path2d::sSegmentTypePointCounts[*segIt];
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment