home *** CD-ROM | disk | FTP | other *** search
- /*
- * $Source: /mit/sipbsrc/uus/src/xscreensaver/RCS/scaling.c,v $
- * $Author: jik $
- *
- * This file is part of xscreensaver. It contains code for figuring
- * out screen aspect ratios. This stuff is a bit of magic that
- * probably doesn't work very well since the X server invariably seems
- * to have incorrect numbers for its aspect ratios, but it makes me
- * sleep better at night to know it's here.
- *
- * Author: Jonathan Kamens, MIT Project Athena and
- * MIT Student Information Processing Board
- *
- * Copyright (c) 1989 by Jonathan Kamens. This code may be
- * distributed freely as long as this notice is kept intact in its
- * entirety and every effort is made to send all corrections and
- * improvements to the code back to the author. Also, don't try to
- * make any money off of it or pretend that you wrote it.
- */
-
- #ifndef lint
- static char rcsid_scaling_c[] = "$Header: scaling.c,v 1.5 89/02/28 06:55:23 jik Exp $";
- #endif
-
- #include <math.h>
- #include <X11/Intrinsic.h>
- #include <X11/Xos.h>
- #include "xsaver.h"
- #include "globals.h"
-
- extern double pow(), sqrt();
-
- double cm_per_pixel_x;
- double cm_per_pixel_y;
-
- void init_scaling()
- {
- cm_per_pixel_x = (double) DisplayWidthMM(dpy, screen) /
- display_width / (double) 10.0;
- cm_per_pixel_y = (double) DisplayHeightMM(dpy, screen) /
- display_height / (double) 10.0;
- }
-
- double cm_x(x)
- int x;
- {
- return((double) (cm_per_pixel_x * x));
- }
-
- double cm_y(y)
- int y;
- {
- return((double) (cm_per_pixel_y * y));
- }
-
-
- double line_length_cm(x, y)
- int x, y;
- {
- return(sqrt((double) (pow(cm_x(x), 2.0) + pow(cm_y(y), 2.0))));
- }
-
-
- int calc_delay(x_off, y_off, velocity)
- int x_off, y_off, velocity;
- {
- double line_length;
- double delay_minutes, delay_seconds;
- int delay;
-
- line_length = line_length_cm(x_off, y_off);
- delay_minutes = line_length / (double) velocity;
- delay_seconds = 60.0 * delay_minutes;
- delay = (int) ((delay_seconds - (double) ((int) delay_seconds)) * 1000);
- return (delay);
- }
-
-