Skip to content

Commit

Permalink
Update to new coding standards.
Browse files Browse the repository at this point in the history
  • Loading branch information
anachrocomputer committed Aug 2, 2020
1 parent 589c9ec commit 85de583
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 78 deletions.
2 changes: 1 addition & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ G-code or SVG. This would be a big change to the library and would
introduce a lot of new code. It would also be a big testing issue.
* Add circles and arcs to the PenDownDistance and plot time calculations.
* Make plot time take into account pen speed if '-v' is used.
* Add Doxygen comments to the library source.
* Add Doxygen comments to the library source and add a Makefile rule for Doxygen.

## Turtle library
* Implement run-time option setting in all Turtle plots, and in the
Expand Down
31 changes: 15 additions & 16 deletions pin_and_cotton.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#define LEFT 8


int main (int argc, char * const argv[])
int main(int argc, char * const argv[])
{
/* High-Resolution Computer Graphics Using C, by Ian O. Angell, 1989.
Exercise 1.10, page 21. */
Expand Down Expand Up @@ -45,32 +45,31 @@ int main (int argc, char * const argv[])
double xc;
double maxx, maxy;

while ((opt = getopt (argc, argv, "no:p:s:t:v:")) != -1) {
while ((opt = getopt(argc, argv, "no:p:s:t:v:")) != -1) {
switch (opt) {
case 'n':
case 'o':
case 'p':
case 's':
case 't':
case 'v':
plotopt (opt, optarg);
plotopt(opt, optarg);
break;
default: /* '?' */
fprintf (stderr, "Usage: %s [-p pen] [-s <size>] [-t title]\n",
argv[0]);
fprintf (stderr, " <size> ::= A1 | A2 | A3 | A4 | A5\n");
exit (EXIT_FAILURE);
fprintf(stderr, "Usage: %s [-p pen] [-s <size>] [-t title]\n", argv[0]);
fprintf(stderr, " <size> ::= A1 | A2 | A3 | A4 | A5\n");
exit(EXIT_FAILURE);
}
}

plotbegin (0);
plotbegin(0);

getplotsize (&maxx, &maxy);
getplotsize(&maxx, &maxy);

xc = maxx / 2.0;

/* Draw square border */
rectangle (xc - (maxy / 2.0), 0.0, xc + (maxy / 2.0), maxy);
rectangle(xc - (maxy / 2.0), 0.0, xc + (maxy / 2.0), maxy);

xoff = (maxx - maxy) / 2.0;

Expand Down Expand Up @@ -145,28 +144,28 @@ int main (int argc, char * const argv[])
else
pin2 = line[j].p1;

// printf ("Drawing to pin %d.\n", pin2);
// printf("Drawing to pin %d.\n", pin2);
}
else {
pin1 = (pin1 + 1) % (n * 4);
needmove = 1;
// printf ("Moving to pin %d\n", pin1);
// printf("Moving to pin %d\n", pin1);
}
} while (j >= nlines);

if (needmove)
moveto (pin[pin1].x, pin[pin1].y);
moveto(pin[pin1].x, pin[pin1].y);

lineto (pin[pin2].x, pin[pin2].y);
lineto(pin[pin2].x, pin[pin2].y);
line[j].drawn = 1;
pin1 = pin2;
needmove = 0;
}


plotend ();
plotend();

printf ("%d pins, %d lines drawn\n", n * 4, nlines);
printf("%d pins, %d lines drawn\n", n * 4, nlines);

return (0);
}
59 changes: 30 additions & 29 deletions spiralsq.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@

#define RADIANS (M_PI / 180.0)

void ringoboxes2 (double x0, double y0, double radius, int nboxes, int ninner, int offset, double slant);
#define SLANT_DEGREES (20.0)

void ringoboxes2(const double x0, const double y0, const double radius, int nboxes, const int ninner, const int offset, const double slant);

int main (int argc, char * const argv[])

int main(int argc, char * const argv[])
{
int opt;
int i;
Expand All @@ -23,69 +25,68 @@ int main (int argc, char * const argv[])
double r;
double slant;

while ((opt = getopt (argc, argv, "no:p:s:t:v:")) != -1) {
while ((opt = getopt(argc, argv, "no:p:s:t:v:")) != -1) {
switch (opt) {
case 'n':
case 'o':
case 'p':
case 's':
case 't':
case 'v':
plotopt (opt, optarg);
plotopt(opt, optarg);
break;
default: /* '?' */
fprintf (stderr, "Usage: %s [-p pen] [-s <size>] [-t title]\n",
argv[0]);
fprintf (stderr, " <size> ::= A1 | A2 | A3 | A4 | A5\n");
// exit (EXIT_FAILURE);
fprintf(stderr, "Usage: %s [-p pen] [-s <size>] [-t title]\n", argv[0]);
fprintf(stderr, " <size> ::= A1 | A2 | A3 | A4 | A5\n");
// exit(EXIT_FAILURE);
}
}

plotbegin (0);
plotbegin(0);

getplotsize (&maxx, &maxy);
getplotsize(&maxx, &maxy);

xc = maxx / 2.0;
yc = maxy / 2.0;

height = maxy;

/* Draw square border */
rectangle (xc - (height / 2.0), 0.0, xc + (height / 2.0), maxy);
rectangle(xc - (height / 2.0), 0.0, xc + (height / 2.0), maxy);

radius = height / 12.0;

/* Draw four concentric circles of squares */
for (i = 0; i < 4; i++) {
if (i & 1)
slant = 20.0;
slant = SLANT_DEGREES;
else
slant = -20.0;
slant = -SLANT_DEGREES;

r = radius * (i + 1.5);
ringoboxes2 (xc, yc, r, 18 * (i + 1), 1, 0, slant * RADIANS);
ringoboxes2(xc, yc, r, 18 * (i + 1), 1, 0, slant * RADIANS);
}

pencolr (1);
pencolr(1);

/* Draw four concentric circles of squares */
for (i = 0; i < 4; i++) {
if (i & 1)
slant = 20.0;
slant = SLANT_DEGREES;
else
slant = -20.0;
slant = -SLANT_DEGREES;

r = radius * (i + 1.5);
ringoboxes2 (xc, yc, r, 18 * (i + 1), 1, 1, slant * RADIANS);
ringoboxes2(xc, yc, r, 18 * (i + 1), 1, 1, slant * RADIANS);
}

plotend ();
plotend();

return (0);
}


void ringoboxes2 (double x0, double y0, double radius, int nboxes, int ninner, int offset, double slant)
void ringoboxes2(const double x0, const double y0, const double radius, int nboxes, const int ninner, const int offset, const double slant)
{
int i, j, k, n;
double side, s2;
Expand Down Expand Up @@ -113,12 +114,12 @@ void ringoboxes2 (double x0, double y0, double radius, int nboxes, int ninner, i
if (offset)
theta += delta / 2.0;

s = sin (theta);
c = cos (theta);
s = sin(theta);
c = cos(theta);

for (k = 0; k < ninner; k++) {
sr = sin (slant);
cr = cos (slant);
sr = sin(slant);
cr = cos(slant);

/* Set up a square */
x[0] = -s2;
Expand Down Expand Up @@ -158,11 +159,11 @@ void ringoboxes2 (double x0, double y0, double radius, int nboxes, int ninner, i
}

/* Draw the rotated square */
moveto (rx[0], ry[0]);
lineto (rx[1], ry[1]);
lineto (rx[2], ry[2]);
lineto (rx[3], ry[3]);
lineto (rx[0], ry[0]);
moveto(rx[0], ry[0]);
lineto(rx[1], ry[1]);
lineto(rx[2], ry[2]);
lineto(rx[3], ry[3]);
lineto(rx[0], ry[0]);
}
}
}
63 changes: 31 additions & 32 deletions superellipse.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
#include "hpgllib.h"


void superellipse (double x0, double y0, double a, double b, double theta, double d);
void superellipse(const double x0, const double y0, const double a, const double b, const double theta, const double d);


int main (int argc, char * const argv[])
int main(int argc, char * const argv[])
{
int opt;
double xc, yc;
Expand All @@ -33,39 +33,38 @@ int main (int argc, char * const argv[])
#endif
int i;

while ((opt = getopt (argc, argv, "no:p:s:t:v:")) != -1) {
while ((opt = getopt(argc, argv, "no:p:s:t:v:")) != -1) {
switch (opt) {
case 'n':
case 'o':
case 'p':
case 's':
case 't':
case 'v':
plotopt (opt, optarg);
plotopt(opt, optarg);
break;
default: /* '?' */
fprintf (stderr, "Usage: %s [-p pen] [-s <size>] [-t title]\n",
argv[0]);
fprintf (stderr, " <size> ::= A1 | A2 | A3 | A4 | A5\n");
exit (EXIT_FAILURE);
fprintf(stderr, "Usage: %s [-p pen] [-s <size>] [-t title]\n", argv[0]);
fprintf(stderr, " <size> ::= A1 | A2 | A3 | A4 | A5\n");
exit(EXIT_FAILURE);
}
}

/* Select first pen and draw border */
plotbegin (1);
plotbegin(1);

getplotsize (&maxx, &maxy);
getplotsize(&maxx, &maxy);

xc = maxx / 2.0;
yc = maxy / 2.0;

/* Draw axes */
moveto (0.0, yc);
lineto (maxx, yc);
moveto (xc, 0.0);
lineto (xc, maxy);
moveto(0.0, yc);
lineto(maxx, yc);
moveto(xc, 0.0);
lineto(xc, maxy);

pencolr (1);
pencolr(1);

#ifndef DEVELOPMENT
theta = 0.0;
Expand All @@ -75,40 +74,40 @@ int main (int argc, char * const argv[])
/* if a==b, we'll get squares and circles */
a = (45.0 + (5.0 * i)) * 40.0;
b = (45.0 + (5.0 * i)) * 40.0;
superellipse (xc, yc, a, b, theta, sq[i]);
superellipse(xc, yc, a, b, theta, sq[i]);
}

a = (45.0 + (5.0 * i)) * 40.0;
b = (45.0 + (5.0 * i)) * 40.0;
rectangle (xc - a, yc - b, xc + a, yc + b);
rectangle(xc - a, yc - b, xc + a, yc + b);
#else
delta = (M_PI * 2.0) / 5.0;

for (i = 0; i < 5; i++) {
a = 87.0 * 40.0;
b = 87.0 * 40.0;
theta = delta * (double)i;
superellipse (xc, yc, a, b, theta, 2.8);
superellipse(xc, yc, a, b, theta, 2.8);
}

twroot2 = pow (2.0, 1.0 / 12.0);
twroot2 = pow(2.0, 1.0 / 12.0);
theta = M_PI / 4.0;

for (i = 0; i <= 12; i++) {
/* if a==b, we'll get squares and circles */
a = (100.0 + (6.0 * i)) * 40.0;
b = (100.0 + (6.0 * i)) * 40.0;
superellipse (X0, Y0, a, b, theta, pow (twroot2, (double)(12 - i)));
superellipse(X0, Y0, a, b, theta, pow(twroot2, (double)(12 - i)));
}
#endif

plotend ();
plotend();

return (0);
}


void superellipse (double x0, double y0, double a, double b, double theta, double d)
void superellipse(const double x0, const double y0, const double a, const double b, const double theta, const double d)
{
double t;
double delta;
Expand All @@ -121,31 +120,31 @@ void superellipse (double x0, double y0, double a, double b, double theta, doubl

delta = (2.0 * M_PI) / (double)npts;

sintheta = sin (theta);
costheta = cos (theta);
sintheta = sin(theta);
costheta = cos(theta);

for (i = 0; i <= npts; i++) {
t = (double)i * delta;

st = sin (t);
ct = cos (t);
st = sin(t);
ct = cos(t);

if (st < 0.0)
sinpt = -pow (-st, 2.0 / d);
sinpt = -pow(-st, 2.0 / d);
else
sinpt = pow (st, 2.0 / d);
sinpt = pow(st, 2.0 / d);

if (ct < 0.0)
cospt = -pow (-ct, 2.0 / d);
cospt = -pow(-ct, 2.0 / d);
else
cospt = pow (ct, 2.0 / d);
cospt = pow(ct, 2.0 / d);

x = (a * cospt * costheta) - (b * sinpt * sintheta);
y = (a * cospt * sintheta) + (b * sinpt * costheta);

if (i == 0)
moveto (x0 + x, y0 + y);
moveto(x0 + x, y0 + y);
else
lineto (x0 + x, y0 + y);
lineto(x0 + x, y0 + y);
}
}

0 comments on commit 85de583

Please sign in to comment.