diff --git a/CG/job_1_cicle.cpp b/CG/job_1_cicle.cpp new file mode 100644 index 0000000..dbb05bc --- /dev/null +++ b/CG/job_1_cicle.cpp @@ -0,0 +1,188 @@ +#include +#include +#include +#include +#include +#include +#include + +#define NUM_POINTS 90 + +std::pair points[NUM_POINTS+1]; + +void pointsGenerate(void){ + + double angle = 0.0; + double radians = 0.0; + int divs = 90/NUM_POINTS; + + double x,y; + + for(int i=0; i <= NUM_POINTS; i++){ + x = 0.5 * cos(radians); + y = 0.5 * sin(radians); + + points[i].first = x; + points[i].second = y; + + angle += divs; + radians = (angle * M_PI) / 180.0; + } +} + +void circ_1(int j){ + + glClear(GL_COLOR_BUFFER_BIT); + + glBegin(GL_LINE_STRIP); + + for(int i=0; i < NUM_POINTS; i++) glVertex2f(points[i].first, points[i].second); + if(j >= 1) + for(int i=NUM_POINTS; i >= 0; i--) glVertex2f(-points[i].first, points[i].second); + + if(j >= 2) + for(int i=0; i < NUM_POINTS; i++) glVertex2f(-points[i].first, -points[i].second); + + if(j >= 3) + for(int i=NUM_POINTS; i >= 0; i--) glVertex2f(points[i].first, -points[i].second); + + glEnd(); + + glFlush(); + + std::this_thread::sleep_for( std::chrono::milliseconds(120)); + +} + +void circ_2(int j){ + + glClear(GL_COLOR_BUFFER_BIT); + + glBegin(GL_LINE_STRIP); + + for(int i=NUM_POINTS; i >= 0; i--) glVertex2f(-points[i].first, points[i].second); + + if(j >= 1) + for(int i=0; i < NUM_POINTS; i++) glVertex2f(-points[i].first, -points[i].second); + + if(j >= 2) + for(int i=NUM_POINTS; i >= 0; i--) glVertex2f(points[i].first, -points[i].second); + + if(j >= 3) + for(int i=0; i < NUM_POINTS; i++) glVertex2f(points[i].first, points[i].second); + + glEnd(); + + glFlush(); + + std::this_thread::sleep_for( std::chrono::milliseconds(120)); + +} + +void circ_3(int j){ + + glClear(GL_COLOR_BUFFER_BIT); + + glBegin(GL_LINE_STRIP); + + + for(int i=0; i < NUM_POINTS; i++) glVertex2f(-points[i].first, -points[i].second); + + if(j >= 1) + for(int i=NUM_POINTS; i >= 0; i--) glVertex2f(points[i].first, -points[i].second); + + if(j >= 2) + for(int i=0; i < NUM_POINTS; i++) glVertex2f(points[i].first, points[i].second); + + if(j >= 3) + for(int i=NUM_POINTS; i >= 0; i--) glVertex2f(-points[i].first, points[i].second); + + glEnd(); + + glFlush(); + + std::this_thread::sleep_for( std::chrono::milliseconds(120)); + +} + +void circ_4(int j){ + + glClear(GL_COLOR_BUFFER_BIT); + + glBegin(GL_LINE_STRIP); + + for(int i=NUM_POINTS; i >= 0; i--) glVertex2f(points[i].first, -points[i].second); + if(j >= 1) + + for(int i=0; i < NUM_POINTS; i++) glVertex2f(points[i].first, points[i].second); + + if(j >= 2) + for(int i=NUM_POINTS; i >= 0; i--) glVertex2f(-points[i].first, points[i].second); + + if(j >= 3) + for(int i=0; i < NUM_POINTS; i++) glVertex2f(-points[i].first, -points[i].second); + + glEnd(); + + glFlush(); + + std::this_thread::sleep_for( std::chrono::milliseconds(120)); + +} + + + +void display(void){ + + + glClear(GL_COLOR_BUFFER_BIT); + + glColor3f(1.0,0.0,0.0); + + int start = 0; + for(int t=0; t < 1500; t++){ + + for(int j = 0; j < 4; j++) + + if(start==0) circ_1(j); + else if(start==2) circ_2(j); + else if(start==3) circ_3(j); + else circ_3(j); + + start = start > 3 ? 0 : start + 1; + + glBegin(GL_POLYGON); + for(int i=0; i < NUM_POINTS; i++) glVertex2f(points[i].first, points[i].second); + for(int i=NUM_POINTS; i >= 0; i--) glVertex2f(-points[i].first, points[i].second); + for(int i=0; i < NUM_POINTS; i++) glVertex2f(-points[i].first, -points[i].second); + for(int i=NUM_POINTS; i >= 0; i--) glVertex2f(points[i].first, -points[i].second); + glEnd(); + + glFlush(); + std::this_thread::sleep_for( std::chrono::milliseconds(500)); + } + + + + +} + +int main(int argc, char** argv){ + + pointsGenerate(); + + glutInit(&argc, argv); + glutInitWindowSize(1000,1000); + glutCreateWindow("Circ create"); + glutDisplayFunc(display); + + glMatrixMode(GL_PROJECTION_MATRIX); + glLoadIdentity(); + glOrtho(0.0, 1000,0.0,1000, 1.0,1.0); + + glutMainLoop(); + + return 0; + + +} \ No newline at end of file diff --git a/CG/job_1_rectangle.cpp b/CG/job_1_rectangle.cpp new file mode 100644 index 0000000..3b18eba --- /dev/null +++ b/CG/job_1_rectangle.cpp @@ -0,0 +1,65 @@ +#include +#include +#include +#include +#include +#include +#include + + +void display(void) { + + double r[4] = {0.85, 0.17, 0.85,0.0}; + double g[4] = {0.14,0.0, 0.17, 0.67}; + double b[4] = {0.81, 0.85, 0.0, 0.39}; + + double move = 0.0; + double move_top = 0.0; + int chosen; + glClear(GL_COLOR_BUFFER_BIT); + + for(int i=0; i < 100; i++){ + chosen = rand() % 4; + glColor3f(r[chosen],g[chosen],b[chosen]); + + glBegin(GL_POLYGON); + glVertex2f(-1.0 + move, -0.2 - move_top); + glVertex2f(-1.0 + move, 1.0 - move_top); + glVertex2f(-0.7 + move, 1.0 - move_top); + glVertex2f(-0.7 + move, -0.2 - move_top); + glEnd(); + + glFlush(); + + if (move < 2.0 ){ + move += 0.1; + }else{ + move = 0.0; + move_top += 0.1; + } + + std::this_thread::sleep_for( std::chrono::milliseconds(150) ); + glClear(GL_COLOR_BUFFER_BIT); + } + +} + +int main(int argc, char *argv[]) { + + time_t t; + srand((unsigned) time(&t)); + + glutInit(&argc,argv); + glutInitWindowSize(1000, 1000); + glutCreateWindow("simple"); + glutDisplayFunc(display); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(0.0, 1000,0.0,1000, 1.0,1.0); + + + glutMainLoop(); + + return 0; +}