//GPL
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define PI 3.141592653589793238462
#define SX 256
#define SY 256
#define PL 100
#define DN 2000
unsigned char imgSX][SY];
double pathPL+1][2], dotsDN][2];
void dodot(int x, int y, double f) {
if(x<0||x>=SX||y<0||y>=SY) return;
imgy][x*=f;
}
void dospot(int x, int y) {
dodot(x, y, .5);
dodot(x+1, y, .75);
dodot(x-1, y, .75);
dodot(x, y+1, .75);
dodot(x, y-1, .75);
}
void dobigspot(int x, int y) {
int a, b;
for(b=-3;b<=3;++b) for(a=-3;a<=3;++a) if(a*a+b*b<=9) dodot(x+a, y+b, (a*a+b*b)/10.);
}
void dospotd(double t, double x) {
dospot((x+1)*(SX/2.), (-t+1)*(SY/2.));
}
void dosmallspotd(double t, double x) {
dodot((x+1)*(SX/2.), (-t+1)*(SY/2.), .25);
}
void dobigspotd(double t, double x) {
dobigspot((x+1)*(SX/2.), (-t+1)*(SY/2.));
}
int main() {
char fn100];
int n, x, y, t, i, w;
double a, b, da, db, ta, tb;
FILE *f;
path0][0=path0][1=0;
for(t=0;t<=PL;++t) patht][1=0;
for(n=1;n<10;++n) {
a=rand()%20000/10000.-1; a/=n*n*n*n/200.; b=rand()%20000*(PI/10000);
for(t=0;t<=PL;++t) {
patht][1+=a*sin((2*PI/PL)*n*t+b);
}
}
for(t=PL;t>=0;--t) patht][1-=path0][1];
path0][0=0;
for(t=1;t<=PL;++t) {
a=patht][1-patht-1][1];
patht][0=patht-1][0+sqrt(1+a*a);
}
for(t=0;t<DN;++t) {
a=rand()%20000/10000.-1; b=rand()%20000/10000.-1;
dotst][0=a*pathPL][0/2; dotst][1=b*1000;
}
for(n=0;n<100;++n) {
i=PL*n/100;
a=pathi+1][0-(da=pathi][0]); b=(db=pathi][1])-pathi+1][1];
ta=pathPL][0]; tb=pathPL][1];
a/=50.; b/=50.;
for(y=0;y<SY;++y) for(x=0;x<SX;++x) imgy][x=255;
for(y=0;y<SY;++y) imgy][y*SX/SY*=.5;
for(y=0;y<SY;++y) imgy][(SY-y-1)*SX/SY*=.5;
for(w=-20;w<=20;++w)
for(t=0;t<PL;++t) dospotd(a*(patht][0-da-w*ta)+b*(patht][1-db-w*tb),
b*(patht][0-da-w*ta)+a*(patht][1-db-w*tb));
for(w=-20;w<=20;++w)
for(t=0;t<PL;t+=10) dobigspotd(a*(patht][0-da-w*ta)+b*(patht][1-db-w*tb),
b*(patht][0-da-w*ta)+a*(patht][1-db-w*tb));
for(w=-20;w<=20;++w)
for(t=0;t<DN;++t) dospotd(a*(dotst][0-da-w*ta)+b*(dotst][1-db-w*tb),
b*(dotst][0-da-w*ta)+a*(dotst][1-db-w*tb));
//if(n==0) printf("%lf; %lf, %lf, %lf; %lf, %lf, %lf, %lf, %lf\n", a*(path[PL][0]-da-1*ta)+b*(path[PL][1]-db-1*tb), path[PL][0], da, 1*ta, path[PL][1], db, 1*tb, path[0][0], path[0][1]);
sprintf(fn, "lor%04d.pgm", n);
f=fopen(fn, "wb");
fprintf(f, "P5\n%d %d\n255\n", SX, SY);
fwrite(img, 256*256, 1, f);
fclose(f);
}
}