home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / compsrcs / misc / volume02 / spiro < prev    next >
Encoding:
Internet Message Format  |  1991-08-27  |  5.3 KB

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