Skip to content

Instantly share code, notes, and snippets.

@olgierd
Last active December 5, 2023 12:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save olgierd/0190492431991b8e28fc71c56d61d571 to your computer and use it in GitHub Desktop.
Save olgierd/0190492431991b8e28fc71c56d61d571 to your computer and use it in GitHub Desktop.
A visual surprise
// usage: gcc source.c -lm && ./a.out | paplay --rate=5161 --format=float32le --channels=1 --raw
#include <stdio.h>
#include <math.h>
int main() {
float x=0,y=0, o=0, os;
for(x=-1.12;x<1.12;x+=0.0187) {
for(int q=0;q<36;q++) { o = fmod(o + 2*1200*M_PI/5161, 2*M_PI); os = sin(o); fwrite(&os, sizeof(float), 1, stdout); }
for(y=-2;y<0.5;y+=0.0157) {
float c=0, xt, ax=y, ay=x; while (ax*ax+ay*ay<=4 && c<100) { xt=ax*ax-ay*ay+y; ay=2*ax*ay+x; ax=xt; c++; }
for(char q=0;q<3;q++) { o = fmod(o+2*(c*8+1500)*M_PI/5161, 2*M_PI); os = sin(o); fwrite(&os, sizeof(float), 1, stdout); }
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment