Skip to content

Commit

Permalink
Change 'lissajous' to draw four curves with different parameters. Als…
Browse files Browse the repository at this point in the history
…o use more 'const'.
  • Loading branch information
anachrocomputer committed Aug 14, 2020
1 parent 25ca2ed commit e06f29a
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions lissajous.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ int main(int argc, char * const argv[])
{
int opt;
double xc, yc;
double h4, w4;
double maxx, maxy;
const double scale = 40.0; /* Plotter units per mm */
double side;

while ((opt = getopt(argc, argv, "no:p:s:t:v:")) != -1) {
switch (opt) {
Expand Down Expand Up @@ -45,14 +46,22 @@ int main(int argc, char * const argv[])
xc = maxx / 2.0;
yc = maxy / 2.0;

/* Draw axes */
h4 = maxy / 4.0;
w4 = maxx / 4.0;

side = maxy / 3.0;

/* Split page into quarters */
moveto(0.0, yc);
lineto(maxx, yc);
moveto(xc, 0.0);
lineto(xc, maxy);

/* Draw a simple Lissajous curve */
lissajous(xc, yc, 150.0 * scale, 5.0, 6.0, 0.0, 144);
/* Draw four simple Lissajous curves */
lissajous(w4, h4, side, 1.0, 3.0, 0.0, 144);
lissajous(xc + w4, h4, side, 5.0, 6.0, 0.0, 144);
lissajous(w4, yc + h4, side, 3.0, 5.0, 0.0, 144);
lissajous(xc + w4, yc + h4, side, 7.0, 9.0, 0.0, 144);

plotend();

Expand All @@ -62,23 +71,20 @@ int main(int argc, char * const argv[])

void lissajous(const double x0, const double y0, const double side, const double f1, const double f2, const double theta, const int npts)
{
double t;
double t1, t2;
const double delta = (2.0 * M_PI) / (double)npts;
const double sintheta = sin(theta);
const double costheta = cos(theta);
double x, y;
const double r = side / 2.0;
int i;

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

t1 = t * f1;
t2 = t * f2;
const double t1 = t * f1;
const double t2 = t * f2;

x = (r * cos(t1) * costheta) - (r * sin(t2) * sintheta);
y = (r * cos(t1) * sintheta) + (r * sin(t2) * costheta);
const double x = (r * cos(t1) * costheta) - (r * sin(t2) * sintheta);
const double y = (r * cos(t1) * sintheta) + (r * sin(t2) * costheta);

if (i == 0)
moveto(x0 + x, y0 + y);
Expand Down

0 comments on commit e06f29a

Please sign in to comment.