Skip to content

Commit

Permalink
trim samples/
Browse files Browse the repository at this point in the history
  • Loading branch information
dimateos committed Feb 4, 2025
1 parent 05b1116 commit 9e381c9
Show file tree
Hide file tree
Showing 224 changed files with 18,663 additions and 18,687 deletions.
6 changes: 3 additions & 3 deletions samples/ArcballDemo/src/ArcballDemoApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ using namespace ci;
using namespace ci::app;

class ArcballDemoApp : public App {
public:
public:
void setup() override;
void resize() override;
void mouseDown( MouseEvent event ) override;
void mouseDrag( MouseEvent event ) override;
void draw() override;

Arcball mArcball;
CameraPersp mCamera;

Sphere mEarthSphere;
gl::BatchRef mEarth;
gl::TextureRef mEarthTex;
Expand Down
20 changes: 10 additions & 10 deletions samples/BSpline/src/BSplineApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ using std::vector;
class BSplineApp : public App {
public:
BSplineApp() : mTrackedPoint( -1 ), mDegree( 3 ), mOpen( true ), mLoop( false ) {}

int findNearestPt( const vec2 &aPt );
void calcLength();

void mouseDown( MouseEvent event ) override;
void mouseUp( MouseEvent event ) override;
void mouseDrag( MouseEvent event ) override;
Expand Down Expand Up @@ -97,7 +97,7 @@ int BSplineApp::findNearestPt( const vec2 &aPt )
{
if( mPoints.empty() )
return -1;

int result = 0;
float nearestDist = distance( mPoints[0], aPt );
for( size_t i = 1; i < mPoints.size(); ++i ) {
Expand All @@ -106,7 +106,7 @@ int BSplineApp::findNearestPt( const vec2 &aPt )
nearestDist = distance( mPoints[i], aPt );
}
}

return result;
}

Expand Down Expand Up @@ -135,7 +135,7 @@ void BSplineApp::draw()
cairo::Context ctx( cairo::createWindowSurface() );
ctx.setSourceRgb( 0.0f, 0.1f, 0.2f );
ctx.paint();

// draw the control points
ctx.setSourceRgb( 1.0f, 1.0f, 0.0f );
for( size_t p = 0; p < mPoints.size(); ++p ) {
Expand All @@ -152,22 +152,22 @@ void BSplineApp::draw()
ctx.moveTo( spline.getPosition( 0 ) );
for( float t = 0; t < 1.0f; t += 0.001f )
ctx.lineTo( spline.getPosition( t ) );

ctx.stroke();

// draw points 1/4, 1/2 and 3/4 along the length
ctx.setSourceRgb( 0.0f, 0.7f, 1.0f );
float totalLength = spline.getLength( 0, 1 );
for( float p = 0.25f; p < 0.99f; p += 0.25f ) {
ctx.newSubPath();
ctx.arc( spline.getPosition( spline.getTime( p * totalLength ) ), 2.5f, 0, 2 * 3.14159f );
}
}

ctx.stroke();
}

// draw the curve by bezier path
drawBSpline( ctx );
drawBSpline( ctx );
}

CINDER_APP( BSplineApp, Renderer2d )
2 changes: 1 addition & 1 deletion samples/BasicApp/src/BasicApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ void BasicApp::keyDown( KeyEvent event )
void BasicApp::draw()
{
// Clear the contents of the window. This call will clear
// both the color and depth buffers.
// both the color and depth buffers.
gl::clear( Color::gray( 0.1f ) );

// Set the current draw color to orange by setting values for
Expand Down
12 changes: 6 additions & 6 deletions samples/BasicAppMultiWindow/src/BasicAppMultiWindowApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class BasicAppMultiWindow : public App {
public:
void setup();
void createNewWindow();

void mouseDrag( MouseEvent event );
void keyDown( KeyEvent event );
void draw();
Expand All @@ -25,7 +25,7 @@ class WindowData {
WindowData()
: mColor( Color( CM_HSV, randFloat(), 0.8f, 0.8f ) ) // a random color
{}

Color mColor;
list<vec2> mPoints; // the points drawn into this window
};
Expand All @@ -34,15 +34,15 @@ void BasicAppMultiWindow::setup()
{
// for the default window we need to provide an instance of WindowData
getWindow()->setUserData( new WindowData );

createNewWindow();
}

void BasicAppMultiWindow::createNewWindow()
{
app::WindowRef newWindow = createWindow( Window::Format().size( 400, 400 ) );
newWindow->setUserData( new WindowData );

// for demonstration purposes, we'll connect a lambda unique to this window which fires on close
int uniqueId = getNumWindows();
newWindow->getSignalClose().connect(
Expand All @@ -53,7 +53,7 @@ void BasicAppMultiWindow::createNewWindow()
void BasicAppMultiWindow::mouseDrag( MouseEvent event )
{
WindowData *data = getWindow()->getUserData<WindowData>();

// add this point to the list
data->mPoints.push_back( event.getPos() );
}
Expand All @@ -72,7 +72,7 @@ void BasicAppMultiWindow::draw()

WindowData *data = getWindow()->getUserData<WindowData>();

gl::color( data->mColor );
gl::color( data->mColor );
gl::begin( GL_LINE_STRIP );
for( auto pointIter = data->mPoints.begin(); pointIter != data->mPoints.end(); ++pointIter ) {
gl::vertex( *pointIter );
Expand Down
32 changes: 16 additions & 16 deletions samples/BezierPath/src/BezierPathApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ using namespace std;
class Path2dApp : public App {
public:
Path2dApp() : mTrackedPoint( -1 ) {}

void mouseDown( MouseEvent event );
void mouseUp( MouseEvent event );
void mouseDrag( MouseEvent event );
void keyDown( KeyEvent event );
void draw();

Path2d mPath;
int mTrackedPoint;
};

void Path2dApp::mouseDown( MouseEvent event )
{
{
if( event.isLeftDown() ) { // line
if( mPath.empty() ) {
mPath.moveTo( event.getPos() );
Expand All @@ -34,7 +34,7 @@ void Path2dApp::mouseDown( MouseEvent event )
mPath.lineTo( event.getPos() );
}

console() << mPath << std::endl;
console() << mPath << std::endl;
console() << "Length: " << mPath.calcLength() << std::endl;
}

Expand All @@ -48,9 +48,9 @@ void Path2dApp::mouseDrag( MouseEvent event )
vec2 endPt = mPath.getPoint( mPath.getNumPoints() - 1 );
// and now we'll delete that line and replace it with a curve
mPath.removeSegment( mPath.getNumSegments() - 1 );
Path2d::SegmentType prevType = ( mPath.getNumSegments() == 0 ) ? Path2d::MOVETO : mPath.getSegmentType( mPath.getNumSegments() - 1 );

Path2d::SegmentType prevType = ( mPath.getNumSegments() == 0 ) ? Path2d::MOVETO : mPath.getSegmentType( mPath.getNumSegments() - 1 );

if( event.isShiftDown() || prevType == Path2d::MOVETO ) { // add a quadratic curve segment
mPath.quadTo( event.getPos(), endPt );
}
Expand All @@ -69,16 +69,16 @@ void Path2dApp::mouseDrag( MouseEvent event )
}
else
tan1 = mPath.getPoint( mPath.getNumPoints() - 1 );

mPath.curveTo( tan1, event.getPos(), endPt );
}

// our second-to-last point is the tangent next to the end, and we'll track that
mTrackedPoint = mPath.getNumPoints() - 2;
}

console() << mPath << std::endl;
console() << "Length: " << mPath.calcLength() << std::endl;
console() << "Length: " << mPath.calcLength() << std::endl;
}

void Path2dApp::mouseUp( MouseEvent event )
Expand All @@ -95,7 +95,7 @@ void Path2dApp::keyDown( KeyEvent event )
void Path2dApp::draw()
{
gl::clear( Color( 0.0f, 0.1f, 0.2f ) );

// draw the control points
gl::color( Color( 1, 1, 0 ) );
for( size_t p = 0; p < mPath.getNumPoints(); ++p )
Expand All @@ -110,13 +110,13 @@ void Path2dApp::draw()
// draw the curve itself
gl::color( Color( 1.0f, 0.5f, 0.25f ) );
gl::draw( mPath );
if( mPath.getNumSegments() > 1 ) {

if( mPath.getNumSegments() > 1 ) {
// draw some tangents
gl::color( Color( 0.2f, 0.9f, 0.2f ) );
gl::color( Color( 0.2f, 0.9f, 0.2f ) );
for( float t = 0; t < 1; t += 0.2f )
gl::drawLine( mPath.getPosition( t ), mPath.getPosition( t ) + normalize( mPath.getTangent( t ) ) * 80.0f );

// draw circles at 1/4, 2/4 and 3/4 the length
gl::color( ColorA( 0.2f, 0.9f, 0.9f, 0.5f ) );
for( float t = 0.25f; t < 1.0f; t += 0.25f )
Expand Down
16 changes: 8 additions & 8 deletions samples/BezierPathIteration/src/BezierPathIterationApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@ class BezierPathIterationApp : public App {
void loadSvg( const fs::path &fsPath );
void fileDrop( FileDropEvent event ) override;
void draw() override;

struct PathIter {
PathIter( const Path2dCalcCache& pathCache, float initialDistance )
: mPathCache( pathCache ), mCurrentDistance( initialDistance )
{
mLastPos = mPathCache.getPosition( mPathCache.calcTimeForDistance( mCurrentDistance ) );
}

const Path2dCalcCache& mPathCache;
vec2 mLastPos;
float mCurrentDistance;
};

vec2 mWindowOffset, mWindowScale;
vector<Path2dCalcCache> mPathCaches;
// each path iterator has a reference to its path(cache) and its current position
Expand All @@ -56,19 +56,19 @@ void BezierPathIterationApp::loadSvg( const fs::path &fsPath )
// make a Path2dCalcCache for each path in the SVG
for( auto &path : paths )
mPathCaches.emplace_back( path );

// Fit the SVG to the window
gl::setMatricesWindow( getWindowSize() );
Rectf svgBounds = shape.calcPreciseBoundingBox();
Rectf fitRect = svgBounds.getCenteredFit( Rectf( getWindowBounds() ), false );
mWindowOffset = ( getWindowSize() - ivec2(fitRect.getSize()) ) / 2;
mWindowScale = fitRect.getSize() / svgBounds.getSize();

// Generate 2000 PathIters, all assigned to random paths and random points along their respective paths
for( int i = 0; i < 2000; ++i ) {
const Path2dCalcCache &pathCache = mPathCaches[randInt(mPathCaches.size())];
mPathIters.emplace_back( pathCache, randFloat() * pathCache.getLength() );
}
}
}

void BezierPathIterationApp::fileDrop( FileDropEvent event )
Expand All @@ -79,7 +79,7 @@ void BezierPathIterationApp::fileDrop( FileDropEvent event )
void BezierPathIterationApp::draw()
{
// clear out the window with black
gl::clear( Color( 0, 0, 0 ) );
gl::clear( Color( 0, 0, 0 ) );

// center and scale the drawing
gl::setMatricesWindow( getWindowSize() );
Expand All @@ -91,7 +91,7 @@ void BezierPathIterationApp::draw()
pathIt.mCurrentDistance += 3.0f; // move 3 units along the path
float newTime = pathIt.mPathCache.calcTimeForDistance( pathIt.mCurrentDistance );
vec2 pos = pathIt.mPathCache.getPosition( newTime );

gl::drawLine( pathIt.mLastPos, pos );
pathIt.mLastPos = pos;
}
Expand Down
24 changes: 12 additions & 12 deletions samples/CairoBasic/src/CairoBasicApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,22 @@ class Flower {
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 draw( cairo::Context &ctx ) const
{
// draw the solid petals
ctx.setSource( mColor );
makePath( ctx );
ctx.fill();

// draw the petal outlines
ctx.setSource( mColor * 0.8f );
makePath( ctx );
ctx.stroke();
};

private:
vec2 mLoc;
float mRadius, mPetalOutsideRadius, mPetalInsideRadius;
Expand All @@ -56,12 +56,12 @@ class CairoBasicApp : public App {
void keyDown( KeyEvent event );
void renderScene( cairo::Context &ctx );
void draw();

vector<Flower> mFlowers;
};

void CairoBasicApp::mouseDown( MouseEvent event )
{
{
// create a new flower
float radius = randFloat( 60, 90 );
int numPetals = randInt( 6, 50 );
Expand Down Expand Up @@ -89,30 +89,30 @@ void CairoBasicApp::keyDown( KeyEvent event )
else if( event.getChar() == 'p' ) {
cairo::Context ctx( cairo::SurfacePs( getHomeDirectory() / "CairoBasicShot.ps", getWindowWidth(), getWindowHeight() ) );
renderScene( ctx );
}
}
else if( event.getChar() == 'd' ) {
cairo::Context ctx( cairo::SurfacePdf( getHomeDirectory() / "CairoBasicShot.pdf", getWindowWidth(), getWindowHeight() ) );
renderScene( ctx );
}
}
}

void CairoBasicApp::renderScene( cairo::Context &ctx )
{
// clear the context with our radial gradient
cairo::GradientRadial radialGrad( getWindowCenter(), 0, getWindowCenter(), getWindowWidth() );
radialGrad.addColorStop( 0, Color( 1, 1, 1 ) );
radialGrad.addColorStop( 1, Color( 0.6, 0.6, 0.6 ) );
ctx.setSource( radialGrad );
radialGrad.addColorStop( 1, Color( 0.6, 0.6, 0.6 ) );
ctx.setSource( radialGrad );
ctx.paint();

for( vector<Flower>::const_iterator flIt = mFlowers.begin(); flIt != mFlowers.end(); ++flIt )
flIt->draw( ctx );
}

void CairoBasicApp::draw()
{
// render the scene straight to the window
cairo::Context ctx( cairo::createWindowSurface() );
cairo::Context ctx( cairo::createWindowSurface() );
renderScene( ctx );
}

Expand Down
Loading

0 comments on commit 9e381c9

Please sign in to comment.