creating actual svg image

Feb 27, 2017 at 9:22pm
Could someone point me in the right direction for turning this code into an actual image using svg? I know the first line of an svg file has to be

<svg xmlns='http://www.w3.org/2000/svg' width='600' height='600' version='1.1'>

but I'm not entirely sure where it would go, as well as the end </svg>.
also if theres any input to improve this it would be greatly appreciated.

#include "stdafx.h"
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <cmath>
using namespace std;

int rand_0toN1(int n);
void choose_object();

char *colour[4] =
{"Red", "Blue", "Orange", "Green"};
char *object[2] =
{"Ball", "Cube"};

int main()
{
int n, i;
srand(time(NULL)); // Set seed for randomizing.
while (1) {
cout << "Enter no. of objects to draw ";
cout << "(0 to exit): ";
cin >> n;
if (n == 0)
break;
for (i = 1; i <= n; i++)
choose_object();
}
return 0;
}
void choose_object() {
int c; // Random index (0 thru 4) into
// colours array
int o; // Random index (0 thru 2) into
// object array
c = rand_0toN1(4);
o = rand_0toN1(2);
cout << colour[c] << "," << object[o] << endl;
}

int rand_0toN1(int n) {
return rand() % n;
}
Feb 27, 2017 at 10:56pm
I'm not exactly sure what it is you're asking.
An SVG file is an XML that contains the geometric representation of an image. You can't just paste an SVG file into a C++ source and expect it to work.

Rasterization of SVG is extremely complicated, because the format is so complex. SVG even supports animation.
librsvg implements at least a sizable subset of the standard (perhaps it implements everything; I'm unsure). Qt contains an implementation (QtSvg) for a smaller subset that's still very practical.
Last edited on Feb 27, 2017 at 10:56pm
Topic archived. No new replies allowed.