Created
August 14, 2015 01:25
-
-
Save scribblemaniac/11097ef141a6bf75eaee to your computer and use it in GitHub Desktop.
Creates asteroids (4-cusped hypocycloid) in VPaint's .vec format
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| This is free and unencumbered software released into the public domain. | |
| Anyone is free to copy, modify, publish, use, compile, sell, or | |
| distribute this software, either in source code form or as a compiled | |
| binary, for any purpose, commercial or non-commercial, and by any | |
| means. | |
| In jurisdictions that recognize copyright laws, the author or authors | |
| of this software dedicate any and all copyright interest in the | |
| software to the public domain. We make this dedication for the benefit | |
| of the public at large and to the detriment of our heirs and | |
| successors. We intend this dedication to be an overt act of | |
| relinquishment in perpetuity of all present and future rights to this | |
| software under copyright law. | |
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |
| EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
| MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | |
| IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR | |
| OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, | |
| ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | |
| OTHER DEALINGS IN THE SOFTWARE. | |
| For more information, please refer to <http://unlicense.org/> | |
| */ | |
| #include <iostream> | |
| #include <fstream> | |
| #include <sstream> | |
| #include <cmath> | |
| using namespace std; | |
| // Adjust these variable to easily customize the output | |
| #define OUTPUT_PATH "VPaintProjects/Result.vec" | |
| #define QUADS 9 | |
| #define ASTEROID_WIDTH 900 | |
| #define ASTEROID_HEIGHT 900 | |
| #define START_X 0 | |
| #define START_Y 0 | |
| #define LINE_WIDTH 1 | |
| #define LINE_COLOR "rgba(0,0,0,1)" | |
| const float middleX = ASTEROID_WIDTH / 2 + START_X; | |
| const float middleY = ASTEROID_HEIGHT / 2 + START_Y; | |
| const float offsetX = ASTEROID_WIDTH / 2 / QUADS; | |
| const float offsetY = ASTEROID_HEIGHT / 2 / QUADS; | |
| int main() { | |
| if(QUADS < 2) { | |
| cerr << "Not enough quads" << endl; | |
| return -1; | |
| } | |
| ofstream output(OUTPUT_PATH); | |
| output << "<?xml version=\"1.0\" encoding=\"UTF-8\"?><vec version=\"1.0\"><playback firstframe=\"0\" lastframe=\"0\" fps=\"24\" subframeinbetweening=\"off\" playmode=\"normal\"/><canvas left=\"0\" top=\"0\" width=\"900\" height=\"900\"/><layer style=\"background-color:rgba(255,255,255,1);\">"; | |
| for(int i=1;i<=QUADS;i++) { | |
| float coords[] = { middleX - offsetX * i, middleX + offsetX * i, middleY - offsetY * (QUADS - i + 1), middleY + offsetY * (QUADS - i + 1) }; | |
| output << "<vertex id=\"" << i << "\" frame=\"0\" position=\"" << coords[0] << "," << middleY << "\"/>"; | |
| output << "<vertex id=\"" << (QUADS + i) << "\" frame=\"0\" position=\"" << middleX << "," << coords[2] << "\"/>"; | |
| output << "<vertex id=\"" << (QUADS * 2 + i) << "\" frame=\"0\" position=\"" << coords[1] << "," << middleY << "\"/>"; | |
| output << "<vertex id=\"" << (QUADS * 3 + i) << "\" frame=\"0\" position=\"" << middleX << "," << coords[3] << "\"/>"; | |
| output << "<edge id=\"" << (QUADS * 4 + i) << "\" startvertex=\"" << i << "\" endvertex=\"" << (QUADS + i) << "\" curve=\"xyw-dense: 5 " << coords[0] << "," << middleY << "," << LINE_WIDTH << " " << coords[1] << "," << middleY << "," << LINE_WIDTH << "\" style=\"color:" << LINE_COLOR << "\"/>"; | |
| output << "<edge id=\"" << (QUADS * 5 + i) << "\" startvertex=\"" << (QUADS + i) << "\" endvertex=\"" << (QUADS * 2 + i) << "\" curve=\"xyw-dense: 5 " << middleX << "," << coords[2] << "," << LINE_WIDTH << " " << middleX << "," << coords[3] << "," << LINE_WIDTH << "\" style=\"color:" << LINE_COLOR << "\"/>"; | |
| output << "<edge id=\"" << (QUADS * 6 + i) << "\" startvertex=\"" << (QUADS * 2 + i) << "\" endvertex=\"" << (QUADS * 3 + i) << "\" curve=\"xyw-dense: 5 " << coords[1] << "," << middleY << "," << LINE_WIDTH << " " << middleX << "," << coords[2] << "," << LINE_WIDTH << "\" style=\"color:" << LINE_COLOR << "\"/>"; | |
| output << "<edge id=\"" << (QUADS * 7 + i) << "\" startvertex=\"" << (QUADS * 3 + i) << "\" endvertex=\"" << i << "\" curve=\"xyw-dense: 5 " << middleX << "," << coords[2] << "," << LINE_WIDTH << " " << middleX << "," << coords[3] << "," << LINE_WIDTH << "\" style=\"color:" << LINE_COLOR << "\"/>"; | |
| } | |
| output << "<vertex id=\"" << 0 << "\" frame=\"0\" position=\"" << middleX << "," << middleY << "\"/>"; | |
| output << endl << endl; | |
| for(int i=1;i<QUADS;i++) { | |
| output << "<edge id=\"" << (QUADS * 8 + i) << "\" startvertex=\"" << i << "\" endvertex=\"" << (i + 1) << "\" curve=\"xyw-dense: 5 " << (middleX - offsetX * i) << "," << middleY << "," << LINE_WIDTH << " " << (middleX - offsetX * (i + 1)) << "," << middleY << "," << LINE_WIDTH << "\" style=\"color:" << LINE_COLOR << "\"/>"; | |
| output << "<edge id=\"" << (QUADS * 9 + i) << "\" startvertex=\"" << (QUADS + i) << "\" endvertex=\"" << (QUADS + i + 1) << "\" curve=\"xyw-dense: 5 " << (middleX + offsetX * i) << "," << middleY << "," << LINE_WIDTH << " " << (middleX + offsetX * (i + 1)) << "," << middleY << "," << LINE_WIDTH << "\" style=\"color:" << LINE_COLOR << "\"/>"; | |
| output << "<edge id=\"" << (QUADS * 10 + i) << "\" startvertex=\"" << (QUADS * 2 + i) << "\" endvertex=\"" << (QUADS * 2 + i + 1) << "\" curve=\"xyw-dense: 5 " << middleX << "," << (middleY - offsetY * (QUADS - i + 1)) << "," << LINE_WIDTH << " " << middleX << "," << (middleY - offsetY * (QUADS - i)) << "," << LINE_WIDTH << "\" style=\"color:" << LINE_COLOR << "\"/>"; | |
| output << "<edge id=\"" << (QUADS * 11 + i) << "\" startvertex=\"" << (QUADS * 3 + i) << "\" endvertex=\"" << (QUADS * 3 + i + 1) << "\" curve=\"xyw-dense: 5 " << middleX << "," << (middleY + offsetY * (QUADS - i + 1)) << "," << LINE_WIDTH << " " << middleX << "," << (middleY + offsetY * (QUADS - i)) << "," << LINE_WIDTH << "\" style=\"color:" << LINE_COLOR << "\"/>"; | |
| } | |
| output << "<edge id=\"" << (QUADS * 9) << "\" startvertex=\"0\" endvertex=\"1\" curve=\"xyw-dense: 5 " << middleX << "," << middleY << "," << LINE_WIDTH << " " << (middleX - offsetX) << "," << middleY << "," << LINE_WIDTH << "\" style=\"color:" << LINE_COLOR << "\"/>"; | |
| output << "<edge id=\"" << (QUADS * 10) << "\" startvertex=\"0\" endvertex=\"" << (QUADS * 2) << "\" curve=\"xyw-dense: 5 " << middleX << "," << middleY << "," << LINE_WIDTH << " " << middleX << "," << (middleY - offsetY) << "," << LINE_WIDTH << "\" style=\"color:" << LINE_COLOR << "\"/>"; | |
| output << "<edge id=\"" << (QUADS * 11) << "\" startvertex=\"0\" endvertex=\"" << (QUADS * 2 + 1) << "\" curve=\"xyw-dense: 5 " << middleX << "," << middleY << "," << LINE_WIDTH << " " << (middleX + offsetX) << "," << middleY << "," << LINE_WIDTH << "\" style=\"color:" << LINE_COLOR << "\"/>"; | |
| output << "<edge id=\"" << (QUADS * 12) << "\" startvertex=\"0\" endvertex=\"" << (QUADS * 4) << "\" curve=\"xyw-dense: 5 " << middleX << "," << middleY << "," << LINE_WIDTH << " " << middleX << "," << (middleY + offsetY) << "," << LINE_WIDTH << "\" style=\"color:" << LINE_COLOR << "\"/>"; | |
| output << "</layer></vec>" << endl; | |
| output.close(); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment