Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Interactive Graphics: Difference between revisions

From ZeroWiki
imported>wjh0470
No edit summary
imported>starl1ght
No edit summary
 
(3 intermediate revisions by one other user not shown)
Line 2: Line 2:


== Source code ==
== Source code ==
주석은 차후에 다시
주석 및 페이지 정리는 나중에 다시
  #include <gl\freeglut.h>
  #include <gl\freeglut.h>
   
   
Line 102: Line 102:
  return 0;
  return 0;
  }
  }
#include <gl\freeglut.h>
#include <math.h>


#define Round 0.2
#include &lt;gl\freeglut.h&gt;
#define PI 3.145926
#include &lt;math.h&gt;
#define radi2theta(x) x*PI/180.0
#define Round 0.2
#define PI 3.145926
#define radi2theta(x) x*PI/180.0
void cycle(float x, float y, float r, float g, float b)
{
float dx = 0, dy = 0;
glColor3f(r, g, b);
glBegin(GL_POLYGON);
for (float i = 0; i &lt; 360; i += 0.01)
{
dx = Round*cos(radi2theta(i));
dy = Round*sin(radi2theta(i));
glVertex2f(x + dx, y + dy);
}
glEnd();
}
void display()
{
glClearColor(1.0, 1.0, 1.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT);
cycle(-0.7, 0.7, 1, 0, 0);
cycle(-0.25, 0.7, 0, 1, 0);
cycle(0.2, 0.7, 0, 0, 1);
glFlush();
}
int main(int argc, char** argv)
{
glutInit(&amp;argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(600, 600);
glutInitWindowPosition(200, 200);
glutCreateWindow("Homework0_3");
glutDisplayFunc(display);
glutMainLoop();
return 0;
}


void cycle(float x, float y, float r, float g, float b)
#include &lt;gl\freeglut.h&gt;
{
float dx = 0, dy = 0;
void display()
glColor3f(r, g, b);
{
glBegin(GL_POLYGON);
// I don't know, but it uses to transparent
for (float i = 0; i < 360; i += 0.01)
glEnable(GL_BLEND);
{
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
dx = Round*cos(radi2theta(i));
dy = Round*sin(radi2theta(i));
// White Base
glVertex2f(x + dx, y + dy);
glClearColor(1, 1, 1, 1);
}
glClear(GL_COLOR_BUFFER_BIT);
glEnd();
}
glBegin(GL_QUADS);
// Black Square
glColor3f(0, 0, 0);
glVertex2f(0.0, 1.0);
glVertex2f(0.0, -1.0);
glVertex2f(1.0, -1.0);
glVertex2f(1.0, 1.0);
// Red Square
for (float i=1,j = 1;i&gt;-1; i -= 0.5, j-= 0.25)
{
glColor4f(1, 0, 0, j);
glVertex2f(-1.0, i);
glVertex2f(1.0, i);
glVertex2f(1.0, i-0.4);
glVertex2f(-1.0, i-0.4);
}
glEnd();
glFlush();
}
int main(int argc, char** argv)
{
glutInit(&amp;argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(600, 600);
glutInitWindowPosition(200, 200);
glutCreateWindow("Homework0_4");
glutDisplayFunc(display);
glutMainLoop();
return 0;
}


void display()
#include &lt;gl\freeglut.h&gt;
{
#include &lt;math.h&gt;
glClearColor(1.0, 1.0, 1.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT);
#define PI 3.145926
 
#define rad2the(x) x * PI / 180.0
cycle(-0.7, 0.7, 1, 0, 0);
cycle(-0.25, 0.7, 0, 1, 0);
void cycle(float x, float y, float roundx, float roundy, float begin, float end)
cycle(0.2, 0.7, 0, 0, 1);
{
 
glBegin(GL_TRIANGLE_FAN);
glFlush();
for (float i = begin; i &lt;= end; i += 0.005)
}
{
float a = 0, b = 0;
a = roundx * cos(rad2the(i));
b = roundy * sin(rad2the(i));
glVertex2f(x + a, y + b);
}
glEnd();
glFlush();
}
void car(float x, float y)
{
glColor3f(1, 0, 0);
cycle(x, y-0.2, 0.8, 0.2, -30, 210);
cycle(x, y, 0.5, 0.2, -30, 210);
glColor3f(0, 0, 0);
cycle(x-0.35, y-0.3, 0.17,0.17, 0, 360);
cycle(x+0.35, y-0.3, 0.17, 0.17, 0, 360);
glColor3f(0.8, 0.8, 0.8);
cycle(x-0.35, y-0.3, 0.1, 0.1, 0, 360);
cycle(x + 0.35, y-0.3, 0.1, 0.1, 0, 360);
glColor3f(0, 0, 1);
cycle(x-0.15, y, 0.3, 0.1, 90, 180);
cycle(x + 0.15, y, 0.3, 0.1, 0, 90);
glBegin(GL_TRIANGLE_FAN);
glVertex2f(x - 0.45, y);
glVertex2f(x-0.15, y);
glVertex2f(x-0.15, y + 0.1);
glEnd();
glBegin(GL_TRIANGLE_FAN);
glVertex2f(x + 0.45, y);
glVertex2f(x + 0.15, y);
glVertex2f(x + 0.15, y + 0.1);
glEnd();
glBegin(GL_TRIANGLE_FAN);
glVertex2f(x - 0.1, y);
glVertex2f(x - 0.1, y + 0.1);
glVertex2f(x + 0.1, y + 0.1);
glVertex2f(x + 0.1, y);
glEnd();
glFlush();
}
void display()
{
glClearColor(1, 1, 1, 1);
glClear(GL_COLOR_BUFFER_BIT);
car(0, 0);
}
int main(int argc, char**argv)
{
glutInit(&amp;argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(600, 600);
glutInitWindowPosition(200, 200);
glutCreateWindow("Homework0 5");
glutDisplayFunc(display);
glutMainLoop();
return 0;
}


int main(int argc, char** argv)
* 개인적인 문서는 하위로 넣어주세요 - [[강민승]]
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(600, 600);
glutInitWindowPosition(200, 200);
glutCreateWindow("Homework0_3");
glutDisplayFunc(display);
glutMainLoop();
return 0;
}



Latest revision as of 10:22, 1 October 2015

Contents

Source code

주석 및 페이지 정리는 나중에 다시

#include <gl\freeglut.h>

void Line()
{
	glLineWidth(5);
	glColor3f(0, 0, 0);
	glBegin(GL_LINES);
	glVertex2f(-1.0, 1.0);
	glVertex2f(1.0, -1.0);
	glEnd();
}

void Square()
{
	glColor3f(1, 0, 0);
	glBegin(GL_LINE_LOOP);
	glVertex2f(-0.7, 0.7);
	glVertex2f(-0.7, 0.2);
	glVertex2f(-0.2, 0.2);
	glVertex2f(-0.2, 0.7);
	glEnd();
}

void display()
{
	glClearColor(1, 1, 1, 1);
	glClear(GL_COLOR_BUFFER_BIT);
	Line();
	Square();
	glFlush();
}

int main(int argc, char**argv)
{
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
	glutInitWindowSize(600, 600);
	glutInitWindowPosition(200, 200);
	glutCreateWindow("Homework0_1");
	glutDisplayFunc(display);
	glutMainLoop();
	return 0;
}
#include <gl\freeglut.h>
#include <diging.h>

float speed = 0;

void Rec(float locationX, float locationY, float size)
{
	vec2 rec[4] = { { -size + locationX, size + locationY }, { size + locationX, size + locationY },
	{ size + locationX, -size + locationY }, { -size + locationX, -size + locationY } };
	glBegin(GL_QUADS);
	for (int i = 0; i < 4;i++)
		glVertex2fv(rec[i]);
	glEnd();
}

void idle()
{
	speed += 0.0005;
	glutPostRedisplay();
}

void display()
{
	glClearColor(0.5, 0.5, 0.5, 0.5);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	mat4 m(1.0);
	glMatrixMode(GL_MODELVIEW);
	glLoadMatrixf(matrix_to_float(m));
	m *= Translate(speed, 0.0, 0.0);
	glPushMatrix();
	glLoadMatrixf(matrix_to_float(m));
	glColor3f(1, 1, 1);
	Rec(-1.0, 0.2, 0.2);
	m *= Translate(speed, 0.0, 0.0);
	glPushMatrix();
	glLoadMatrixf(matrix_to_float(m));
	glColor3f(0, 0, 0);
	Rec(-1.0, -0.2, 0.2);
	glutSwapBuffers();
}

int main(int argc, char**argv)
{
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
	glutInitWindowPosition(200, 200);
	glutInitWindowSize(600, 600);
	glutCreateWindow("Homework2-1");
	glutIdleFunc(idle);
	glutDisplayFunc(display);
	glutMainLoop();

	return 0;
}
#include <gl\freeglut.h>
#include <math.h>

#define Round 0.2
#define PI 3.145926
#define radi2theta(x) x*PI/180.0

void cycle(float x, float y, float r, float g, float b)
{
	float dx = 0, dy = 0;
	glColor3f(r, g, b);
	glBegin(GL_POLYGON);
	for (float i = 0; i < 360; i += 0.01)
	{
		dx = Round*cos(radi2theta(i));
		dy = Round*sin(radi2theta(i));
		glVertex2f(x + dx, y + dy);
	}
	glEnd();
}

void display()
{
	glClearColor(1.0, 1.0, 1.0, 1.0);
	glClear(GL_COLOR_BUFFER_BIT);

	cycle(-0.7, 0.7, 1, 0, 0);
	cycle(-0.25, 0.7, 0, 1, 0);
	cycle(0.2, 0.7, 0, 0, 1);

	glFlush();
}

int main(int argc, char** argv)
{
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
	glutInitWindowSize(600, 600);
	glutInitWindowPosition(200, 200);
	glutCreateWindow("Homework0_3");
	glutDisplayFunc(display);
	glutMainLoop();
	return 0;
}
#include <gl\freeglut.h>

void display()
{
	// I don't know, but it uses to transparent
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	
	// White Base
	glClearColor(1, 1, 1, 1);
	glClear(GL_COLOR_BUFFER_BIT);
	
	glBegin(GL_QUADS);
	
	// Black Square
	glColor3f(0, 0, 0);
	glVertex2f(0.0, 1.0);
	glVertex2f(0.0, -1.0);
	glVertex2f(1.0, -1.0);
	glVertex2f(1.0, 1.0);

	// Red Square
	for (float i=1,j = 1;i>-1; i -= 0.5, j-= 0.25)
	{
		glColor4f(1, 0, 0, j);
		glVertex2f(-1.0, i);
		glVertex2f(1.0, i);
		glVertex2f(1.0, i-0.4);
		glVertex2f(-1.0, i-0.4);
	}
	glEnd();
	glFlush();
}

int main(int argc, char** argv)
{
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
	glutInitWindowSize(600, 600);
	glutInitWindowPosition(200, 200);
	glutCreateWindow("Homework0_4");
	glutDisplayFunc(display);
	glutMainLoop();
	return 0;
}
#include <gl\freeglut.h>
#include <math.h>

#define PI 3.145926
#define rad2the(x) x * PI / 180.0

void cycle(float x, float y, float roundx, float roundy, float begin, float end)
{
	glBegin(GL_TRIANGLE_FAN);
	for (float i = begin; i <= end; i += 0.005)
	{
		float a = 0, b = 0;
		a = roundx * cos(rad2the(i));
		b = roundy * sin(rad2the(i));
		glVertex2f(x + a, y + b);
	}
	glEnd();
	glFlush();
}

void car(float x, float y)
{
	glColor3f(1, 0, 0);
	cycle(x, y-0.2, 0.8, 0.2, -30, 210);
	cycle(x, y, 0.5, 0.2, -30, 210);

	glColor3f(0, 0, 0);
	cycle(x-0.35, y-0.3, 0.17,0.17, 0, 360);
	cycle(x+0.35, y-0.3, 0.17, 0.17, 0, 360);

	glColor3f(0.8, 0.8, 0.8);
	cycle(x-0.35, y-0.3, 0.1, 0.1, 0, 360);
	cycle(x + 0.35, y-0.3, 0.1, 0.1, 0, 360);

	glColor3f(0, 0, 1);
	cycle(x-0.15, y, 0.3, 0.1, 90, 180);
	cycle(x + 0.15, y, 0.3, 0.1, 0, 90);

	glBegin(GL_TRIANGLE_FAN);
	glVertex2f(x - 0.45, y);
	glVertex2f(x-0.15, y);
	glVertex2f(x-0.15, y + 0.1);
	glEnd();

	glBegin(GL_TRIANGLE_FAN);
	glVertex2f(x + 0.45, y);
	glVertex2f(x + 0.15, y);
	glVertex2f(x + 0.15, y + 0.1);
	glEnd();

	glBegin(GL_TRIANGLE_FAN);
	glVertex2f(x - 0.1, y);
	glVertex2f(x - 0.1, y + 0.1);
	glVertex2f(x + 0.1, y + 0.1);
	glVertex2f(x + 0.1, y);
	glEnd();
	glFlush();

}

void display()
{
	glClearColor(1, 1, 1, 1);
	glClear(GL_COLOR_BUFFER_BIT);
	car(0, 0);
	
}

int main(int argc, char**argv)
{
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
	glutInitWindowSize(600, 600);
	glutInitWindowPosition(200, 200);
	glutCreateWindow("Homework0 5");
	glutDisplayFunc(display);
	glutMainLoop();
	return 0;
}
  • 개인적인 문서는 하위로 넣어주세요 - 강민승