SVGlib.h

De troyesGEII
Aller à : navigation, rechercher

retour vers la page des Tps II

#include <stdio.h>
FILE *sortie;<br>
struct pts {
 int x,y;
};<br>
void SVGopen(int dx, int dy){
  sortie=fopen("demo.svg","w+t");
  fprintf(sortie,"<?xml version=\"1.0\" standalone=\"no\"?>\n");
  fprintf(sortie,"<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n");
  fprintf(sortie," \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n");
  fprintf(sortie,"<svg  width=\"%dmm\" height=\"%dmm\" viewBox=\"0 0 %d %d\" preserveAspectRatio=\"xMinYMin\" xml:space=\"preserve\"\n",dx,dy,dx,dy);
  fprintf(sortie,"xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\">\n");
}<br>
void SVGClose(){
  fprintf(sortie,"</svg>\n");
  fclose(sortie);
}<br>
void SVGrectanglePlein(int x, int y, int Dx, int Dy,int rgbTour,int rgbFill){
    fprintf(sortie,"<rect x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" style=\"fill:#%06x;stroke:#%06x;\"/>\n",x,y,Dx,Dy,rgbFill,rgbTour);
}<br>
void SVGrectangleVide(int x, int y, int Dx, int Dy){
    fprintf(sortie,"<rect x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" style=\"fill:none;stroke:black;\"/>\n",x,y,Dx,Dy);
}<br>
void SVGline(int x1, int y1, int x2, int y2, int rgb){
    fprintf(sortie,"<line x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" style=\"stroke:#%06x;\"/>\n",x1,y1,x2,y2,rgb);
}<br>
void SVGlineLarge(int x1, int y1, int x2, int y2, int rgb,int epaisseur){
    fprintf(sortie,"<line x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" style=\"stroke-width: %d;stroke:#%06x;\"/>\n",x1,y1,x2,y2,epaisseur,rgb);
}<br>
void SVGcircleVide(int cx, int cy, int r){
    fprintf(sortie,"<circle cx=\"%d\" cy=\"%d\" r=\"%d\" style=\"fill:none;stroke:black;\"/>\n",cx,cy,r);
}<br>
void SVGcirclePlein(int cx, int cy, int r, int rgbTour,int rgbFill){
    fprintf(sortie,"<circle cx=\"%d\" cy=\"%d\" r=\"%d\" style=\"fill:#%06x;stroke:#%06x;\"/>\n",cx,cy,r,rgbFill,rgbTour);
}<br>
void SVGText(int x, int y, int size, char *chaine){
    fprintf(sortie,"<text x=\"%d\" y=\"%d\"  font-family=\"Verdana\" font-size=\"%d\" fill=\"black\"> %s </text>\n",x,y,size,chaine);
}<br>
void SVGellipseVide(int cx, int cy, int rx, int ry){
    fprintf(sortie,"<ellipse cx=\"%d\" cy=\"%d\" rx=\"%d\" ry=\"%d\" style=\"fill:none;stroke:black;\"/>\n",cx,cy,rx,ry);
}<br>
void SVGellipsePlein(int cx, int cy, int rx, int ry, int rgbTour,int rgbFill){
    fprintf(sortie,"<ellipse cx=\"%d\" cy=\"%d\" rx=\"%d\" ry=\"%d\" style=\"fill:#%06x;stroke:#%06x;\"/>\n",cx,cy,rx,ry,rgbFill,rgbTour);
}<br>
void SVGrectanglePleinArrondi(int x, int y, int Dx, int Dy, int rx, int ry, int rgbTour,int rgbFill){
    fprintf(sortie,"<rect x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" rx=\"%d\" ry=\"%d\" style=\"fill:#%06x;stroke:#%06x;\"/>\n",x,y,Dx,Dy,rx,ry,rgbFill,rgbTour);
}<br>
void SVGrectangleVideArrondi(int x, int y, int Dx, int Dy,int rx, int ry){
    fprintf(sortie,"<rect x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" rx=\"%d\" ry=\"%d\" style=\"fill:none;stroke:black;\"/>\n",x,y,Dx,Dy,rx,ry);
}<br>
void SVGpolyline(int nb, struct pts tabPts[],int rgbFill, int rgbTour) {
 int i;
 fprintf(sortie,"<polyline points =\"");
 for (i=0;i<nb;i++) {
    fprintf(sortie,"%d,%d ",tabPts[i].x,tabPts[i].y);
 } 
 fprintf(sortie,"\" style=\"fill:#%06x;stroke:#%06x;\"/>\n",rgbFill,rgbTour);
}<br>
void SVGpolygon(int nb, struct pts tabPts[],int rgbFill, int rgbTour) {
 int i;
 fprintf(sortie,"<polygon points =\"");
 for (i=0;i<nb;i++) {
    fprintf(sortie,"%d,%d ",tabPts[i].x,tabPts[i].y);
 } 
 fprintf(sortie,"\" style=\"fill:#%06x;stroke:#%06x;\"/>\n",rgbFill,rgbTour);
}<br>
void SVGrectanglePleinAnimate(int x, int y, int Dx, int Dy,int rgbTour,int rgbFill,int nb,struct pts tabPts[],int timesec){
    int i;
    fprintf(sortie,"<rect x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" style=\"fill:#%06x;stroke:#%06x;\">\n",x,y,Dx,Dy,rgbFill,rgbTour);
    fprintf(sortie,"<animate attributeName=\"x\" dur=\"%ds\" values=\"",timesec) ;
    for (i=0;i<nb-1;i++)
       fprintf(sortie,"%d;",tabPts[i].x);
    fprintf(sortie,"%d\" />",tabPts[i].x);
    fprintf(sortie,"<animate attributeName=\"y\" dur=\"%ds\" values=\"",timesec) ;
    for (i=0;i<nb-1;i++)
       fprintf(sortie,"%d;",tabPts[i].y);
    fprintf(sortie,"%d\" />",tabPts[i].y);
    fprintf(sortie,"</rect>\n");
}<br>
void SVGrectanglePleinAnimateMouseOver(int x, int y, int Dx, int Dy,int rgbTour,int rgbFill,int nb,struct pts tabPts[],int timesec){
    int i;
    fprintf(sortie,"<rect x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" style=\"fill:#%06x;stroke:#%06x;\">\n",x,y,Dx,Dy,rgbFill,rgbTour);
    fprintf(sortie,"<animate begin=\"mouseover\" attributeName=\"x\" dur=\"%ds\" values=\"",timesec) ;
    for (i=0;i<nb-1;i++)
       fprintf(sortie,"%d;",tabPts[i].x);
    fprintf(sortie,"%d\" />",tabPts[i].x);
    fprintf(sortie,"<animate begin=\"mouseover\" attributeName=\"y\" dur=\"%ds\" values=\"",timesec) ;
    for (i=0;i<nb-1;i++)
       fprintf(sortie,"%d;",tabPts[i].y);
    fprintf(sortie,"%d\" />",tabPts[i].y);
    fprintf(sortie,"</rect>\n");
}

retour vers la page des Tps II