home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / x / volume3 / xsaver / part03 / scaling.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-03-10  |  2.0 KB  |  78 lines

  1. /*
  2.  * $Source: /mit/sipbsrc/uus/src/xscreensaver/RCS/scaling.c,v $
  3.  * $Author: jik $
  4.  *
  5.  * This file is part of xscreensaver.  It contains code for figuring
  6.  * out screen aspect ratios.  This stuff is a bit of magic that
  7.  * probably doesn't work very well since the X server invariably seems
  8.  * to have incorrect numbers for its aspect ratios, but it makes me
  9.  * sleep better at night to know it's here.
  10.  *
  11.  * Author: Jonathan Kamens, MIT Project Athena and
  12.  *                          MIT Student Information Processing Board
  13.  *
  14.  * Copyright (c) 1989 by Jonathan Kamens.  This code may be
  15.  * distributed freely as long as this notice is kept intact in its
  16.  * entirety and every effort is made to send all corrections and
  17.  * improvements to the code back to the author.  Also, don't try to
  18.  * make any money off of it or pretend that you wrote it.
  19.  */
  20.  
  21. #ifndef lint
  22.      static char rcsid_scaling_c[] = "$Header: scaling.c,v 1.5 89/02/28 06:55:23 jik Exp $";
  23. #endif
  24.  
  25. #include <math.h>
  26. #include <X11/Intrinsic.h>
  27. #include <X11/Xos.h>
  28. #include "xsaver.h"
  29. #include "globals.h"
  30.  
  31. extern double pow(), sqrt();
  32.  
  33. double cm_per_pixel_x;
  34. double cm_per_pixel_y;
  35.  
  36. void init_scaling()
  37. {
  38.      cm_per_pixel_x = (double) DisplayWidthMM(dpy, screen) /
  39.       display_width / (double) 10.0;
  40.      cm_per_pixel_y = (double) DisplayHeightMM(dpy, screen) /
  41.       display_height / (double) 10.0;
  42. }
  43.  
  44. double cm_x(x)
  45. int x;
  46. {
  47.      return((double) (cm_per_pixel_x * x));
  48. }
  49.  
  50. double cm_y(y)
  51. int y;
  52. {
  53.      return((double) (cm_per_pixel_y * y));
  54. }
  55.  
  56.      
  57. double line_length_cm(x, y)
  58. int x, y;
  59. {
  60.      return(sqrt((double) (pow(cm_x(x), 2.0) + pow(cm_y(y), 2.0))));
  61. }
  62.  
  63.  
  64. int calc_delay(x_off, y_off, velocity)
  65. int x_off, y_off, velocity;
  66. {
  67.      double line_length;
  68.      double delay_minutes, delay_seconds;
  69.      int delay;
  70.      
  71.      line_length = line_length_cm(x_off, y_off);
  72.      delay_minutes = line_length / (double) velocity;
  73.      delay_seconds = 60.0 * delay_minutes;
  74.      delay = (int) ((delay_seconds - (double) ((int) delay_seconds)) * 1000);
  75.      return (delay);
  76. }
  77.  
  78.