#include "web_server.h"
#include <stdio.h>
#include <math.h>
#define GIFSIDE 320
char gifdata[GIFSIDE*GIFSIDE];
void outgif() {
float i;
int x,y,xc,yc;
int color;
web_client_gifsetpalette("EGA");
if(*ClientInfo->Query("img")!=0) {
printf("Content-type: image/gif\r\n\r\n");
if(!strcmp(ClientInfo->Query("img"),"circle")) {
xc=atoi(ClientInfo->Query("x"))%GIFSIDE;
yc=atoi(ClientInfo->Query("y"))%GIFSIDE;
color=(rand()%15)+1;
for(i=0;i<6.28;i+=0.01) {
x=(int)(GIFSIDE+(xc+cos(i)*10))%GIFSIDE;
y=(int)(GIFSIDE+(yc+sin(i)*10))%GIFSIDE;
gifdata[x+(y*GIFSIDE)]=color;
};
};
web_client_gifoutput(gifdata,GIFSIDE,GIFSIDE);
};
printf("<center>Generated a circle (click inside the image)<BR>\n");
printf("Pressed x=%s,y=%s<BR>\n",ClientInfo->Query("x"),ClientInfo->Query("y"));
printf("<form><input type=image border=0 src='/gif?img=circle&x=%s&y=%s'></form></CENTER>\n",ClientInfo->Query("x"),ClientInfo->Query("y"));
};
main() {
struct web_server server; // server handler
memset(gifdata,0,GIFSIDE*GIFSIDE);
if(!web_server_init(&server,83,"help.log",0)) { // initialize
fprintf(stderr,"can't open listen socket\n");
};
web_server_addhandler(&server,"* /gif",outgif,0);
while(1) {
web_server_run(&server); // run server
};
};
|