/* * testlayer2.c */ #include <stdio.h> #include <math.h> #include <eggxlib.h> double f(double x) { return sin(x) + sin(3 * x); } int main() { /* */ int win; double xmin, xmax, ymin, ymax; double a, b, pi, x, y, c, t, dt; int i, j, N, Nt; double dx; /* */ pi = 4 * atan(1.0); a = 0; b = 2 * pi; /* */ win = eggx_gopen(500, 500); eggx_winname(win, "mygraph"); eggx_gclr(win); xmin = a - (b - a) / 10; xmax = b + (b - a) / 10; ymin = - 2.0; ymax = 2.0; eggx_window(win, xmin, ymin, xmax, ymax); eggx_newcolor(win, "green"); /* */ N = 200; dx = (b - a) / N; Nt = 500; c = 1; dt = 10.0 / Nt; for (i = 0; i <= Nt; i++) { eggx_layer(win, i & 1, 1 - (i & 1)); eggx_gclr(win); t = i * dt; x = a; y = f(x - c * t); eggx_line(win, x, y, PENUP); for (j = 1; j <= N; j++) { x = j * dx; y = f(x - c * t); eggx_line(win, x, y, PENDOWN); } } eggx_ggetch(win); /* eggx */ eggx_gclose(win); return 0; }