/*
-----------------------------------------------------------------------
simpleplot.c | www.sqrt.ch
Writes values for a function into a simple path in a standalone SVG
Piecewise linear approximation
-----------------------------------------------------------------------
*/

#include <math.h>
#include <stdio.h>

// Note that most SVG Renderer take the Origin to the upper LEFT
// and have the positive y-axis DOWNWARDS!

int main()
{
	printf("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<svg shape-rendering=\"geometricPrecision\" viewBox=\"-5 -5 10 10\" xmlns=\"http://www.w3.org/2000/svg\">\n\t<path d=\"M ");

	float x0 = -5, x1 = 5, step = 0.005;
	int up = (x1 - x0) / step + 1;

	for (int i = 0; i < up; i++)
	{
		float x = x0 + i * step;
		double y = 2 * sin(5 * x);
		printf("%.5f ", x);
		printf("%.15lf ", y);
	}

	printf("\" fill=\"none\" stroke=\"#000\" stroke-width=\"0.05\"/>\n\t<desc>www.sqrt.ch</desc>\n</svg>");
	return 0;
}

// Type in the terminal:
// gcc -o simpleplot.exe simpleplot.c
// simpleplot > plot.svg

// For reduction of the size (yet not the precision) you may use "Scour".
