Advertisement
j0h

scgStdArg

j0h
Feb 5th, 2024 (edited)
997
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 21.48 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdbool.h>
  3. #include <stdio.h>
  4. #include <string.h>
  5. #include <math.h>
  6. #include <stdarg.h>
  7.  
  8. /*
  9.  * For original project details of this project go to
  10. http://www.codedrome.com/svg-library-in-c/
  11.  *
  12.  * I'm adding some features, polyline, polygon, inline commenter, svg pixel-map... other geometries, and features intended for zellij design
  13.  * To compile using this library: //gcc -g -Wall  prog.c -o prog    -lm
  14.  * */
  15.  
  16.  
  17. // --------------------------------------------------------
  18. // STRUCT svg
  19. // --------------------------------------------------------
  20. typedef struct svg{
  21.     char* svg;
  22.     int height;
  23.     int width;
  24.     bool finalized;
  25. } svg;
  26.  
  27. // --------------------------------------------------------
  28. // FUNCTION PROTOTYPES
  29. // --------------------------------------------------------
  30. //ok I just realized bruh did an obnoxious thing, and made all the shape functions take arguments in different patterns.
  31. //function( psvg, x,y, height, width, radius, fill, stroke, strokewidth )
  32. //Ill fix that later, RN gonna make animation work.
  33.  
  34. /*I too did an anoying thing and wrote animateRotate using the format of the former args patterns.
  35.  * Using stdarg.h, functions require specifying the number of args for a function, these are as follows
  36.  *
  37.  * svg_ellipse: 8
  38.  * svg_polygon 8
  39.  * svg_text 8
  40.  * svg_line 7
  41.  * svg_rectangle 10
  42.  *
  43.  * after which, args are passed to the animateRotate function
  44.  *
  45.  * Example animateRotate call:
  46.  *   svg_animateRotate( 8, svg_polygon, psvg, 100.0, 100.0, 50.0, 5, "blue", "green", 7, durration);
  47.  * */
  48. svg* svg_create(int width, int height);
  49. void svg_finalize(svg* psvg);
  50. void svg_print(svg* psvg);
  51. void svg_save(svg* psvg, char* filepath);
  52. void svg_free(svg* psvg);
  53. void svg_fill(svg* psvg, char* fill);
  54. void svg_circle(svg* psvg, char* stroke, int strokewidth, char* fill, int r, int cx, int cy);
  55. void svg_line(svg* psvg, char* stroke, int strokewidth, int x1, int y1, int x2, int y2);
  56. void svg_rectangle(svg* psvg, int width, int height, int x, int y, char* fill, char* stroke, int strokewidth, int radiusx, int radiusy);
  57. void svg_text(svg* psvg, int x, int y, char* fontfamily, int fontsize, char* fill, char* stroke, char* text);
  58. void svg_ellipse(svg* psvg, int cx, int cy, int rx, int ry, char* fill, char* stroke, int strokewidth);
  59. void svg_polygon(svg* psvg, double cx, double cy, float radius, int nsides, char* fill, char* stroke, int strokewidth );
  60. //void svg_polyline(svg* psvg, int a[], char* stroke, int strokewidth); //comeback to this it was for a kinnect
  61. //void svg_starpolygon(svg* psvg, double cx, double cy, float radius, int npoints, char* fill, char* stroke, int strokewidth );
  62. //void svg_gearpolygon(svg* psvg, double cx, double cy, float radius, int teeth, char* fill, char* stroke, int strokewidth );
  63. //void svg_diamondpolygon(svg* psvg, double cx, double cy, float radius, char* fill, char* stroke, int strokewidth );
  64. void svg_animateRotate(int num_args, ...); //take shape functions
  65. void svg_animateColor(int num_args, ...);
  66.  
  67. // --------------------------------------------------------
  68. // STATIC FUNCTION appendstringtosvg
  69. // --------------------------------------------------------
  70. static void appendstringtosvg(svg* psvg, char* text){
  71.     int l = strlen(psvg->svg) + strlen(text) + 1;
  72.  
  73.     char* p = realloc(psvg->svg, l);
  74.  
  75.     if(p){
  76.         psvg->svg = p;
  77.     }
  78.  
  79.     strcat(psvg->svg, text);
  80. }
  81.  
  82. // --------------------------------------------------------
  83. // STATIC FUNCTION appendnumbertosvg
  84. // --------------------------------------------------------
  85. static void appendnumbertosvg(svg* psvg, int n){
  86.     char sn[16];
  87.     sprintf(sn, "%d", n);
  88.     appendstringtosvg(psvg, sn);
  89. }
  90.  
  91. // --------------------------------------------------------
  92. // FUNCTION svg_create
  93. // --------------------------------------------------------
  94. svg* svg_create(int width, int height){
  95.     svg* psvg = malloc(sizeof(svg));
  96.  
  97.     if(psvg != NULL)    {
  98.         *psvg = (svg){.svg = NULL, .width = width, .height = height, .finalized = false};
  99.  
  100.         psvg->svg = malloc(1);
  101.  
  102.         sprintf(psvg->svg, "%s", "\0");
  103.  
  104.         appendstringtosvg(psvg, "<svg width='");
  105.         appendnumbertosvg(psvg, width);
  106.         appendstringtosvg(psvg, "px' height='");
  107.         appendnumbertosvg(psvg, height);
  108.         appendstringtosvg(psvg, "px' xmlns='http://www.w3.org/2000/svg' version='1.1' xmlns:xlink='http://www.w3.org/1999/xlink'>\n");
  109.  
  110.         return psvg;
  111.     }    else    {
  112.         return NULL;
  113.     }
  114. }
  115.  
  116. // --------------------------------------------------------
  117. // FUNCTION svg_finalize
  118. // --------------------------------------------------------
  119. void svg_finalize(svg* psvg){
  120.     appendstringtosvg(psvg, "</svg>");
  121.     psvg->finalized = true;
  122. }
  123.  
  124. // --------------------------------------------------------
  125. // FUNCTION svg_print
  126. // --------------------------------------------------------
  127. void svg_print(svg* psvg){
  128.     printf("%s\n", psvg->svg);
  129. }
  130.  
  131. // --------------------------------------------------------
  132. // FUNCTION svg_save
  133. // --------------------------------------------------------
  134. void svg_save(svg* psvg, char* filepath){
  135.     if(!psvg->finalized){
  136.         svg_finalize(psvg);
  137.     }
  138.  
  139.     FILE* fp;
  140.     fp = fopen(filepath, "w");
  141.  
  142.     if(fp != NULL){
  143.         fwrite(psvg->svg, 1, strlen(psvg->svg), fp);
  144.  
  145.         fclose(fp);
  146.     }
  147. }
  148.  
  149. //----------------------------------------------------------------
  150. // FUNCTION svg_free
  151. //----------------------------------------------------------------
  152. void svg_free(svg* psvg){
  153.     free(psvg->svg);
  154.     free(psvg);
  155. }
  156.  
  157. //----------------------------------------------------------------
  158. // FUNCTION svg_circle
  159. //----------------------------------------------------------------
  160. void svg_circle(svg* psvg, char* stroke, int strokewidth, char* fill, int r, int cx, int cy){
  161.     appendstringtosvg(psvg, "    <circle stroke='");
  162.     appendstringtosvg(psvg, stroke);
  163.     appendstringtosvg(psvg, "' stroke-width='");
  164.     appendnumbertosvg(psvg, strokewidth);
  165.     appendstringtosvg(psvg, "px' fill='");
  166.     appendstringtosvg(psvg, fill);
  167.     appendstringtosvg(psvg, "' r='");
  168.     appendnumbertosvg(psvg, r);
  169.     appendstringtosvg(psvg, "' cy='");
  170.     appendnumbertosvg(psvg, cy);
  171.     appendstringtosvg(psvg, "' cx='");
  172.     appendnumbertosvg(psvg, cx);
  173.     appendstringtosvg(psvg, "' />\n");
  174. }
  175.  
  176. //----------------------------------------------------------------
  177. // FUNCTION svg_line
  178. //----------------------------------------------------------------
  179. void svg_line(svg* psvg, char* stroke, int strokewidth, int x1, int y1, int x2, int y2){
  180.     appendstringtosvg(psvg, "    <line stroke='");
  181.     appendstringtosvg(psvg, stroke);
  182.     appendstringtosvg(psvg, "' stroke-width='");
  183.     appendnumbertosvg(psvg, strokewidth);
  184.     appendstringtosvg(psvg, "px' x1='");
  185.     appendnumbertosvg(psvg, y2);
  186.     appendstringtosvg(psvg, "' y1='");
  187.     appendnumbertosvg(psvg, x2);
  188.     appendstringtosvg(psvg, "' x2='");
  189.     appendnumbertosvg(psvg, y1);
  190.     appendstringtosvg(psvg, "' y2='");
  191.     appendnumbertosvg(psvg, x1);
  192.     appendstringtosvg(psvg, "' />\n");
  193. }
  194.  
  195. //----------------------------------------------------------------
  196. // FUNCTION svg_rectangle
  197. //----------------------------------------------------------------
  198. void svg_rectangle(svg* psvg, int width, int height, int x, int y, char* fill, char* stroke, int strokewidth, int radiusx, int radiusy){
  199.     appendstringtosvg(psvg, "    <rect fill='");
  200.     appendstringtosvg(psvg, fill);
  201.     appendstringtosvg(psvg, "' stroke='");
  202.     appendstringtosvg(psvg, stroke);
  203.     appendstringtosvg(psvg, "' stroke-width='");
  204.     appendnumbertosvg(psvg, strokewidth);
  205.     appendstringtosvg(psvg, "px' width='");
  206.     appendnumbertosvg(psvg, width);
  207.     appendstringtosvg(psvg, "' height='");
  208.     appendnumbertosvg(psvg, height);
  209.     appendstringtosvg(psvg, "' y='");
  210.     appendnumbertosvg(psvg, y);
  211.     appendstringtosvg(psvg, "' x='");
  212.     appendnumbertosvg(psvg, x);
  213.     appendstringtosvg(psvg, "' ry='");
  214.     appendnumbertosvg(psvg, radiusy);
  215.     appendstringtosvg(psvg, "' rx='");
  216.     appendnumbertosvg(psvg, radiusx);
  217.     appendstringtosvg(psvg, "' />\n");
  218. }
  219.  
  220. // --------------------------------------------------------
  221. // FUNCTION svg_fill
  222. // --------------------------------------------------------
  223. void svg_fill(svg* psvg, char* Fill){
  224.     svg_rectangle(psvg, psvg->width, psvg->height, 0, 0, Fill, Fill, 0, 0, 0);
  225. }
  226.  
  227. //----------------------------------------------------------------
  228. // FUNCTION svg_text
  229. //----------------------------------------------------------------
  230. void svg_text(svg* psvg, int x, int y, char* fontfamily, int fontsize, char* fill, char* stroke, char* text){
  231.     appendstringtosvg(psvg, "    <text x='");
  232.     appendnumbertosvg(psvg, x);
  233.     appendstringtosvg(psvg, "' y = '");
  234.     appendnumbertosvg(psvg, y);
  235.     appendstringtosvg(psvg, "' font-family='");
  236.     appendstringtosvg(psvg, fontfamily);
  237.     appendstringtosvg(psvg, "' stroke='");
  238.     appendstringtosvg(psvg, stroke);
  239.     appendstringtosvg(psvg, "' fill='");
  240.     appendstringtosvg(psvg, fill);
  241.     appendstringtosvg(psvg, "' font-size='");
  242.     appendnumbertosvg(psvg, fontsize);
  243.     appendstringtosvg(psvg, "px'>");
  244.     appendstringtosvg(psvg, text);
  245.     appendstringtosvg(psvg, "</text>\n");
  246. }
  247.  
  248. //----------------------------------------------------------------
  249. // FUNCTION svg_ellipse
  250. //----------------------------------------------------------------
  251. void svg_ellipse(svg* psvg, int cx, int cy, int rx, int ry, char* fill, char* stroke, int strokewidth){
  252.     appendstringtosvg(psvg, "    <ellipse cx='");
  253.     appendnumbertosvg(psvg, cx);
  254.     appendstringtosvg(psvg, "' cy='");
  255.     appendnumbertosvg(psvg, cy);
  256.     appendstringtosvg(psvg, "' rx='");
  257.     appendnumbertosvg(psvg, rx);
  258.     appendstringtosvg(psvg, "' ry='");
  259.     appendnumbertosvg(psvg, ry);
  260.     appendstringtosvg(psvg, "' fill='");
  261.     appendstringtosvg(psvg, fill);
  262.     appendstringtosvg(psvg, "' stroke='");
  263.     appendstringtosvg(psvg, stroke);
  264.     appendstringtosvg(psvg, "' stroke-width='");
  265.     appendnumbertosvg(psvg, strokewidth);
  266.     appendstringtosvg(psvg, "' />\n");
  267. }
  268.  
  269. //---------------------------------------------------------
  270. //FUNCTION svg_polyline: this function had been getting data from the kinect
  271. //---------------------------------------------------------
  272. /*
  273.  * void svg_polyline(svg* psvg, int a[], char* stroke, int strokewidth){
  274.  
  275. appendstringtosvg(psvg, " <polyline  points='");
  276. //assume array is x,y alternating. or index,depth.
  277. //it goes: x,y  x,y  x,y... untill the end. append with quotes
  278. //determine array size
  279. int aSize= sizeof(a)/sizeof(a[index]);
  280. for (int i =0; i< aSize; i++){
  281.     appendstringtosvg(psvg, i);
  282.     appendstringtosvg(psvg, ",");
  283.     appendstringtosvg(psvg, i);
  284.     appendstringtosvg(psvg, " ");
  285.         }
  286.  appendstringtosvg(psvg, "' stroke='");    
  287.  appendstringtosvg(psvg, stroke);
  288.  appendstringtosvg(psvg, "' stroke-width='");
  289.  appendnumbertosvg(psvg, strokewidth);
  290.  appendstringtosvg(psvg, "' />\n");
  291.     }
  292. */
  293.  
  294. //----------------------------------------------------------------
  295. // FUNCTION svg_polygon
  296. //----------------------------------------------------------------
  297. void svg_polygon(svg* psvg, double cx, double cy, float radius, int nsides, char* fill, char* stroke, int strokewidth ){
  298. //cx,cy ==center point
  299. //put xi ,yi in an array   
  300. float xi, yi=0.0;
  301.     if (nsides<3){
  302.     printf("Error: Too Few Sides\n");
  303.     exit(0);
  304. }
  305.  
  306. //start building the polygon:
  307.     appendstringtosvg(psvg, "    <polygon style=\"fill:");
  308.     appendstringtosvg(psvg, fill);
  309.     appendstringtosvg(psvg, "; stroke:");
  310.     appendstringtosvg(psvg, stroke);
  311.     appendstringtosvg(psvg, "; stroke-width:");
  312.     appendnumbertosvg(psvg, strokewidth);
  313.     appendstringtosvg(psvg, "\" points='");
  314.  
  315.     //calc x,y point cordinates. trig funtions take radians
  316.     for (int i =1; i < nsides+1;  i++){
  317.     xi= cx + radius * cos((2*M_PI/nsides) * i);
  318.         appendnumbertosvg(psvg, xi);
  319.         appendstringtosvg(psvg, ", ");
  320.     yi= cy + radius * sin((2*M_PI/nsides) *  i);
  321.         appendnumbertosvg(psvg, yi);   
  322.         appendstringtosvg(psvg, " ");      
  323.         printf("%f , %f\n ", xi, yi);
  324.         }
  325.         printf("\n");
  326.         //close polygon
  327.      appendstringtosvg(psvg, "' />\n");
  328.     }
  329.  
  330. //----------------------------------------------------------------
  331. // FUNCTION svg_animate :: transform methods
  332. //----------------------------------------------------------------
  333.  
  334. /*
  335.   * In SVG's animateTransform element, the type attribute specifies the type of transformation to be animated. The type attribute can take the following values:
  336.     translate: Animates a translation transformation, which moves an element along the x and y axes.
  337.     scale: Animates a scaling transformation, which changes the size of an element along the x and y axes.
  338.     rotate: Animates a rotation transformation, which rotates an element around a specified point.
  339.     skewX: Animates a skew transformation along the x-axis, which tilts an element horizontally.
  340.     skewY: Animates a skew transformation along the y-axis, which tilts an element vertically.
  341.  
  342.  * */
  343.  //----------------------------------------------------------------
  344. // FUNCTION svg_animateRotate
  345. //----------------------------------------------------------------
  346. // Operator function that accepts variable arguments
  347. void svg_animateRotate(int num_args, ...) {
  348.     va_list args;
  349.     va_start(args, num_args);
  350.  
  351.     for (int i = 0; i < num_args; i++) {
  352.         // Get the function pointer from the variable arguments
  353.         void (*func)(svg*, ...);
  354.         func = va_arg(args, void (*)(svg*, ...));
  355.  
  356.         // Call the function with the remaining arguments
  357.         if (func == svg_ellipse) {
  358.             svg* psvg = va_arg(args, svg*);
  359.             int cx = va_arg(args, int);
  360.             int cy = va_arg(args, int);
  361.             int rx = va_arg(args, int);
  362.             int ry = va_arg(args, int);
  363.             char* fill = va_arg(args, char*);
  364.             char* stroke = va_arg(args, char*);
  365.             int strokewidth = va_arg(args, int);
  366.             int dur = va_arg(args,int);               //maybe make that a float or double later
  367.             appendstringtosvg(psvg, " \n<g>\n");            
  368.             svg_ellipse(psvg, cx, cy, rx, ry, fill, stroke, strokewidth); //write the shape
  369.             appendstringtosvg(psvg, " \n <animateTransform \n  attributeName=\"transform\" \n  attributeType=\"XML\" \n type=\"rotate\"\n");
  370.             appendstringtosvg(psvg, "from=\"0 "); //cx,cy atleast in the polygon function are center
  371.             appendnumbertosvg(psvg, cx);
  372.             appendstringtosvg(psvg, " ");
  373.             appendnumbertosvg(psvg, cy);
  374.             appendstringtosvg(psvg, "\"\n");
  375.  
  376.             appendstringtosvg(psvg, "to=\"360 "); //theta space x space y
  377.             appendnumbertosvg(psvg, cx);
  378.             appendstringtosvg(psvg, " ");
  379.             appendnumbertosvg(psvg, cy);
  380.             appendstringtosvg(psvg, "\"\ndur =\"");
  381.             appendnumbertosvg(psvg, dur);
  382.             appendstringtosvg(psvg, "s\"\n");
  383.             appendstringtosvg(psvg, "repeatCount=\"indefinite\" />\n</g>\n");
  384.         } else if (func == svg_polygon) { //8 args
  385.             svg* psvg = va_arg(args, svg*);
  386.             double cx = va_arg(args, double);
  387.             double cy = va_arg(args, double);
  388.             float radius = va_arg(args, double); // Note: float is promoted to double in va_arg
  389.             int nsides = va_arg(args, int);
  390.             char* fill = va_arg(args, char*);
  391.             char* stroke = va_arg(args, char*);
  392.             int strokewidth = va_arg(args, int);
  393.             int dur = va_arg(args,int);               //maybe make that a float or double later
  394.             appendstringtosvg(psvg, " \n<g>\n");
  395.             svg_polygon(psvg, cx, cy, radius, nsides, fill, stroke, strokewidth);
  396.             appendstringtosvg(psvg, " \n <animateTransform \n  attributeName=\"transform\" \n  attributeType=\"XML\" \n type=\"rotate\"\n");
  397.             appendstringtosvg(psvg, "from=\"0 "); //cx,cy atleast in the polygon function are center
  398.             appendnumbertosvg(psvg, cx);
  399.             appendstringtosvg(psvg, " ");
  400.             appendnumbertosvg(psvg, cy);
  401.             appendstringtosvg(psvg, "\"\n");
  402.  
  403.             appendstringtosvg(psvg, "to=\"360 "); //theta space x space y
  404.             appendnumbertosvg(psvg, cx);
  405.             appendstringtosvg(psvg, " ");
  406.             appendnumbertosvg(psvg, cy);
  407.             appendstringtosvg(psvg, "\"\ndur =\"");
  408.             appendnumbertosvg(psvg, dur);
  409.             appendstringtosvg(psvg, "s\"\n");
  410.             appendstringtosvg(psvg, "repeatCount=\"indefinite\" />\n</g>\n");
  411.         }  else if (func == svg_text) {
  412.             //This function doesn some BS related to groups.
  413.             //void svg_text(svg* psvg, int x, int y, char* fontfamily, int fontsize, char* fill, char* stroke, char* text);
  414.             svg* psvg = va_arg(args, svg*);
  415.             int x = va_arg(args, int);
  416.             int y = va_arg(args, int);
  417.             char* fontfamily = va_arg(args, char*); // use system fonts
  418.             int fontsize = va_arg(args, int);
  419.             char* fill = va_arg(args, char*);
  420.             char* stroke = va_arg(args, char*);
  421.             char* text = va_arg(args, char*);
  422.             int dur = va_arg(args,int);               //durration of animation
  423.             appendstringtosvg(psvg, " \n<g>\n");
  424.             svg_text(psvg, x, y, fontfamily, fontsize, fill, stroke, text);
  425.             appendstringtosvg(psvg, " \n<animateTransform \n  attributeName=\"transform\" \n  attributeType=\"XML\" \n type=\"rotate\"\n");
  426.             appendstringtosvg(psvg, "from=\"0 "); //cx,cy atleast in the polygon function are center
  427.             appendnumbertosvg(psvg, x);                 //maybe set x, y based on text length.
  428.             appendstringtosvg(psvg, " ");
  429.             appendnumbertosvg(psvg, y);
  430.             appendstringtosvg(psvg, "\"\n");
  431.  
  432.             appendstringtosvg(psvg, "to=\"360 "); //theta space x space y
  433.             appendnumbertosvg(psvg, x);
  434.             appendstringtosvg(psvg, " ");
  435.             appendnumbertosvg(psvg, y);
  436.             appendstringtosvg(psvg, "\"\ndur =\"");
  437.             appendnumbertosvg(psvg, dur);
  438.             appendstringtosvg(psvg, "s\"\n");
  439.             appendstringtosvg(psvg, "repeatCount=\"indefinite\" />\n</g>\n");
  440.             }  else if (func == svg_rectangle) {
  441.             // svg_rectangle(psvg,  width,  height, x,  y,  fill,  stroke,  strokewidth,  radiusx,  radiusy); //all ints 10 args
  442.             svg* psvg = va_arg(args, svg*);
  443.             int width = va_arg(args, int);
  444.             int height = va_arg(args, int);
  445.             int x = va_arg(args, int);
  446.             int y = va_arg(args, int);
  447.             char* fill = va_arg(args, char*);
  448.             char* stroke = va_arg(args, char*);
  449.             int strokewidth = va_arg(args, int);
  450.             int radiusx = va_arg(args, int);
  451.             int radiusy = va_arg(args, int);
  452.             int dur = va_arg(args,int);               //durration of animation
  453.             appendstringtosvg(psvg, " \n<g>");
  454.             svg_rectangle(psvg,  width,  height, x,  y,  fill,  stroke,  strokewidth,  radiusx,  radiusy);
  455.             appendstringtosvg(psvg, " \n<animateTransform \n  attributeName=\"transform\" \n  attributeType=\"XML\" \n type=\"rotate\"\n");
  456.             appendstringtosvg(psvg, "from=\"0 "); //cx,cy atleast in the polygon function are center
  457.             appendnumbertosvg(psvg, x);                 //maybe set x, y based on text length.
  458.             appendstringtosvg(psvg, " ");
  459.             appendnumbertosvg(psvg, y);
  460.             appendstringtosvg(psvg, "\"\n");
  461.  
  462.             appendstringtosvg(psvg, "to=\"360 "); //theta space x space y
  463.             appendnumbertosvg(psvg, x);
  464.             appendstringtosvg(psvg, " ");
  465.             appendnumbertosvg(psvg, y);
  466.             appendstringtosvg(psvg, "\"\ndur =\"");
  467.             appendnumbertosvg(psvg, dur);
  468.             appendstringtosvg(psvg, "s\"\n");
  469.             appendstringtosvg(psvg, "repeatCount=\"indefinite\" />\n</g>\n");
  470.     } else if (func == svg_line) {
  471.         //void svg_line(svg* psvg, char* stroke, int strokewidth, int x1, int y1, int x2, int y2);
  472.         // svg_line(psvg, stroke, strokewidth,  x1,  y1, x2,  y2);
  473.             svg* psvg = va_arg(args, svg*);
  474.             char* stroke = va_arg(args, char*);
  475.             int strokewidth = va_arg(args, int);
  476.             int x1 = va_arg(args, int);
  477.             int y1 = va_arg(args, int);
  478.             int x2 = va_arg(args, int);
  479.             int y2 = va_arg(args, int);
  480.  
  481.             int dur = va_arg(args,int);               //durration of animation
  482.             appendstringtosvg(psvg, " \n<g>");
  483.             svg_line(psvg, stroke, strokewidth,  x1,  y1, x2,  y2);
  484.             appendstringtosvg(psvg, " \n<animateTransform \n  attributeName=\"transform\" \n  attributeType=\"XML\" \n type=\"rotate\"\n");
  485.             appendstringtosvg(psvg, "from=\"0 "); //cx,cy atleast in the polygon function are center
  486.             appendnumbertosvg(psvg, x1);                 //maybe set x, y based on text length.
  487.             appendstringtosvg(psvg, " ");
  488.             appendnumbertosvg(psvg, y1);
  489.             appendstringtosvg(psvg, "\"\n");
  490.  
  491.             appendstringtosvg(psvg, "to=\"360 "); //theta space x space y
  492.             appendnumbertosvg(psvg, x2);
  493.             appendstringtosvg(psvg, " ");
  494.             appendnumbertosvg(psvg, y2);
  495.             appendstringtosvg(psvg, "\"\ndur =\"");
  496.             appendnumbertosvg(psvg, dur);
  497.             appendstringtosvg(psvg, "s\"\n");
  498.             appendstringtosvg(psvg, "repeatCount=\"indefinite\" />\n</g>\n");
  499.         }
  500. }//end for loop
  501.     va_end(args);
  502. }
  503.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement