Skip to content

Instantly share code, notes, and snippets.

@ThomasLengeling
Created August 8, 2014 23:33
Show Gist options
  • Save ThomasLengeling/cc710d1007ed544f67b7 to your computer and use it in GitHub Desktop.
Save ThomasLengeling/cc710d1007ed544f67b7 to your computer and use it in GitHub Desktop.
Tree
#include "cinder/app/AppNative.h"
#include "cinder/gl/gl.h"
#include "cinder/params/Params.h"
using namespace ci;
using namespace ci::app;
using namespace std;
class FractalArbolApp : public AppNative {
public:
void setup();
void mouseDown(MouseEvent event);
void update();
void draw();
void branch(float len, float angle);
float len;
int angle;
int h;
int w;
ci::params::InterfaceGlRef mParam;
};
void FractalArbolApp::branch(float len, float angle)
{
//Tronco
gl::color(1, 0, 0);
gl::drawLine(ci::Vec2f(0, 0), ci::Vec2f(0, -len));
gl::translate(ci::Vec2f(0, -len));
if (len<20) {
return;
}
else {
//Rama izquierda
gl::pushMatrices();
gl::rotate(angle);
branch(len*0.7, angle);
gl::popMatrices();
//Rama Derecha
gl::pushMatrices();
gl::rotate(-angle);
branch(len*0.7, angle);
gl::popMatrices();
}
}
void FractalArbolApp::setup()
{
mParam = ci::params::InterfaceGl::create(getWindow(), "Arbol Fractal", ci::Vec2i(200, 200));
mParam->addParam("len", &len, "");
mParam->addParam("angle", &angle, "");
h = 768;
w = 1024;
len = 100;
angle = 20;
setWindowSize(w, h);
setWindowPos(500, 200);
}
void FractalArbolApp::mouseDown(MouseEvent event)
{
}
void FractalArbolApp::update()
{
}
void FractalArbolApp::draw()
{
//gl::clear(Color(1,1,1));
gl::enableAlphaBlending();
gl::color(1, 1, 1, 1);
gl::drawSolidRect(getWindowBounds());
gl::pushMatrices();
gl::translate(ci::Vec2f(w / 2, h));
branch(len, angle);
gl::popMatrices();
mParam->draw();
}
CINDER_APP_NATIVE(FractalArbolApp, RendererGl)
@ThomasLengeling
Copy link
Author

Solo necesitabas el gl::pushMatrix() y gl::popMatrix() entre el translate, le anadi el angulo tambien a la funciona para entender mejor la fucion

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment