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



Revision as of 19:08, 30 September 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;
}