rendered paste bodydiff -urN Sgraph/Makefile new/Sgraph/Makefile--- Sgraph/Makefile 1970-01-01 09:00:00.000000000 +0900+++ new/Sgraph/Makefile 2010-11-04 00:41:04.000000000 +0900@@ -0,0 +1,18 @@+INCLUDES = -I/usr/X11R6/include+LIBS = -lX11 -lXt -lXpm -L/usr/X11R6/lib -lm+FLAGS =+CC = gcc++OBJS = main.o function.o++graph : $(OBJS)+ $(CC) -o graph $(FLAGS) $(OBJS) $(LIBS)++main.o : main.c+ $(CC) $(FLAGS) $(INCLUDES) -c main.c++function.o : function.c+ $(CC) $(FLAGS) $(INCLUDES) -c function.c++clean :+ rm -f $(OBJS) graph *.corediff -urN Sgraph/common.h new/Sgraph/common.h--- Sgraph/common.h 1970-01-01 09:00:00.000000000 +0900+++ new/Sgraph/common.h 2010-11-04 00:41:04.000000000 +0900@@ -0,0 +1,26 @@+#include <stdio.h>+#include <unistd.h>+#include <math.h>+#include <X11/Xlib.h>+#include <X11/Xutil.h>+#include <X11/Intrinsic.h>+#include <X11/Shell.h>+#include <X11/StringDefs.h>++#define SQ(x) ((x)*(x))++int width, height;+Display *disp;+Window win;+Pixmap map;+GC gc, mgc, rgc;+XGCValues gcv;+XEvent ev;++static char *colors[] = {"black", "blue4", "green4", "cyan4", "red4", + "magenta4", "brown", "lightgray", "gray", "blue", "green", "cyan", + "red", "magenta", "yellow", "white", + "gray0", "gray6", "gray12", "gray18", "gray24", "gray30", "gray36", + "gray42", "gray48", "gray54", "gray60", "gray66", "gray72", + "gray78", "gray84", "gray90"};+diff -urN Sgraph/function.c new/Sgraph/function.c--- Sgraph/function.c 1970-01-01 09:00:00.000000000 +0900+++ new/Sgraph/function.c 2010-11-04 00:41:04.000000000 +0900@@ -0,0 +1,243 @@+#include "common.h"++XtIntervalId *id;++double func(double x,double y,double ex,double ey,double ez);+static void graph_timer();++/* マウスの右ボタンをクリックすると終了します */++void graph(linecolor)+char *linecolor;+{+ + XColor def, closest;+ Font font;+ + int i, j, k;++ int vvv=0;+ + +/*+ width = DisplayWidth(disp, 0)/4;+ height = DisplayHeight(disp, 0)/2;+*//*+ XMapWindow(disp, win);+ XFlush(disp);+*/+ +// gcv.font = font;+ +// XChangeGC(disp, mgc, GCFont, &gcv);+ ++// graph_timer();+// id = XtAddTimeOut( 1, graph_timer, NULL);++ while(True) graph_timer();//, usleep(1);+ ++}++/* カラーバーを表示します */+/* マウスの右ボタンをクリックすると終了します */++void color_bar() +{+ int i;+ XColor def, closest;++ XMapWindow(disp, win);+ while (True) {+ XNextEvent(disp, &ev);+ if (Button3 == ev.xbutton.button) exit(0);+ for (i = 0; 32 > i; i++) {+ XAllocNamedColor(disp, DefaultColormap(disp, 0), + colors[i], &closest, &def);+ XSetForeground(disp, gc, closest.pixel);+ + if (16 > i)+ XFillRectangle(disp, win, gc, + i * (width / 16), 0, + width / 16, height * 2 / 3);+ + else+ XFillRectangle(disp, win, gc, + (i - 16) * (width / 16), height * 2 / 3, + width / 16, height / 3);+ }; + } +} +++/* マウスの左ボタンをクリックしたところで、四角を描きます */+/* マウスの右ボタンをクリックすると終了します */++void box(linecolor, linewidth)+char *linecolor;+int linewidth;+{+ XColor def, closest;++ XAllocNamedColor(disp, DefaultColormap(disp, 0),+ linecolor, &closest, &def);+ XSetForeground(disp, gc, closest.pixel);+ XSetLineAttributes(disp, gc, linewidth,+ LineSolid, CapButt, JoinMiter);++ XMapWindow(disp, win);++ XFlush(disp);+ + while (True){+ XNextEvent(disp, &ev);+ if (Button3 == ev.xbutton.button) exit(0);+ if (Button1 == ev.xbutton.button) + XDrawRectangle(disp, win, gc,+ ev.xbutton.x, ev.xbutton.y, 10, 10);+ }+}+++/* ブラインドのように画面を消してきます */++void blind(linecolor)+char *linecolor;+{+ XColor def, closest;+ int i, j, width, height;++ XAllocNamedColor(disp, DefaultColormap(disp, 0),+ linecolor, &closest, &def);+ XSetForeground(disp, rgc, closest.pixel);++ XSetSubwindowMode(disp, rgc, IncludeInferiors);++ width = DisplayWidth(disp, 0);+ height = DisplayHeight(disp, 0);+++ for (i = 0; 20 > i; i++)+ for (j = 0; height / 20 > j; j++) {+ XDrawLine(disp, RootWindow(disp, 0), rgc,+ 0, i + j * 20, width, i + j * 20);+ XSync(disp, 0);+ }+++}+++double func(double x,double y,double ex,double ey,double ez)+{+ return 1000 / sqrt( SQ(x-ex) + SQ(y-ey) + SQ(ez) );+// return ex/10 * log( x )/log( y ) * 1000 / sqrt( SQ(x-ex) + SQ(y-ey) + SQ(ez) );+// return ex/10 * log( fabs(x+0.2) )/log( fabs(y+0.3) ) * 1000 / sqrt( SQ(x-ex) + SQ(y-ey) + SQ(ez) );+}++static void graph_timer()+{+ const double RT3 = sqrt(3);+ const int SIZE = 400;+ const int Dpoint = 5;+ const int Dline = 20;+ const int Npoints = SIZE / Dpoint + 1;+++ XPoint points[Npoints];+ + XColor def, closest;+ Font font;+ + int i, j, k, x, y;+ static int ox, oy;++ int vvv=0;+++ while( XCheckTypedWindowEvent(disp, win, MotionNotify, &ev) ){++ ox = ev.xmotion.x - width/2;+ oy = ev.xmotion.y - height;+ }+ + +// printf("%d %d\n", ox, ev.xmotion.x);+ + if( XCheckTypedWindowEvent(disp, win, ButtonPress, &ev) ){+ switch(ev.xbutton.button){+ case Button1:+ ox = ev.xbutton.x - width/2;+ oy = ev.xbutton.y - height;+ x = ox/RT3 - oy;+ y = -ox/RT3 - oy;+ break;+ case Button3:+ exit(0);+ }+ }+ + x = ox/RT3 - oy;+ y = -ox/RT3 - oy;+++ XAllocNamedColor(disp, DefaultColormap(disp, 0),+ "white", &closest, &def);+// printf("past\n");+ + XSetForeground(disp, mgc, closest.pixel);+ XFillRectangle(disp, map, mgc, 0, 0, width, height);++ closest.red = 0x4000;+ closest.green = 0x4000;+ closest.blue = 0x4000;++ XAllocColor(disp, DefaultColormap(disp, 0), &closest);+ XSetForeground(disp, mgc, closest.pixel);++ for(i=0;i<=SIZE;i+=Dline){++ for(j=0,k=0;j<=SIZE;j+=Dpoint,k++){+ //points[k].x = (j-i) * RT3/2 + width/2;+ //points[k].y = -func(j, i, x, y, 7) -(i+j) / 2 + height;+ {+ double ii = i;+ double jj = j;+ double i = ii - SIZE/2;+ double j = jj - SIZE/2; + points[k].x = (j-i) * RT3/2 + width/2;+ points[k].y = -func(j, i, x, y, 7) -(i+j) / 2 + height/2;+ }+ }+ XDrawLines(disp, map, mgc, points, Npoints, CoordModeOrigin);+ for(j=0,k=0;j<=SIZE;j+=Dpoint,k++){+ //points[k].x = (i-j) * RT3/2 + width/2;+ //points[k].y = -func(i, j, x, y, 7) -(i+j) / 2 + height;+ {+ double ii = i;+ double jj = j;+ double i = ii - SIZE/2;+ double j = jj - SIZE/2; + points[k].x = (i-j) * RT3/2 + width/2;+ points[k].y = -func(i, j, x, y, 7) -(i+j) / 2 + height/2;+ }+ }+ XDrawLines(disp, map, mgc, points, Npoints, CoordModeOrigin);+ }++ +// font = XLoadFont(disp, "menu10");++// XSetFont(disp, mgc, font);++ XDrawString(disp, map, mgc, 20, 20, "I love me.",+ strlen("I love me."));+ XDrawString(disp, map, mgc, 20, 40, "たい", strlen("たい"));++ XCopyArea(disp, map, win, gc, 0, 0, width, height, 0, 0);+++// id = XtAddTimeOut( 1, graph_timer, NULL);+ +}diff -urN Sgraph/main.c new/Sgraph/main.c--- Sgraph/main.c 1970-01-01 09:00:00.000000000 +0900+++ new/Sgraph/main.c 2010-11-04 00:41:04.000000000 +0900@@ -0,0 +1,52 @@+#include "common.h"++void graph();+void color_bar() ;+void box();+void pattern();+void blind();++int+main() +{++ static char linecolor1[] = "white";+ static char linecolor2[] = "black";++// char list[200][20];+// int ac[200],i;++ disp = XOpenDisplay(NULL);++ //win = RootWindow(disp, 0);++ width = DisplayWidth(disp, 0);+ height = DisplayHeight(disp, 0);+ + + win = XCreateSimpleWindow(disp, RootWindow(disp, 0), 0, 0, + width = DisplayWidth(disp, 0) / 2, + height = DisplayHeight(disp, 0) / 2, 1, + BlackPixel(disp, 0), WhitePixel(disp, 0));++ map = XCreatePixmap(disp, win, width, height,+ DefaultDepth(disp, DefaultScreen(disp)));++ gc = XCreateGC(disp, win, 0, NULL);+ mgc = XCreateGC(disp, map, 0, NULL);+ rgc = XCreateGC(disp, RootWindow(disp, 0), 0, NULL);+ + XSelectInput(disp, win,+ ButtonPressMask | PointerMotionMask | ExposureMask);+ +// list = XListFonts(disp, "*", 200, ac);+// for(i=0;i<200;i++){+// printf("%s\n", list[i]);+// }+// exit(0);++ XMapWindow(disp, win);++ graph("black");+ +}