#include <iostream>
#include <fstream>
#include <cmath>
using namespace std;

int main(){
    ofstream of("diffuse.svg");

    of << "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"-2 -2 8 2.1\">\n"; // Output Header，viewBox= x, y 座標の開始位置，幅，高さ
    double x_s = -4;
    double x_e = 4;
    double y_p = 0;
    double n = 2*256+1;
    double dx = (x_e-x_s)/(n-1);
    double r = 1.0/50;
	double s20 = 0.04;
	int nk=8;
	double dk = (x_e-x_s)/nk/2*0;
	for(int k=0;k<nk;++k)
	{
		double rk = double(k)/nk;
		double t = rk*8;
		double t2 = 1 + t*0.3;
		double s2 = s20*t2*t2;
		double x_p = x_s;
		for(double i=0;i<n;++i){
			double x = x_p + dx;
			double y = exp(-x*x*0.5/s2)/sqrt(2*M_PI*s2);
			// 線分を描画する．2点必要なため，x, y, x_p, y_p を用意する．
			// y 座標は上下反転
			double c = 240*( exp(-(double)t/5 ));
			double g = (255-c)*0.5;
			double b = g*0.5;
			of << "<circle cx='" << x_p+t*dk << "' cy='" << -y_p << "' r='" << r << "' style=\"fill:rgb(" <<c <<"," << b << "," << g << ");\" />\n";
			x_p = x;
			y_p = y;
		}
	}
	of << "</svg>\n";
}
