Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include "glut.h"
- #include <cmath>
- #include <iostream>
- #include <string>
- #include <ctime>
- #define SIZE 6
- #define LP 0.4
- #define M 3.14
- using namespace std;
- # define M_PI 3.14159265358979323846 /* pi */
- GLint Width = 800, Height = 800;
- void DRAWING(double x, double y, double r, double a) {
- double m1[SIZE];
- double m2[SIZE];
- glBegin(GL_LINES);
- glLineWidth(2.0);
- for (int i = 0; i < SIZE; i++) {
- m1[i] = r * cos(a + i * M_PI*LP);
- m2[i] = r * sin(a + i * M_PI*LP);
- }
- for (int i = 0; i < SIZE - 1; i++) {
- glColor3d(0.0, 1.0, 0.0);
- glVertex2d(x + m1[i], y + m2[i]);
- glVertex2d(x + m1[i + 1], y + m2[i + 1]);
- }
- glEnd();
- glFinish();
- }
- void DARER(double x, double y, double r, double a, int d) {
- double v;
- v = 2 * r*cos(M_PI / 5);
- for (int i = 0; i < SIZE; i++) {
- DRAWING(x - v * cos(a + i * M_PI*LP), y - v * sin(a + i * M_PI*LP), r, a + M_PI + i * M_PI*LP);
- if (d > 0)
- DARER(x - v * cos(a + i * M_PI*LP), y -
- v * sin(a + i * M_PI*LP), r / (2 * cos(M_PI / 5) + 1), a + M_PI + (2 * i + 1)*M_PI * 2 / 10, d - 1);
- }
- }
- void Draw()
- {
- DARER(100, 100, 95, M_PI / 10, 4);
- }
- void Reshape(GLint w, GLint h)
- {
- glClearColor(0.3, 0.3, 0.3, 1.0);
- glClear(GL_COLOR_BUFFER_BIT);
- Width = w;
- Height = h;
- glViewport(0, 0, w, h);
- }
- void main(int argc, char ** argv)
- {
- glutInit(&argc, argv);
- glutInitDisplayMode(GLUT_RGB);
- glutInitWindowPosition(200, 200);
- glutInitWindowSize(Width, Height);
- glutCreateWindow("Gosper's Curve");
- glClearColor(0.3, 0.3, 0.3, 1.0);
- glClear(GL_COLOR_BUFFER_BIT);
- glutDisplayFunc(Draw);
- glutReshapeFunc(Reshape);
- glMatrixMode(GL_PROJECTION);
- glScaled(0.001f, 0.001f, 0.001f);
- glutMainLoop();
- }
Advertisement
Add Comment
Please, Sign In to add comment