Skip to content

Commit

Permalink
lcb
Browse files Browse the repository at this point in the history
  • Loading branch information
andrefs committed May 10, 2012
1 parent 65c1517 commit 923c8b8
Showing 1 changed file with 56 additions and 74 deletions.
130 changes: 56 additions & 74 deletions logistic.c
@@ -1,114 +1,96 @@
//////////////////////////////////////////////////////////////////////////////////
// Logistic Map v1.2.c //
// 2007.12.11 //
// Desenha o mapa segundo a função mais geral (tudo de uma vez), //
// permite redimensionamento da janela. Inclui eixos, nao inclui //
// leitura de ficheiro,zoom ou diferentes funçoes //
//////////////////////////////////////////////////////////////////////////////////

// Logistic Map v1.4.c //
// 2007.12.12 //
// Desenha cada ponto de uma vez, mas apaga os anteriores, //
// permite redimensionamento da janela. Nao inclui eixos,leitura //
// de ficheiro,zoom ou diferentes funçoes //
//////////////////////////////////////////////////////////////////////////////////
#include <GL/glut.h>
#include <GL/gl.h>
#include <stdio.h>
#include <math.h>

#define JUMPS 5000
#define OFFSET 50000
#define JUMPS 100
#define OFFSET 500
#define START 2.3
#define END 4.0
#define NUM_PONTOS 50
#define X0 0.5

double r = START;
double x = X0;
int i=0;

double calc(double r, double x){
return (r*x*(1-x));
return 1;
}

/*
double calc(double r, double x){
return (r*sin(x)*(1-sin(x)));
//////////////////////////////////////////////////////////
// Called to draw scene
void RenderScene(void){
// Clear the window with current clearing color
glClear(GL_COLOR_BUFFER_BIT);
// Set current drawing color to red
// R G B
glColor3f(1.0f, 0.0f, 0.0f);
glBegin(GL_POINTS);
glVertex2f(r,x);
glEnd();
// Flush drawing commands and swap
glutSwapBuffers();
}
*/
int itera(int num_pontos, double x0, double r){
long int i;
double x;
x = calc(r, x0);
for (i=0;i<OFFSET;i++){
x = calc(r,x);

///////////////////////////////////////////////////////////
// Called by GLUT library when idle (window not being
// resized or moved)
void TimerFunction(int value){
if (i >= OFFSET+NUM_PONTOS){
i = 0;
x = X0;
r+= (1.0/JUMPS);
}
for (i=OFFSET; i<(OFFSET + num_pontos); i++){
while (i < OFFSET){
x = calc(r,x);
glVertex2d(r,x);
i++;
}
return 1;
}

int draw_logistic(double start, double end, double jumps, int num_pontos, double x0){
double r;
for (r=start; r<end; r+=(1.0/jumps)){
itera(num_pontos, x0, r);
glFlush();
}
return 1;
x = calc(r,x);
i++;
// Redraw the scene with new coordinates
glutPostRedisplay();
glutTimerFunc(1,TimerFunction, 1);
}

int draw_eixos(){
glColor3f(1.0f, .0f, 0.0f);
glBegin(GL_LINES);
//Eixo XX
glVertex2f(START-0.05,0);
glVertex2f(END+0.003,0);
//Eixo YY
glVertex2f(START,-0.05);
glVertex2f(START,1.0);
glEnd();

glBegin(GL_TRIANGLES);
glVertex2f(END, 0.01);
glVertex2f(END, -0.01);
glVertex2f(END+ 0.02, 0);

glColor3f(1.0f, .0f, 0.0f);
glVertex2f(2.29,1.0);
glVertex2f(2.31, 1.0);
glVertex2f(2.3, 1.02);
glEnd();
glFlush();
return 1;
}

void RenderScene(void){
glClear(GL_COLOR_BUFFER_BIT);
draw_eixos();
glColor3f(0.0f, 0.0f, 0.0f);
glBegin(GL_POINTS);
draw_logistic(START, END, JUMPS, NUM_PONTOS, X0);
glEnd();
glFlush();
}

void SetupRC(void){
glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
//////////////////////////////////////////////////////////
// Set up the rendering state
void SetupRC(void)
{
// Set clear color to blue
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
}

///////////////////////////////////////////////////////////
// Called by GLUT library when the window has chanaged size
void ChangeSize(GLsizei w, GLsizei h){
if (h == 0) h = 1;
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho (START-0.1 , END + 0.1 , -0.1, 1.1 , 1.0, -1.0);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}

}
///////////////////////////////////////////////////////////
// Main program entry point
int main(int argc, char* argv[])
{
{
glutInit(&argc, argv);
glutInitWindowSize(1433 , 864); //Define tamanho da janela
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize(1483,864);
glutCreateWindow("Logistic Map");
glutDisplayFunc(RenderScene);
glutReshapeFunc(ChangeSize);
glutTimerFunc(1, TimerFunction, 1);
SetupRC();
glutMainLoop();
return 0;
Expand Down

0 comments on commit 923c8b8

Please sign in to comment.