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 Apr 28, 2019
1 parent cc463bc commit 3ea3a0e
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 78 deletions.
2 changes: 1 addition & 1 deletion flake.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ struct Finger {
double w2;
};

int main (int argc, char * const argv[])
int main(int argc, char * const argv[])
{
int i;
int j;
Expand Down
50 changes: 22 additions & 28 deletions fraserspiral.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@

#define DEGREES (180.0 / M_PI)

void ringoshapes (double x0, double y0, double radius, int nshapes);
void ringoshapes(const double x0, const double y0, const double radius, const int nshapes);


int main (int argc, char * const argv[])
int main(int argc, char * const argv[])
{
int opt;
int i;
Expand All @@ -22,74 +22,68 @@ int main (int argc, char * const argv[])
double radius;
double r;

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 / 24.0;

/* Draw eleven concentric circles of shapes */
for (i = 0; i < 11; i++) {
r = radius * (i + 1);
ringoshapes (xc, yc, r, 16 + i);
ringoshapes(xc, yc, r, 16 + i);
}

plotend ();
plotend();

return (0);
}


void ringoshapes (double x0, double y0, double radius, int nshapes)
void ringoshapes(const double x0, const double y0, const double radius, const int nshapes)
{
int i;
double theta;
double x, y;
double delta;
double xc, yc;
double d;

delta = 2.0 * M_PI / (double)nshapes;
const double d = radius / 4.0;
const double delta = 2.0 * M_PI / (double)nshapes;

for (i = 0; i < nshapes; i++) {
theta = i * delta;
const double theta = i * delta;

x = (radius * cos (theta)) + x0;
y = (radius * sin (theta)) + y0;
x = (radius * cos(theta)) + x0;
y = (radius * sin(theta)) + y0;

moveto (x, y);

d = radius / 4.0;
moveto(x, y);

xc = (d * cos (theta + (M_PI / 2.0))) + x0;
yc = (d * sin (theta + (M_PI / 2.0))) + y0;
xc = (d * cos(theta + (M_PI / 2.0))) + x0;
yc = (d * sin(theta + (M_PI / 2.0))) + y0;

arc (xc, yc, (delta * 1.2) * DEGREES);
arc(xc, yc, (delta * 1.2) * DEGREES);
}
}
57 changes: 27 additions & 30 deletions lotus.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
#include "hpgllib.h"


double zigzagring (double x0, double y0, double r1, double r2, int npts, int incr, int flag);
double zigzagring(const double x0, const double y0, const double r1, const double r2, const int npts, const int incr, const int flag);


int main (int argc, char * const argv[])
int main(int argc, char * const argv[])
{
/* Mosaic and Tessellated Patterns, by John Willson, 1983.
ISBN: 0-486-24379-6. Plate 23. */
Expand All @@ -25,67 +25,64 @@ int main (int argc, char * const argv[])
double radius;
double incrad;

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 's':
if (strchr (optarg, '1'))
if (strchr(optarg, '1'))
scale = 80.0;
else if (strchr (optarg, '2'))
else if (strchr(optarg, '2'))
scale = 56.57;
else if (strchr (optarg, '4'))
else if (strchr(optarg, '4'))
scale = 28.28;
else if (strchr (optarg, '5'))
else if (strchr(optarg, '5'))
scale = 20.0;

case 'n':
case 'o':
case 'p':
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");
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 = 15.0 * scale; /* Inital radius 15mm */
radius = 15.0 * scale; /* Initial radius 15mm */
incrad = 15.0 * scale; /* Each zig-zag 15mm bigger than the previous one */

for (i = 0; i < 8; i++)
radius = zigzagring (xc, yc, radius, radius + incrad, 18, 1, i & 1);
radius = zigzagring(xc, yc, radius, radius + incrad, 18, 1, i & 1);

plotend ();
plotend();

return (0);
}


double zigzagring (double x0, double y0, double r1, double r2, int npts, int incr, int flag)
double zigzagring(const double x0, const double y0, const double r1, const double r2, const int npts, const int incr, const int flag)
{
int i;
double x1[128], y1[128];
double x2[128], y2[128];
double theta1, theta2;
double delta;
int n1, n2;

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

for (i = 0; i < npts; i++) {
if (flag) {
Expand All @@ -97,26 +94,26 @@ double zigzagring (double x0, double y0, double r1, double r2, int npts, int inc
theta2 = (delta * (double)i) + (delta / 2.0);
}

x1[i] = (cos (theta1) * r1) + x0;
y1[i] = (sin (theta1) * r1) + y0;
x1[i] = (cos(theta1) * r1) + x0;
y1[i] = (sin(theta1) * r1) + y0;

x2[i] = (cos (theta2) * r2) + x0;
y2[i] = (sin (theta2) * r2) + y0;
x2[i] = (cos(theta2) * r2) + x0;
y2[i] = (sin(theta2) * r2) + y0;
}

moveto (x1[0], y1[0]);
moveto(x1[0], y1[0]);
n1 = 0;
n2 = incr / 2;

for (i = 0; i < npts; i++) {
lineto (x1[n1], y1[n1]);
lineto (x2[n2], y2[n2]);
lineto(x1[n1], y1[n1]);
lineto(x2[n2], y2[n2]);

n1 = (n1 + incr) % npts;
n2 = (n2 + incr) % npts;
}

lineto (x1[0], y1[0]);

lineto(x1[0], y1[0]);
return (r2);
}
37 changes: 18 additions & 19 deletions pin_circle.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

int draw_pin_circle(const double xc, const double yc, const double r, const int n1, const int n2);

int main (int argc, char * const argv[])
int main(int argc, char * const argv[])
{
/* https://twitter.com/janjarfalk/status/991291613338132480 */
int n1, n2;
Expand All @@ -22,47 +22,47 @@ int main (int argc, char * const argv[])
double xc, yc;
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;
yc = maxy / 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);

n1 = 24;
n2 = 5;
r = (maxy / 2.0) * 0.98;

nlines = draw_pin_circle(xc, yc, r, n1, n2);

plotend ();
plotend();

printf ("%d+%d pins, %d lines drawn\n", n1, n2, nlines);
printf("%d+%d pins, %d lines drawn\n", n1, n2, nlines);

return (0);
}


int draw_pin_circle(const double xc, const double yc, const double r, const int n1, const int n2)
{
struct coord {
Expand All @@ -80,21 +80,20 @@ int draw_pin_circle(const double xc, const double yc, const double r, const int
int nlines = 0;
int pin1, pin2;
const double delta = (M_PI * 2.0) / (double)n1;
double theta;
int needmove;
const int n3 = n2 + 1;
const int n4 = n1 + n2;

/* Pre-compute coordinates of pins */
for (i = 0; i < n1; i++) {
theta = (double)i * delta;
const double theta = (double)i * delta;

pin[i].x = xc + (cos(theta) * r);
pin[i].y = yc + (sin(theta) * r);
}

for (i = 0; i < n2; i++) {
theta = ((double)i * delta) + (delta / 2.0);
const double theta = ((double)i * delta) + (delta / 2.0);

pin[i + n1].x = xc + (cos(theta) * r);
pin[i + n1].y = yc + (sin(theta) * r);
Expand Down Expand Up @@ -139,19 +138,19 @@ int draw_pin_circle(const double xc, const double yc, const double r, const int
else
pin2 = line[j].p1;

// printf ("Drawing to pin %d.\n", pin2);
// printf("Drawing to pin %d.\n", pin2);
}
else {
pin1 = (pin1 + 1) % (n1 * 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;
Expand Down

0 comments on commit 3ea3a0e

Please sign in to comment.