<std::
size_tN>
70void spirograph(std::array<std::pair<double, double>, N> *points,
doublel,
71 doublek,
doublerot) {
72 doubledt = rot * 2.f * M_PI / N;
74 const doublek1 = 1.f - k;
80 for(step = 0; step < N; step++) {
82 doublefirst = R * (k1 * std::cos(t) + l * k * std::cos(k1 * t / k));
83 doublesecond = R * (k1 * std::sin(t) - l * k * std::sin(k1 * t / k));
84points[0][step].first = first;
85points[0][step].second = second;
95 doublel = 0.3, k = 0.75, rot = 10.;
96std::stringstream fname;
97fname << std::setw(3) <<
"spirograph_"<< l <<
"_"<< k <<
"_"<< rot
99std::ofstream fp(fname.str());
101perror(fname.str().c_str());
105std::array<std::pair<double, double>, N> points;
109 for(
size_ti = 0; i < N; i++) {
110fp << points[i].first <<
","<< points[i].first;
120static boolpaused = 0;
121static const intanimation_speed = 25;
123static const doublestep = 0.01;
124static doublel_ratio = step * 10;
125static doublek_ratio = step;
126static const doublenum_rot = 20.;
130static inline voidglutBitmapString(
void*font,
char*message) {
131 for(
char*ch = message; *ch !=
'\0'; ch++) glutBitmapCharacter(font, *ch);
145voiddisplay_graph(
conststd::array<std::pair<double, double>, N> &points,
146 doublel,
doublek) {
147glClearColor(1.0f, 1.0f, 1.0f,
149glClear(GL_COLOR_BUFFER_BIT);
152glColor3f(0.f, 0.f, 1.f);
155 for(
size_ti = 1; i <
N; i++) {
156glVertex2f(points[i - 1].first, points[i - 1].second);
157glVertex2f(points[i].first, points[i].second);
161glColor3f(0.f, 0.f, 0.f);
162std::stringstream buffer;
163buffer << std::setw(3) <<
"l = "<<
l;
164glRasterPos2f(-.85, .85);
165glutBitmapString(GLUT_BITMAP_TIMES_ROMAN_24,
166 const_cast<char*
>(buffer.str().c_str()));
169buffer << std::setw(3) <<
"k = "<<
k;
170glRasterPos2f(-.85, .70);
171glutBitmapString(GLUT_BITMAP_TIMES_ROMAN_24,
172 const_cast<char*
>(buffer.str().c_str()));
182 const size_t N= 5000;
184 static booldirection1 =
true;
185 static booldirection2 =
true;
187std::array<std::pair<double, double>,
N> points;
189 spirograph(&points, l_ratio, k_ratio, num_rot);
190display_graph(points, l_ratio, k_ratio);
197 if(k_ratio >= (1.f - step))
202 if(k_ratio <= step) {
206 if(l_ratio >= (1.f - step))
225voidtimer_cb(
intt) {
226glutTimerFunc(animation_speed, timer_cb, 0);
237voidkeyboard_cb(
unsigned charkey,
intx,
inty) {
268int main(
intargc,
char**argv) {
272glutInit(&argc, argv);
273glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
274glutCreateWindow(
"Spirograph");
275glutInitWindowSize(400, 400);
277glutTimerFunc(spirograph::animation_speed, spirograph::timer_cb, 0);
278glutKeyboardFunc(spirograph::keyboard_cb);
279glutDisplayFunc(spirograph::test2);
double k(double x)
Another test function.
double l(double x)
Another test function.
static void test2()
Self-implementations, 2nd test.
int main()
Main function.
void test()
Test function to save resulting points to a CSV file.
void spirograph(std::array< std::pair< double, double >, N > *points, double l, double k, double rot)
constexpr uint32_t N
A struct to represent sparse table for min() as their invariant function, for the given array A....
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4