SVGlib.h
retour vers la page des Tps II
#include <stdio.h>
FILE *sortie;
struct pts {
int x,y;
};
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");
}
void SVGClose(){
fprintf(sortie,"</svg>\n");
fclose(sortie);
}
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
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");
}
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");
}