본문 바로가기
College Computer Science/Graphic Programming Design

[그래픽스] 2D 애니메이션 (니모를 찾는 니모 아빠와 도리)

by 2den 2022. 2. 9.
728x90
#include "cg.h"
#include "draw.h"

int w = 1000;
int h = 1000;
float t = 0.0;

void display()
{
	glClear(GL_COLOR_BUFFER_BIT);

	glClearColor(0.2, 0.2, 1.0, 1.0);

	// center
	glColor3f(0.2, 0.2, 1.0);
	rect(vector2D(-0.1, 0.1), vector2D(0.1, -0.1));


	// Nemo's body
	glPushMatrix();
	glRotatef(20.0 * t, 0.0, 0.0, 1.0);
	glTranslatef(0.0, 0.5 + 0.05 * sin(4 * t), 0.0);
	glColor3f(1.0, 0.6, 0.0);
	ellipse(vector2D(0.0, 0.0), 0.06, 0.04);


	// Nemo's eye
	glPushMatrix();
	glTranslatef(-0.03, 0.01, 0.0);
	glColor3f(0.0, 0.0, 0.0);
	circle(vector2D(0.0, 0.0), 0.005);
	
	glPopMatrix();
	

	// Nemo's tail
	glPushMatrix();
	glTranslatef(0.05, 0.0, 0.0);
	glRotatef(10.0 * sin(15 * t), 0.0, 0.0, 1.0);
	glColor3f(1.0, 0.6, 0.0);
	triangle(vector2D(0.0, 0.0), vector2D(0.04, 0.04), vector2D(0.04, -0.04));
	
	glPopMatrix();
	glPopMatrix();

	

	// Dad's body
	glPushMatrix();
	glRotatef(21.0 * t, 0.0, 0.0, 1.0);
	glTranslatef(0.0, - 0.5 + 0.03 * sin(4 * t), 0.0);
	glColor3f(1.0, 0.5, 0.0);
	ellipse(vector2D(0.0, 0.0), 0.08, 0.06);


	// Dad's eye
	glPushMatrix();
	glTranslatef(0.045, 0.02, 0.0);
	glColor3f(0.0, 0.0, 0.0);
	circle(vector2D(0.0, 0.0), 0.007);

	glPopMatrix();


	// Dad's tail
	glPushMatrix();
	glTranslatef(-0.06, 0.0, 0.0);
	glRotatef(10.0 * sin(10 * t), 0.0, 0.0, 1.0);
	glColor3f(1.0, 0.5, 0.0);
	triangle(vector2D(0.0, 0.0), vector2D(-0.06, 0.06), vector2D(-0.06, -0.06));

	glPopMatrix();



	// Dori's body
	glPushMatrix();
	glRotatef(100 * t, 0.0, 0.0, 1.0);
	glTranslatef(0.0, -0.25, 0.0);
	glColor3f(0.0, 0.0, 1.0);
	triangle(vector2D(-0.07, 0.0), vector2D(0.06, 0.07), vector2D(0.06, -0.07));

	// Dori's eye
	glPushMatrix();
	glTranslatef(0.045, 0.03, 0.0);
	glColor3f(0.0, 0.0, 0.0);
	circle(vector2D(0.0, 0.0), 0.007);

	glPopMatrix();

	
	// Dori's tail
	glPushMatrix();
	glTranslatef(-0.04, 0.0, 0.0);
	glRotatef(10.0 * sin(20 * t), 0.0, 0.0, 1.0);
	glColor3f(1.0, 2.0, 0.0);
	triangle(vector2D(0.0, 0.0), vector2D(-0.04, 0.06), vector2D(-0.04, -0.06));
	
	glPopMatrix();
	glPopMatrix();
	glPopMatrix();

	glutSwapBuffers();
}

void idle()
{
	t += 0.01;
	glutPostRedisplay();
}

int main(int argc, char** argv)
{
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);
	glutInitWindowSize(w, h);
	glutCreateWindow("transformations");

	glMatrixMode(GL_MODELVIEW);

	glutDisplayFunc(display);
	glutIdleFunc(idle);

	glutMainLoop();
}
728x90

댓글