Just for fun. App below (os x ), spacebar generates a new random image.
/*
* harmonograph.cpp
*
* Created by Brecht Debackere on 02/04/10.
* Copyright 2010 Autofasurer. All rights reserved.
*
*/
#include <GLUT/glut.h>
#include <iostream>
using namespace std;
//initialising variables
float fXpos = 0.0, fYpos = 0.0, fFrequency = 0.0, fAmplitude = 0.0, fPhase = 0.0, fTime = 0.0;
//initialising states
void init()
{
glClearColor(0.0,0.0,0.0,0.7);
glEnable(GL_BLEND);
glBlendFunc(GL_ONE, GL_ONE);
}
//reshaping the viewport and projection
void reshape(int width, int height)
{
glViewport(0, 0, 1024, 768);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(90.,(GLfloat) width/(GLfloat) height,0.1, 800.0);
glMatrixMode(GL_MODELVIEW);
gluLookAt(0.0,0.0,10.0, 0.0, 0.0, 0.0, 0,1,0);
}
//reading the keyboard input
void key(unsigned char key, int x, int y){
switch (key){
case 32:
fFrequency = (rand()%500-250)/5.0;
fPhase = (rand()%500-250)/5.0;
fAmplitude = (rand()%500-250)/5.0;
fTime = 0.0;
break;
}
}
//drawing and displaying
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glBegin(GL_POINTS);
glColor3d(0.2, 0.1, 0.0);
while (fTime < 100.0) {
fXpos = 4*(cos(fFrequency * fTime) + cos(fPhase * fTime)*0.5 + cos(fAmplitude * fTime)*0.33);
fYpos = 4*(sin(fFrequency * fTime) + sin(fPhase * fTime)*0.5 + sin(fAmplitude * fTime)*0.33);
glVertex3f(fXpos, fYpos, 0);
fTime += 0.001;
}
glEnd();
fFrequency -= 0.0001;
fAmplitude += 0.0001;
fPhase += 0.0001;
fTime = 0.0;
glutSwapBuffers();
}
//main loop with initialising of window and glut, assigning functions
int main(int argc, char** argv)
{
srand(time(NULL));
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutGameModeString(”1024×768:32″);
glutEnterGameMode();
init();
glutDisplayFunc(display);
glutIdleFunc(display);
glutReshapeFunc(reshape);
glutKeyboardFunc(key);
glutMainLoop();
return 0;
}
SpirographApp