Skip to content

Instantly share code, notes, and snippets.

@neuro-sys
Created May 3, 2011 15:04
Show Gist options
  • Save neuro-sys/953491 to your computer and use it in GitHub Desktop.
Save neuro-sys/953491 to your computer and use it in GitHub Desktop.
sinusoid shit
#include <SDL/SDL.h>
#include <SDL/SDL_draw.h>
#include <stdio.h>
#include <math.h>
SDL_Surface* screen;
Uint8 *keys;
int done;
int main(int argc, char *argv[])
{
SDL_Init(SDL_INIT_EVERYTHING);
atexit(SDL_Quit);
screen = SDL_SetVideoMode(800, 600, 32, SDL_SWSURFACE);
keys = SDL_GetKeyState(NULL);
while (!done) {
SDL_FillRect(screen, NULL, 0);
SDL_PumpEvents();
if (keys[SDLK_ESCAPE])
exit(0);
{
int i, j;
Uint32 t = SDL_GetTicks() >> 2;
t = 51. + 50. * sin(t * M_PI / 220.);
printf("%d\n", t);
for (i = 0; i < 600; i++) {
for (j = 0; j < 800; j++) {
int i2 = (600 / 2- i);
i2 *= i2;
int j2 = (800 / 2- j);
j2 *= j2;
int col = 125. + 12500. * sin(sqrt(j2/t + i2/t)) / sqrt(j2 + i2);
//printf("%d\n", col);
if (col < 0 || col > 255)
continue;
Draw_Pixel(screen, j, i, SDL_MapRGB(screen->format, col, col, col));
}
}
SDL_UpdateRect(screen, 0, 0, 800, 600);
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment