/ Published in: C++
URL: http://www.autofasurer.net/wp/
GLUT / OpenGL / C++ (although not much happening there). The finished app is available at the above link. Haven't tested on anything but my own Macbook Pro, so use at your own risk :)
Expand |
Embed | Plain Text
/* * 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 fRed = 1.0, fGreen = 1.0, fBlue =1.0, fXpos = 0.0, fYpos = 0.0, fFrequency = 0.0, fAmplitude = 0.0, fPhase = 0.0, fTime = 0.0, fPointsize = 1.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, 1440, 900); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45.,(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_LINE_STRIP); while (fTime < 400.0) { glColor3d(fRed, fGreen, fBlue); 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.002; } glEnd(); fFrequency -= 0.0001; fAmplitude += 0.0001; fPhase += 0.0001; fTime = 0.0; glutSwapBuffers(); fRed = (rand()%100)/400.0; fGreen = (rand()%100)/400.0; fBlue = (rand()%100)/400.0; } //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("1440x900:32"); glutEnterGameMode(); init(); glutDisplayFunc(display); glutIdleFunc(display); glutReshapeFunc(reshape); glutKeyboardFunc(key); glutMainLoop(); return 0; }
You need to login to post a comment.
