English: #include <stdio.h>
- include <math.h>
- define pi 3.141592653589793
int main()
{ int i,j,k ;
double x,y,u,v ;
int xa,ya,xb,yb,xc,yc,dx,dy,xm,ym ;
printf("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
"<svg xmlns=\"http://www.w3.org/2000/svg\"\n"
"xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n"
"width=\"600\" height=\"600\">\n"
"<title>A simulated election</title>\n") ;
for(i=0;i<600;i++) for(j=0;j<600;j++)
{ u = i - 300 ;
v = j - 300 ;
x = exp(-(u*u+v*v)/80000) ;
k = (int) (0.5 + 255 * (1-x) ) ;
printf("<rect width=\"1\" height=\"1\" x=\"%d\" y=\"%d\""
" style=\"fill:rgb(%d,%d,%d)\"/>\n",i,j,k,k,k) ;
}
xa = 180 ; ya = 350 ;
xb = 450 ; yb = 130 ;
xc = 420 ; yc = 430 ;
printf("<circle cx=\"%d\" cy=\"%d\" r=\"4\" fill=\"red\"/>\n",xa,ya) ;
printf("<circle cx=\"%d\" cy=\"%d\" r=\"4\" fill=\"red\"/>\n",xb,yb) ;
printf("<circle cx=\"%d\" cy=\"%d\" r=\"4\" fill=\"red\"/>\n",xc,yc) ;
printf("<circle cx=\"%d\" cy=\"%d\" r=\"4\" fill=\"yellow\"/>\n",300,300) ;
xm = (xa+xb)/2 ; ym = (ya+yb)/2 ;
dx = -(yb-ya) ; dy = (xb-xa) ;
printf("<line x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\"\n "
"style=\"stroke:red;stroke-width:2\"/>\n",
xm-6*dx,ym-6*dy,xm+6*dx,ym+6*dy) ;
xm = (xb+xc)/2 ; ym = (yb+yc)/2 ;
dx = -(yc-yb) ; dy = (xc-xb) ;
printf("<line x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\"\n "
"style=\"stroke:red;stroke-width:2\"/>\n",
xm-6*dx,ym-6*dy,xm+6*dx,ym+6*dy) ;
xm = (xc+xa)/2 ; ym = (yc+ya)/2 ;
dx = -(ya-yc) ; dy = (xa-xc) ;
printf("<line x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\"\n "
"style=\"stroke:red;stroke-width:2\"/>\n",
xm-6*dx,ym-6*dy,xm+6*dx,ym+6*dy) ;
printf("<text x=\"%d\" y=\"%d\" fill=\"red\">A</text>\n",(int)xa-6,(int)ya+20) ;
printf("<text x=\"%d\" y=\"%d\" fill=\"red\">B</text>\n",(int)xb-6,(int)yb+20) ;
printf("<text x=\"%d\" y=\"%d\" fill=\"red\">C</text>\n",(int)xc-6,(int)yc+20) ;
printf("<text x=\"294\" y=\"320\" fill=\"yellow\">O</text>\n") ;
printf("<text x=\"40\" y=\"520\" fill=\"red\">A–C–B</text>\n") ;
printf("<text x=\"380\" y=\"560\" fill=\"red\">C–A–B</text>\n") ;
printf("<text x=\"540\" y=\"420\" fill=\"red\">C–B–A</text>\n") ;
printf("<text x=\"540\" y=\"100\" fill=\"red\">B–C–A</text>\n") ;
printf("<text x=\"260\" y=\"40\" fill=\"red\">B–A–C</text>\n") ;
printf("<text x=\"20\" y=\"90\" fill=\"red\">A–B–C</text>\n") ;
printf("</svg>\n") ;
}