Create a gist now

Instantly share code, notes, and snippets.

@gavinmyers /goop.c
Last active Dec 10, 2015

What would you like to do?
playing around, this is very broken
#include <GL/glut.h>
#define GOOP_WIDTH 1000
#define GOOP_HEIGHT 1000
static GLubyte GoopImage[GOOP_WIDTH][GOOP_HEIGHT][3];
void goop(void) {
int i, j, k;
for (i = 2; i < GOOP_HEIGHT-2; i++) {
for (j = 10; j < GOOP_WIDTH-25; j++) {
for (k = 0; k < 3; k++) {
int r = 0;
r += GoopImage[i-1][j-1][k];
r += GoopImage[i-0][j-1][k];
r += GoopImage[i+1][j-1][k];
r = r / 3;
if(r > 180) {
GoopImage[i+1][j+1][k] = r;
} else if (r > 65) {
GoopImage[i-1][j-1][k] = r;
} else {
GoopImage[i+0][j-0][k] = r;
}
}
}
}
}
void initGoop(void) {
int i, j, c;
for (i = 0; i < GOOP_HEIGHT; i++)
for (j = 0; j < GOOP_WIDTH; j++) {
GoopImage[i][j][0] = (GLubyte) rand() % 255;
GoopImage[i][j][1] = (GLubyte) rand() % 255;
GoopImage[i][j][2] = (GLubyte) rand() % 255;
}
}
void init() {
glClearColor(0.0, 0.0, 0.0, 0.0);
glShadeModel(GL_FLAT);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
}
void display() {
//glClear(GL_COLOR_BUFFER_BIT);
glRasterPos2i(0, 0);
goop();
for(int i = 0; i < 100; i++) {
int sx = rand()%(GOOP_WIDTH-25);
int sy = rand()%(GOOP_HEIGHT-25);
for(int x1 = 0; x1 < rand() % 20; x1++) {
for(int y1 = 0; y1 < rand() % 20; y1++) {
int r = rand()%255;
int g = rand()%255;
int b = rand()%255;
GoopImage[sx+x1][sy+y1][0] = (GLubyte) r;
GoopImage[sx+x1][sy+y1][1] = (GLubyte) g;
GoopImage[sx+x1][sy+y1][2] = (GLubyte) b;
}
}
}
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glDrawPixels(GOOP_WIDTH, GOOP_HEIGHT, GL_RGB, GL_UNSIGNED_BYTE, GoopImage);
glFlush();
glutSwapBuffers();
glutPostRedisplay();
}
void reshape(int w, int h) {
gluOrtho2D(0.0f, 0.0f, w, h);
glViewport(0, 0, w/32, h/32);
}
int main(int argc, char **argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB);
glutInitWindowSize (640, 480);
glutCreateWindow(argv[0]);
glutDisplayFunc(display);
glutReshapeFunc(reshape);
init();
initGoop();
glutMainLoop();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment