Skip to content

Instantly share code, notes, and snippets.

@joastbg
Last active November 6, 2015 00:49
Show Gist options
  • Select an option

  • Save joastbg/9738cf8a0b592e507687 to your computer and use it in GitHub Desktop.

Select an option

Save joastbg/9738cf8a0b592e507687 to your computer and use it in GitHub Desktop.
SVG symmetry generator
#include <iostream>
#include <iterator>
#include <fstream>
#include <algorithm>
#include <iomanip>
#include <complex>
#include <cmath>
double const pi = 4 * std::atan(1);
int main () {
std::cout << std::fixed << std::setprecision(3);
std::string code = "<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\">";
std::cout << code << std::endl;
std::cout << "<circle cx=\"300\" cy=\"300\" r=\"250\" stroke=\"gray\" ";
std::cout << "stroke-width=\"1.5\" fill=\"white\" />" << std::endl;
int n = 3;
std::cout << "<polyline points=\"\n";
for (int k = 0; k <= n; ++k) {
auto c = std::polar<double>(1, 2*pi*k/n + pi/2);
std::cout << 300 + 250*c.real() << ", " << 300 + 250 * c.imag();
std::cout << ", ";
}
std::cout << "\" style=\"fill:none;stroke:black;stroke-width:3\" />\n";
for (int k = 0; k < n; ++k) {
auto c = std::polar<double>(1, 2*pi*k/n + pi/2);
std::cout << "<line x1=\"300\" y1=\"300\" ";
std::cout << "x2=\"" << 300 + 250*c.real() << "\" y2=\"" << 300 + 250*c.imag() << "\" ";
std::cout << "style=\"stroke:rgb(180,180,180);stroke-width:1.5\" />";
std::cout << "<circle cx=\"" << 300 + 250*c.real() << "\" cy=\"";
std::cout << 300 + 250*c.imag() << "\" r=\"40\" ";
std::cout << "stroke=\"black\" stroke-width=\"3\" fill=\"green\" />" << std::endl;
}
std::cout << "<circle cx=\"300\" cy=\"300\" r=\"30\" stroke=\"black\" ";
std::cout << "stroke-width=\"3\" fill=\"gray\" />" << std::endl;
std::cout << "</svg>" << std::endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment