Skip to content

Instantly share code, notes, and snippets.

@Craigson
Created January 2, 2015 21:23
Show Gist options
  • Select an option

  • Save Craigson/66fd314b9bc25db11ed0 to your computer and use it in GitHub Desktop.

Select an option

Save Craigson/66fd314b9bc25db11ed0 to your computer and use it in GitHub Desktop.
Cinder Baic Animation
#include "cinder/app/AppNative.h"
#include "cinder/gl/gl.h"
#include "cinder/Rand.h"
#define CIRCLE_COUNT 100;
using namespace ci;
using namespace ci::app;
using namespace std;
class BasicAnimationApp : public AppNative {
public:
void setup();
void mouseDown( MouseEvent event );
void update();
void draw();
void prepareSettings(Settings *settings);
Vec2f currentPos [CIRCLE_COUNT];
Vec2f targetPos [CIRCLE_COUNT];
float rad [CIRCLE_COUNT];
};
void BasicAnimationApp::prepareSettings(Settings *settings){
settings->setWindowSize(800,600);
settings->setFrameRate(60);
}
void BasicAnimationApp::setup()
{
for (int i = 0; i<CIRCLE_COUNT; i++){
currentPos[i].x = Rand::randFloat(0, getWindowWidth());
currentPos[i].y = Rand::randFloat(0, getWindowHeight());
targetPos[i].x = Rand::randFloat(0, getWindowWidth());
targetPos[i].y = Rand::randFloat(0, getWindowHeight());
rad[i] = Rand::randFloat(5,25);
}
}
void BasicAnimationApp::mouseDown( MouseEvent event )
{
}
void BasicAnimationApp::update()
{
Vec2f difference;
for (int i =0; i < CIRCLE_COUNT; i ++){
difference = targetPos[i] - currentPos[i];
difference *= 0.98f;
currentPos[i] = targetPos[i] - difference;
if (currentPos[i].distance(targetPos[i]) < 1.0f){
targetPos[i].x = Rand::randFloat(0, getWindowWidth());
targetPos[i].y = Rand::randFloat(0, getWindowHeight());
}
}
}
void BasicAnimationApp::draw()
{
// clear out the window with black
gl::clear( Color( 0, 0, 0 ) );
for (int i = 0; i < CIRCLE_COUNT; i++){
gl::drawSolidCircle(currentPos[i],rad[i]);
}
}
CINDER_APP_NATIVE( BasicAnimationApp, RendererGl )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment