-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
253 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,188 @@ | ||
#include <iostream> | ||
#include <ctime> | ||
#include <GL/gl.h> | ||
#include <GL/glut.h> | ||
#include <cmath> | ||
#include <utility> | ||
#include <thread> | ||
|
||
#define NUM_POINTS 90 | ||
|
||
std::pair<double, double> 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; | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <ctime> | ||
#include <thread> | ||
#include <chrono> | ||
#include <GL/gl.h> | ||
#include <GL/glut.h> | ||
|
||
|
||
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; | ||
} |