+
+ /* Get the delay between animation frames */
+
+ si->delay = get_integer_resource (dpy, "delay", "Integer");
+
+ if (si->delay < 0) si->delay = 0;
+ si->TTL = get_integer_resource(dpy, "ttl", "TTL");
+
+ /* Create the Graphics Contexts that will be used to draw things */
+
+ gcv.foreground =
+ get_pixel_resource (dpy, si->cmap, "sweepColor", "SweepColor");
+ si->hi = XCreateGC(dpy, win, GCForeground, &gcv);
+ gcv.font = si->font->fid;
+ si->text = XCreateGC(dpy, win, GCForeground|GCFont, &gcv);
+ gcv.foreground = get_pixel_resource(dpy, si->cmap,
+ "scopeColor", "ScopeColor");
+ si->erase = XCreateGC (dpy, win, GCForeground, &gcv);
+ gcv.foreground = get_pixel_resource(dpy, si->cmap,
+ "gridColor", "GridColor");
+ si->grid = XCreateGC (dpy, win, GCForeground, &gcv);
+
+ reshape (si);
+
+ /* Compute pixel values for fading text on the display */
+ {
+ char *s = get_string_resource(dpy, "textColor", "TextColor");
+ XParseColor(dpy, si->cmap, s, &start);
+ if (s) free (s);
+ s = get_string_resource(dpy, "scopeColor", "ScopeColor");
+ XParseColor(dpy, si->cmap, s, &end);
+ if (s) free (s);
+ }
+
+ rgb_to_hsv (start.red, start.green, start.blue, &h1, &s1, &v1);
+ rgb_to_hsv (end.red, end.green, end.blue, &h2, &s2, &v2);
+
+ si->text_steps = get_integer_resource(dpy, "textSteps", "TextSteps");
+ if (si->text_steps < 0 || si->text_steps > 255)
+ si->text_steps = 10;
+
+ si->text_colors = (XColor *) calloc(si->text_steps, sizeof(XColor));
+ make_color_ramp (dpy, si->cmap,
+ h1, s1, v1,
+ h2, s2, v2,
+ si->text_colors, &si->text_steps,
+ False, True, False);
+
+ /* Compute the pixel values for the fading sweep */
+
+ {
+ char *s = get_string_resource(dpy, "sweepColor", "SweepColor");
+ XParseColor(dpy, si->cmap, s, &start);
+ if (s) free (s);
+ }
+
+ rgb_to_hsv (start.red, start.green, start.blue, &h1, &s1, &v1);
+
+ si->sweep_degrees = get_integer_resource(dpy, "sweepDegrees", "Degrees");
+ if (si->sweep_degrees <= 0) si->sweep_degrees = 20;
+ if (si->sweep_degrees > 350) si->sweep_degrees = 350;
+
+ si->sweep_segs = get_integer_resource(dpy, "sweepSegments", "SweepSegments");
+ if (si->sweep_segs < 1 || si->sweep_segs > 255)
+ si->sweep_segs = 255;
+
+ si->sweep_colors = (XColor *) calloc(si->sweep_segs, sizeof(XColor));
+ make_color_ramp (dpy, si->cmap,
+ h1, s1, v1,
+ h2, s2, v2,
+ si->sweep_colors, &si->sweep_segs,
+ False, True, False);
+
+ if (si->sweep_segs <= 0)
+ si->sweep_segs = 1;
+
+
+# ifdef HAVE_PING
+ si->sensor_info = (void *) init_ping(si);
+# else /* !HAVE_PING */
+ parse_mode (dpy, 0); /* just to check argument syntax */
+# endif /* !HAVE_PING */
+
+ if (!si->sensor)
+ {
+ si->sensor = simulator;
+ si->sensor_info = (void *) init_sim(dpy);
+ if (! si->sensor_info)
+ exit(1);
+ }
+
+ /* Done */
+
+ return si;
+}
+
+
+static unsigned long
+sonar_draw (Display *dpy, Window window, void *closure)
+{
+ sonar_info *si = (sonar_info *) closure;
+ Bogie *bl;
+ struct timeval start, finish;
+ long delay;
+
+# ifdef HAVE_COCOA /* repaint the whole window so that antialiasing works */
+ XClearWindow (dpy,window);
+ XFillRectangle (dpy, window, si->erase, 0, 0, si->width, si->height);
+# endif
+
+ /* Call the sensor and display the results */
+
+# ifdef GETTIMEOFDAY_TWO_ARGS
+ gettimeofday(&start, (struct timezone *) 0);
+# else
+ gettimeofday(&start);
+# endif
+ bl = si->sensor(si, si->sensor_info);
+ Sonar(si, bl);
+
+ /* Set up and sleep for the next one */
+
+ si->current = (si->current - 1) % 90;
+ if (si->current == 0)
+ si->sweepnum++;
+
+# ifdef GETTIMEOFDAY_TWO_ARGS
+ gettimeofday(&finish, (struct timezone *) 0);
+# else
+ gettimeofday(&finish);
+# endif
+
+ delay = si->delay - delta(&start, &finish);
+ if (delay < 0) delay = 0;
+ return delay;
+}
+
+
+static void
+sonar_reshape (Display *dpy, Window window, void *closure,
+ unsigned int w, unsigned int h)
+{
+ sonar_info *si = (sonar_info *) closure;
+ XClearWindow (si->dpy, si->win);
+ reshape (si);
+}
+
+static Bool
+sonar_event (Display *dpy, Window window, void *closure, XEvent *event)
+{
+ return False;