added chaos / iterative algorithm
git-svn-id: svn://anubis/misc/sierpinski-gtk@250 bd8a9e45-a331-0410-811e-c64571078777
This commit is contained in:
parent
78734bad16
commit
ba473756ff
@ -1,4 +1,5 @@
|
|||||||
|
|
||||||
|
#include <stdlib.h> /* rand() */
|
||||||
#include <GL/gl.h>
|
#include <GL/gl.h>
|
||||||
#include <GL/glu.h>
|
#include <GL/glu.h>
|
||||||
|
|
||||||
@ -32,11 +33,22 @@ void SierpinskiDA::regenerate(int npts)
|
|||||||
|
|
||||||
gl_begin();
|
gl_begin();
|
||||||
glNewList(m_dl, GL_COMPILE);
|
glNewList(m_dl, GL_COMPILE);
|
||||||
glBegin(GL_LINE_LOOP);
|
glBegin(GL_POINTS);
|
||||||
|
|
||||||
for (int i = 0; i < 4; i++)
|
double pt[3];
|
||||||
|
double r = rand() / RAND_MAX;
|
||||||
|
for (int i = 0; i < 3; i++)
|
||||||
{
|
{
|
||||||
glVertex3fv(pts[i]);
|
pt[i] = pts[0][i] + r * pts[1][i] - pts[0][i];
|
||||||
|
}
|
||||||
|
for (int i = 0; i < npts; i++)
|
||||||
|
{
|
||||||
|
glVertex3dv(pt);
|
||||||
|
int pt_idx = rand() & 0x3;
|
||||||
|
for (int j = 0; j < 3; j++)
|
||||||
|
{
|
||||||
|
pt[j] = (pt[j] + pts[pt_idx][j]) / 2.0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
glEnd();
|
glEnd();
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
|
|
||||||
|
#include <time.h> /* time() */
|
||||||
|
#include <stdlib.h> /* srand() */
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include <gtkmm/main.h>
|
#include <gtkmm/main.h>
|
||||||
@ -33,6 +36,8 @@ int main(int argc, char * argv[])
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
srand(time(NULL));
|
||||||
|
|
||||||
Gtk::Window mw;
|
Gtk::Window mw;
|
||||||
mw.set_default_size(400, 420);
|
mw.set_default_size(400, 420);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user