void ContinuousPathApp::drawCurves(cairo::Context &ctx, Path2d path, float thickness, Color col) { ctx.setLineWidth(thickness); ctx.setSource(col); ctx.newSubPath(); int pointIndex = 0; for (int i=0; i<path.getNumSegments(); i++) { int segType = path.getSegmentType(i); // change jumpIndex depending on the type of segment switch(segType){ case Path2d::CUBICTO: if(i==0) ctx.moveTo(path.getPoint(pointIndex)); // do a curve to using the next 2 points as the curves and the 3rd as the end point ctx.curveTo(path.getPoint(pointIndex+1), path.getPoint(pointIndex+2), path.getPoint(pointIndex+3)); pointIndex += 3; break; case Path2d::MOVETO: // don't do anything with this point ctx.moveTo(path.getPoint(pointIndex)); pointIndex += 0; break; default: pointIndex += 1; break; } } ctx.stroke(); }
void PathSimplificationApp::drawLine(cairo::Context &ctx, Vec2f const &pt1, Vec2f const &pt2, float thickness, Color col) { ctx.setLineWidth(thickness); ctx.setSource(col); ctx.newSubPath(); ctx.moveTo(pt1.x, pt1.y); ctx.lineTo(pt2.x, pt2.y); ctx.closePath(); ctx.stroke(); }
void makePath( cairo::Context &ctx ) const { for( int petal = 0; petal < mNumPetals; ++petal ) { ctx.newSubPath(); float petalAngle = ( petal / (float)mNumPetals ) * 2 * M_PI; Vec2f outsideCircleCenter = mLoc + Vec2f::xAxis() * cos( petalAngle ) * mRadius + Vec2f::yAxis() * sin( petalAngle ) * mRadius; Vec2f insideCircleCenter = mLoc + Vec2f::xAxis() * cos( petalAngle ) * mPetalInsideRadius + Vec2f::yAxis() * sin( petalAngle ) * mPetalInsideRadius; ctx.arc( outsideCircleCenter, mPetalOutsideRadius, petalAngle + M_PI / 2 + M_PI, petalAngle + M_PI / 2 ); ctx.arc( insideCircleCenter, mPetalInsideRadius, petalAngle + M_PI / 2, petalAngle + M_PI / 2 + M_PI ); ctx.closePath(); } }
void ContinuousPathApp::drawCircle(cairo::Context &ctx, Vec2f const &pt, double diameter, Color col, bool outline) { ctx.setLineWidth(1); ctx.setSource( col ); ctx.newSubPath(); ctx.circle( pt.x, pt.y, diameter ); ctx.closePath(); if(outline){ ctx.stroke(); }else{ ctx.fill(); } }