Skip to content
Snippets Groups Projects
Verified Commit 50720193 authored by Martin's avatar Martin
Browse files

initial commit

parents
No related branches found
No related tags found
No related merge requests found
spiro
.vscode
spiro: spiro.c
gcc -o spiro spiro.h spiro.c -lncurses -lm
spiro.c 0 → 100644
#include "spiro.h"
int scale(double pixel)
{
return round((pixel / 2 + 0.5) * LINES);
}
void plot(double R, double r, double O)
{
for (int tn = 0; tn < T_MAX * RESOLUTION; tn++)
{
double t = M_PI * tn / RESOLUTION;
int x = scale((R - r) * cos(t) + O * cos((R - r) / r * t));
int y = scale((R - r) * sin(t) - O * sin((R - r) / r * t));
if (x < 0 || x >= COLS || y < 0 || y >= LINES)
continue;
mvaddch(y, x, '.');
}
}
void clearscr()
{
for (int x = 0; x < COLS; x++)
{
for (int y = 0; y < LINES; y++)
{
mvaddch(y, x, ' ');
}
}
}
int main(int argc, char *argv[])
{
initscr();
while (1)
{
for (double R = 1; R >= 0; R -= 0.1)
{
for (double r = 0; r <= 1; r += 0.1)
{
for (double O = 0; O <= 1; O += 0.1)
{
char buf[50];
plot(R, r, O);
sprintf(buf, "R=%.2f r=%.2f O=%.2f", R, r, O);
mvaddstr(0, COLS - strlen(buf), buf);
refresh();
clearscr();
}
}
}
}
endwin();
}
spiro.h 0 → 100644
#include <curses.h>
#include <unistd.h>
#include <string.h>
#ifndef __USE_MISC
#define __USE_MISC
#endif
#include <math.h>
// number of pixels in the range t=(0, PI)
#define RESOLUTION 1000
// defines the maximum value of t = T_MAX*PI
#define T_MAX 1000
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment