home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume2 / spiro < prev    next >
Encoding:
Internet Message Format  |  1991-08-07  |  4.8 KB

  1. From: pjs269@tijc02.uucp (Paul Schmidt        )
  2. Newsgroups: comp.sources.misc
  3. Subject: v02i046: spiro - generate pretty patterns
  4. Message-ID: <7194@ncoast.UUCP>
  5. Date: 6 Feb 88 01:27:03 GMT
  6. Approved: allbery@ncoast.UUCP
  7.  
  8. Comp.sources.misc: Volume 2, Issue 46
  9. Submitted-By: "Paul Schmidt" <pjs269@tijc02.UUCP>
  10. Archive-Name: spiro
  11.  
  12. Here's a little program to draw pretty designs called "spiro".
  13.  
  14. Spiro will draw a pattern to the screen using plot(3X) function
  15. calls.  The pattern is defined by three numbers input as arguments.
  16. The pattern is produced by rotating a circle inside of another
  17. circle with a "pen" a set distance from the center of the rotating
  18. circle.  The arguments are radius(1), radius(2), and and optional
  19. distance.  The first radius is the stable circle and the second
  20. radius is the rotating circle.
  21.  
  22. Author:
  23.     Paul Schmidt - 2/2/1988
  24.     mcnc!rti!tijc02!pjs269
  25.  
  26. #---------------------CUT HERE-----------------------------
  27. #!/bin/sh
  28. # Cut above the preceeding line, or cut here if you must.
  29. # This is a shar archive.  Extract with sh, not csh.
  30. # The rest of this file will extract:
  31. #     README
  32. #     spiro.h
  33. #     spiro.c
  34. sed 's/^X//' > README << '/*EOF'
  35. X(C) Copyright 1988, Paul Schmidt, All Rights Reserved.
  36. X
  37. XThis code may be copied and distributed for personal use.
  38. XCommercial use of this code is forbidden.
  39. X
  40. Xspiro - Make a pretty design
  41. X
  42. Xspiro will draw a pattern to the screen using plot(3X) function
  43. Xcalls.  The pattern is defined by three numbers input as arguments.
  44. XThe pattern is produced by rotating a circle inside of another
  45. Xcircle with a "pen" a set distance from the center of the rotating
  46. Xcircle.  The arguments are radius(1), radius(2), and and optional
  47. Xdistance.  The first radius is the stable circle and the second
  48. Xradius is the rotating circle.
  49. X
  50. XIt is easier to see how it works by running it.
  51. X
  52. XExample:
  53. X    spiro 23 17 11
  54. X
  55. XTo compile:
  56. X
  57. X    cc -O -o spiro spiro.c -lXXXX -lm
  58. X    where XXXX is the plotting device whose library is found
  59. Xin /usr/lib/libXXXX.a.
  60. X
  61. XAuthor:
  62. X    Paul Schmidt - 2/2/1988
  63. X    mcnc!rti!tijc02!pjs269
  64. /*EOF
  65. ls -l README
  66. sed 's/^X//' > spiro.h << '/*EOF'
  67. X#define MAX(X,Y) ( (X) > (Y) ? (X) : (Y) )
  68. X#ifndef _ABS
  69. X#define _ABS(X,Y) ( (X) > (Y) ? (X) - (Y) : (Y) - (X) )
  70. X#endif
  71. X
  72. X/* Defaults for the TEKTRONIX 4014 terminal */
  73. X#define LO_X 0
  74. X#define LO_Y 0
  75. X#define HI_X 3120
  76. X#define HI_Y 3120
  77. /*EOF
  78. ls -l spiro.h
  79. sed 's/^X//' > spiro.c << '/*EOF'
  80. X/*
  81. X**    (C) Copyright 1988, Paul Schmidt, All Rights Reserved.
  82. X**
  83. X**    This code may be copied and distributed for personal use.
  84. X**    Commercial use of this code is forbidden.
  85. X**
  86. X**    spiro - Make a pretty design
  87. X**
  88. X**    spiro will draw a pattern to the screen using plot(3X) function
  89. X**    calls.  The pattern is defined by three numbers input as arguments.
  90. X**    The pattern is produced by rotating a circle inside of another
  91. X**    circle with a "pen" a set distance from the center of the rotating
  92. X**    circle.  The arguments are radius(1), radius(2), and and optional
  93. X**    distance.  The first radius is the stable circle and the second
  94. X**    radius is the rotating circle.
  95. X**
  96. X**    It is easier to see how it works by running it.
  97. X**
  98. X**    Example:
  99. X**        spiro 23 17 11
  100. X**
  101. X**    To compile:
  102. X**
  103. X**        cc -O -o spiro spiro.c -lXXXX -lm
  104. X**
  105. X**        where XXXX is the plotting device whose library is found
  106. X**    in /usr/lib/libXXXX.a.
  107. X**
  108. X**    Author:
  109. X**        Paul Schmidt - 2/2/1988
  110. X**        mcnc!rti!tijc02!pjs269
  111. X*/
  112. X
  113. X#include <math.h>
  114. X#include "spiro.h"
  115. X
  116. Xstruct pos
  117. X{
  118. X    double    x;
  119. X    double    y;
  120. X};
  121. X
  122. Xmain(argc, argv)
  123. Xint argc;
  124. Xchar *argv[];
  125. X{
  126. X    double size1, size2, dist, d;
  127. X    struct pos center;
  128. X    double loops;
  129. X    double inc1, inc2;
  130. X    double angle1, angle2;
  131. X    double scale;
  132. X
  133. X    if ((argc < 3) || (argc > 4))
  134. X    {
  135. X        printf("Usage: %s number number [number]\n", argv[0]);
  136. X        exit(1);
  137. X    }
  138. X
  139. X    size1 = (double)atoi(argv[1]);
  140. X    size2 = (double)atoi(argv[2]);
  141. X    if (argc == 4)
  142. X        dist = (double)atoi(argv[3]);
  143. X    else
  144. X        dist = size2/2.0;
  145. X
  146. X    inc1 = 0.2;
  147. X    loops = 2.0*M_PI*MAX(size1, size2)/(double)gcd((int)size1, (int)size2);
  148. X
  149. X    scale = (HI_X/2)/(_ABS(size1 - size2) + dist);
  150. X    size1 *= scale;
  151. X    size2 *= scale;
  152. X    dist *= scale;
  153. X
  154. X    space(LO_X, LO_Y, HI_X, HI_Y);
  155. X    openpl();
  156. X    erase();
  157. X
  158. X    center.x = (HI_X - LO_X)/2 - 1;
  159. X    center.y = (HI_Y - LO_Y)/2 - 1;
  160. X
  161. X    move((int)(center.x + size1 - size2 + dist), (int)center.y);
  162. X
  163. X    linemod("solid");
  164. X
  165. X    d = size1 - size2;
  166. X    angle1 = angle2 = 0;
  167. X    inc2 = inc1-inc1*((double)size1/(double)size2);
  168. X    for (;angle1 < loops; angle1+=inc1, angle2 += inc2)
  169. X    {
  170. X        struct pos p1, p2;
  171. X
  172. X        p1.x = cos(angle1)*d + center.x;
  173. X        p1.y = sin(angle1)*d + center.y;
  174. X
  175. X        p2.x = cos(angle2)*dist + p1.x;
  176. X        p2.y = sin(angle2)*dist + p1.y;
  177. X
  178. X        cont((int)p2.x, (int)p2.y);
  179. X    }
  180. X    move(0, 0);
  181. X    closepl();
  182. X    exit();
  183. X}
  184. X
  185. X/*
  186. X**    Calculate the greatest common denominator.
  187. X*/
  188. Xgcd(i, j)
  189. Xint i, j;
  190. X{
  191. X    while (j != 0)
  192. X    {
  193. X        int temp;
  194. X
  195. X        temp = j;
  196. X        j = i % j;
  197. X        i = temp;
  198. X    }
  199. X    return(i);
  200. X}
  201. /*EOF
  202. ls -l spiro.c
  203. exit
  204.