/* Dynamic-continuum by P.L. Garrido. Granada. Septembre 1999. */ #include #include #include #include #include #include #include #include typedef void (*func)(); struct circle_struct { int type; func draw; char *next; double x1,y1; double r; }; typedef struct circle_struct *Circle; #define CIRCLE 1 Circle make_circle(); Widget w; static short width; static short height; static char *display_list = NULL; static char etiqueta1[64],etiqueta2[64],etiqueta3[64]; double tiempo, energia; int step; redisplay(ii) int ii; { char *list; Circle node; func p; int n; Arg wargs[5]; GC gc; XGCValues gc_values; n=0; XtSetArg(wargs[n],XtNheight,&height);n++; XtSetArg(wargs[n],XtNwidth,&width);n++; XtGetValues(w,wargs,n); gc_values.line_width = 1; gc_values.function = GXset; gc = XCreateGC(XtDisplay(w),XtWindow(w),GCLineWidth|GCFunction,&gc_values); if(ii==1) { n=tiempo; sprintf(etiqueta1,"Time: %d ",n); XDrawImageString(XtDisplay(w),XtWindow(w),gc,250,60,etiqueta1,25); n=energia; sprintf(etiqueta2,"Error: %d ",n); XDrawImageString(XtDisplay(w),XtWindow(w),gc,250,20,etiqueta2,25); sprintf(etiqueta3,"Iteracion: %d ",step); XDrawImageString(XtDisplay(w),XtWindow(w),gc,250,40,etiqueta3,25); XSetFunction(XtDisplay(w),gc,GXclear); } list=display_list; while(list != NULL){ node = (Circle) list; p=node->draw; ( *p)(gc,node); list = node->next; } if(ii==1)XSetFunction(XtDisplay(w),gc,GXset); XFreeGC(XtDisplay(w),gc); } void display_circle(gc,circle) GC gc; Circle circle; { int ix,iy, ir; ix = width*circle->x1; iy = height*(1.-circle->y1); ir = width*circle->r; XDrawArc(XtDisplay(w),XtWindow(w),gc,ix,iy,ir,ir,0,360*64); /*XFillArc(XtDisplay(w),XtWindow(w),gc,ix,iy,ir,ir,0,360*64);*/ } Circle make_circle(x1,y1,r) int x1,y1,r; { Circle result; result = (Circle) malloc(sizeof *result); result->draw=display_circle; result->x1=((double) x1)/width; result->y1=1.-((double) y1)/height; result->r=((double) r)/width; result->next=display_list; display_list=(char*) result; return(result); } void redisplay_event(w1,client,ev) Widget w1; XtPointer client; XExposeEvent *ev;{ if(ev->type ==ConfigureNotify) redisplay(0); if(ev->type==Expose) redisplay(0); } void move(iix,iiy) int iix[],iiy[]; { char *list; Circle obj; int n; double x[4],y[4]; redisplay(1); n=1; while(n<4){ x[n]=iix[n]; y[n]=iiy[n]; n++; } n=1; list=display_list; while(list !=NULL){ obj = (Circle) list; obj->x1=x[n]/width; obj->y1=1.-y[n]/height; list=obj->next; n++; } redisplay(0); } void dibujo() { double dtl,rt,rl,ro; double xl,yl,xo,yo,fac; int irt,ixt,iyt,irl,ixl,iyl,ixo,iyo,iro,n; int iix[4],iiy[4]; dtl=384400000.; rt=6378160./dtl; rl= 1737400./dtl; ro=1737400./dtl; fac=width/3.; irt=2.*fac*rt; irl=2.*fac*rl; iro=2.*fac*ro; ixt=width/2.-fac*rt; iyt=height/2.-fac*rt; iix[3]=ixt; iiy[3]=iyt; make_circle(ixt,iyt,irt); tiempo=0.; scanf("%lf %lf %lf %lf %lf %lf", &tiempo,&xl,&yl,&xo,&yo,&energia); ixl=width/2.+fac*(xl-rl); iyl=height/2.+fac*(yl-rl); make_circle(ixl,iyl,irl); ixo=width/2.+fac*(xo-ro); iyo=height/2.+fac*(yo-ro); make_circle(ixo,iyo,iro); step=0; while(tiempo !=-1.){ scanf("%lf %lf %lf %lf %lf %lf", &tiempo,&xl,&yl,&xo,&yo,&energia); iix[2]=width/2.+fac*(xl-rl); iiy[2]=width/2.+fac*(yl-rl); iix[1]=width/2.+fac*(xo-ro); iiy[1]=width/2.+fac*(yo-ro); move(iix,iiy); step++; } } int colores(ir,ig,ib) int ir,ig,ib;{ Colormap cmap; XColor color; cmap=DefaultColormap(XtDisplay(w),DefaultScreen(XtDisplay(w))); color.red=ir; /*0-65535*/ color.green=ig; color.blue=ib; XAllocColor(XtDisplay(w),cmap,&color); return(color.pixel); } main(argc, argv) int argc; char **argv; { Widget toplevel; Widget box; int n,col; Arg wargs[10]; toplevel = XtInitialize(argv[0], "prueba", NULL, 0, &argc, argv); box= XtCreateManagedWidget("box",boxWidgetClass,toplevel,NULL,0); w=XtCreateManagedWidget("w",coreWidgetClass,box,NULL,0); n=0; XtSetArg(wargs[n],XtNheight,600);n++; XtSetArg(wargs[n],XtNwidth,600);n++; col=colores(0,0,0); XtSetArg(wargs[n],XtNbackground,col);n++; col=colores(65535,65535,65535); XtSetArg(wargs[n],XtNforeground,col);n++; XtSetValues(w,wargs,n); XtAddEventHandler(w,ExposureMask | StructureNotifyMask,FALSE,redisplay_event,NULL); XtRealizeWidget(toplevel); redisplay(0); dibujo(); XtMainLoop(); }