#### Category : CG LAB

6. To draw a simple shaded scene consisting of a tea pot on a table. Define suitably the position and properties of the light source along with the properties of the surfaces of the solid object used in the scene. Lighting and Shading#include<GL/glut.h> void obj(double tx,double ty,double tz,double sx,double sy,double sz){ glRotated(50,0,1,0); glRotated(10,-1,0,0); glRotated(11.7,0,0,-1); glTranslated(tx,ty,tz); glScaled(sx,sy,sz); glutSolidCube(1); ..

8. Develop a menu driven program to animate a flag using the Bezier Curve algorithm#include<GL/glut.h>#include<math.h>#include<stdio.h> void bezierCoefficients(int n,int *c){ int k,i; for(k=0;k<=n;k++) { c[k]=1; for(i=n;i>=k+1;i–) c[k]*=i; for(i=n-k;i>=2;i–) c[k]/=i; }} void display(){ int cp[4][2]={{10,10},{100,200},{200,50},{300,300}}; int c[4],k,n=3; float x,y,u,blend; bezierCoefficients(n,c); glClear(GL_COLOR_BUFFER_BIT); glColor3f(1.0,0.0,0.0); glLineWidth(5.0); glBegin(GL_LINE_STRIP); for(u=0;u<1.0;u+=0.01) { x=0;y=0; for(k=0;k<4;k++) { blend=c[k]*pow(u,k)*pow(1-u,n-k); x+=cp[k][0]*blend; y+=cp[k][1]*blend; } glVertex2f(x,y); } glEnd(); glFlush();} ..

2. Create and rotate a triangle about the origin and a fixed point.#include <stdio.h>#include <GL/glut.h> void display(){    glClear(GL_COLOR_BUFFER_BIT);    glLoadIdentity();    glTranslatef( -0.14 , 0.62 , 0.0);    glRotatef(90 , 0 , 0 , 1);    glBegin( GL_TRIANGLES );    glColor3f( 0 , 1 , 0);    glVertex3f( -0.3 , -0.2 , 0 );  ..

4. Draw a color cube and allow the user to move the camera suitably to experiment with perspective viewing. Positioning of Camera #include<stdio.h>#include<math.h>#include<iostream>#include<GL/glut.h>using namespace std; float v[8][3] = {{-1,-1,-1},{-1,1,-1},{1,1,-1},{1,-1,-1},{-1,-1,1},{-1,1,1},{1,1,1},{1,-1,1}};float t[] ={0,0,0};int ax = 2;float viewer[]={5,0,0}; void init(){ glMatrixMode(GL_PROJECTION); glFrustum(-2,2,-2,2,2,10); glMatrixMode(GL_MODELVIEW);} void polygon(int a, int b, int c, int d){ glBegin(GL_QUADS); glVertex3fv(v[a]); glVertex3fv(v[b]); glVertex3fv(v[c]); glVertex3fv(v[d]); glEnd();} void colorcube(){ glColor3f(0,0,1); polygon(0,1,2,3); glColor3f(0,1,0); polygon(4,5,6,7); glColor3f(1,0,0); polygon(0,1,5,4); glColor3f(0,0,0); polygon(3,2,6,7); glColor3f(0,1,1); polygon(0,4,7,3); glColor3f(1,0,1); polygon(1,5,6,2);} void spincube(){ t[ax] += 1; if (t[ax] == 360)  ..

7. Design, develop and implement recursively subdivide a tetrahedron to form 3D Sierpinski gasket. The number of recursive steps is to be specified by the user. Sierpinski gasket#include<stdio.h>#include<math.h>#include<iostream>#include<GL/glut.h>using namespace std;float v[4][3] = { { 0.0,0.0,1.0 },{ 0,1,-1 },{ -0.8,-0.4,-1 },{ 0.8,-0.4,-1 } };int n; void triangle(float a[], float b[], float c[]){ glBegin(GL_POLYGON); glVertex3fv(a); glVertex3fv(b); glVertex3fv(c); ..

1. Implement Bresenham’s line drawing algorithm for all types of slope.#include<stdio.h>#include<math.h>#include<iostream>#include<GL/glut.h> int xstart, ystart, xend, yend;void init(){ gluOrtho2D(0, 500, 0, 500);} void draw_pixel(int x, int y){ glColor3f(1, 0, 0); glBegin(GL_POINTS); glVertex2i(x, y); glEnd(); glFlush();} void LineBres(int xstart, int ystart, int xend, int yend){ int dx = abs(xend – xstart); int dy = abs(yend – ystart); ..