pjs269@tijc02.uucp (Paul Schmidt ) (02/06/88)
Comp.sources.misc: Volume 2, Issue 46 Submitted-By: "Paul Schmidt" <pjs269@tijc02.UUCP> Archive-Name: spiro Comp.sources.misc: Volume 2, Issue 46 Submitted-By: "Paul Schmidt" <pjs269@tijc02.UUCP> Archive-Name: spiro Here's a little program to draw pretty designs called "spiro". Spiro will draw a pattern to the screen using plot(3X) function calls. The pattern is defined by three numbers input as arguments. The pattern is produced by rotating a circle inside of another circle with a "pen" a set distance from the center of the rotating circle. The arguments are radius(1), radius(2), and and optional distance. The first radius is the stable circle and the second radius is the rotating circle. Author: Paul Schmidt - 2/2/1988 mcnc!rti!tijc02!pjs269 #---------------------CUT HERE----------------------------- #!/bin/sh # Cut above the preceeding line, or cut here if you must. # This is a shar archive. Extract with sh, not csh. # The rest of this file will extract: # README # spiro.h # spiro.c sed 's/^X//' > README << '/*EOF' X(C) Copyright 1988, Paul Schmidt, All Rights Reserved. X XThis code may be copied and distributed for personal use. XCommercial use of this code is forbidden. X Xspiro - Make a pretty design X Xspiro will draw a pattern to the screen using plot(3X) function Xcalls. The pattern is defined by three numbers input as arguments. XThe pattern is produced by rotating a circle inside of another Xcircle with a "pen" a set distance from the center of the rotating Xcircle. The arguments are radius(1), radius(2), and and optional Xdistance. The first radius is the stable circle and the second Xradius is the rotating circle. X XIt is easier to see how it works by running it. X XExample: X spiro 23 17 11 X XTo compile: X X cc -O -o spiro spiro.c -lXXXX -lm X where XXXX is the plotting device whose library is found Xin /usr/lib/libXXXX.a. X XAuthor: X Paul Schmidt - 2/2/1988 X mcnc!rti!tijc02!pjs269 /*EOF ls -l README sed 's/^X//' > spiro.h << '/*EOF' X#define MAX(X,Y) ( (X) > (Y) ? (X) : (Y) ) X#ifndef _ABS X#define _ABS(X,Y) ( (X) > (Y) ? (X) - (Y) : (Y) - (X) ) X#endif X X/* Defaults for the TEKTRONIX 4014 terminal */ X#define LO_X 0 X#define LO_Y 0 X#define HI_X 3120 X#define HI_Y 3120 /*EOF ls -l spiro.h sed 's/^X//' > spiro.c << '/*EOF' X/* X** (C) Copyright 1988, Paul Schmidt, All Rights Reserved. X** X** This code may be copied and distributed for personal use. X** Commercial use of this code is forbidden. X** X** spiro - Make a pretty design X** X** spiro will draw a pattern to the screen using plot(3X) function X** calls. The pattern is defined by three numbers input as arguments. X** The pattern is produced by rotating a circle inside of another X** circle with a "pen" a set distance from the center of the rotating X** circle. The arguments are radius(1), radius(2), and and optional X** distance. The first radius is the stable circle and the second X** radius is the rotating circle. X** X** It is easier to see how it works by running it. X** X** Example: X** spiro 23 17 11 X** X** To compile: X** X** cc -O -o spiro spiro.c -lXXXX -lm X** X** where XXXX is the plotting device whose library is found X** in /usr/lib/libXXXX.a. X** X** Author: X** Paul Schmidt - 2/2/1988 X** mcnc!rti!tijc02!pjs269 X*/ X X#include <math.h> X#include "spiro.h" X Xstruct pos X{ X double x; X double y; X}; X Xmain(argc, argv) Xint argc; Xchar *argv[]; X{ X double size1, size2, dist, d; X struct pos center; X double loops; X double inc1, inc2; X double angle1, angle2; X double scale; X X if ((argc < 3) || (argc > 4)) X { X printf("Usage: %s number number [number]\n", argv[0]); X exit(1); X } X X size1 = (double)atoi(argv[1]); X size2 = (double)atoi(argv[2]); X if (argc == 4) X dist = (double)atoi(argv[3]); X else X dist = size2/2.0; X X inc1 = 0.2; X loops = 2.0*M_PI*MAX(size1, size2)/(double)gcd((int)size1, (int)size2); X X scale = (HI_X/2)/(_ABS(size1 - size2) + dist); X size1 *= scale; X size2 *= scale; X dist *= scale; X X space(LO_X, LO_Y, HI_X, HI_Y); X openpl(); X erase(); X X center.x = (HI_X - LO_X)/2 - 1; X center.y = (HI_Y - LO_Y)/2 - 1; X X move((int)(center.x + size1 - size2 + dist), (int)center.y); X X linemod("solid"); X X d = size1 - size2; X angle1 = angle2 = 0; X inc2 = inc1-inc1*((double)size1/(double)size2); X for (;angle1 < loops; angle1+=inc1, angle2 += inc2) X { X struct pos p1, p2; X X p1.x = cos(angle1)*d + center.x; X p1.y = sin(angle1)*d + center.y; X X p2.x = cos(angle2)*dist + p1.x; X p2.y = sin(angle2)*dist + p1.y; X X cont((int)p2.x, (int)p2.y); X } X move(0, 0); X closepl(); X exit(); X} X X/* X** Calculate the greatest common denominator. X*/ Xgcd(i, j) Xint i, j; X{ X while (j != 0) X { X int temp; X X temp = j; X j = i % j; X i = temp; X } X return(i); X} /*EOF ls -l spiro.c exit