CG Reportnewraj22
CG Reportnewraj22
I.
2014
Synopsis
The main aim of computer graphics is to display and print realisticlooking images. This task is achieved by computing the outer surface of the
object or objects to be displayed, and rendering it by simulating the way it is
seen in real life. Most real objects are visible because they reflect light, so the
main task of rendering is to simulate light reflection. Rendering is therefore an
important part of computer graphics. In order to render a real object, such as a
teapot or a car, its surface has first to be calculated and stored in the computer
as a mathematical expression. The rendering algorithm then scans the surface
point by point, computes the normal vector to the surface at every point, and
uses the normal to compute the amount and color of light reflected from the
point.
Electric circuit using Bresenhams' Line Drawing Algorithm, here
bresenhams' line drawing algorithm is used to simulate an Electrical Circuit.
Bouncing of balloons using Curves, here Bezier curves are used to create
Balloons. Bezier curves are a very popular curve type. Bezier curves have
precisely n control points, where n + 1 is the degree of the Bezier polynomial.
A Bezier curve is a parametric curve frequently used in computer graphics
and related fields.
Line is the two points connected each other. Line is the fundamental
unit of the computer graphics used to generate different shapes of objects by
connecting different points in the plane. The lines can be animated with
differen color combinations to use in developments of repots. This project
deals with different line pattern like Thick and Thin line and Two lines
with background. The Bresenhams line drawing algorithm is one of the
computer graphics techneque to draw line effectivly by coonecting points.
Bouncing is a special affect in motion pictures and animations that
keep changing (or Translates) the image's position around the screen through a
seamless transition. Creating Balloons with Bezier Curves, Bezier curves
have n control points, where n+1 is the degree of the Bezier polynomial. The
idea behind Bezier curves is to create a smooth curve, one intuitive
Dept. Of MCA
Page 1
2014
mechanism is to first connect the four control points with lines. Then draw
new lines connecting the midpoints of those lines, until the resulting curve is
sufficiently smooth.
Dept. Of MCA
Page 2
2014
Design Specification
Bresenhams Line-Drawing Algorithm:
Page 3
2014
top left corner of the grid, (1,1) is at the top left end of the line and (11, 5) is at
the bottom right end of the line.
Algorithm:
Step 1: Input the two endpoints and store the left endpoint in
(x0,y0).
Step 2: Set color for frame-buffer position (x0,y0); ie., plot the first
point.
Step 3: Calculatte the costants x,y,2y,2y-2x, and obtain the
starting value for decision parameter as
p0=2y-x
Step 4: At each xk along the line, starting at k=0, perform the
following test: If pk< 0, the next point to plot is (xk+1, yk)
and
pk+1=pk+2y
Otherwise, the next point to ploat is(xk+1,yk+1) and
pk+1=pk+2y-2x
Step 5: Repeat step 4 x-1 more times.
Page 4
2014
Pi is called control point for the Bezier curve. By connecting all control points
with lines, we receive a polygon - starting in P0 and finishing in Pn - that is
called Bzier polygon. The Bezier curve is completely contained in the hull
built from the Bzier polygon.
Page 5
2014
The Bernstein polynomials are the weighting functions for Bezier curves. The
following image shows the Berstein polynomial functions of a Bezier curve of
degree We can see how much influence has each polynomial on the curve
progression. For
example at t=0 only b0 is nonzero. Therefore all other polynomials don't have
a bearing on the curve progression in the point S(t=0).
III.
Dept. Of MCA
Graphical Features
Page 6
2014
Black
White
The color of the background for Bouncing Balloons using Curves is:
Black
Red
Green
Blue
Yellow
Light Blue
White
Dept. Of MCA
Page 7
2014
Green
glClear(GL_COLOR_BUFFER_BIT)
gluOrtho2D()
glColor3f()
glMatrixMode(GL_PROJECTION)
glClearColor()
glBegin(GL_POINTS)
glBegin(GL_LINES)
glEnd()
glFlush()
Dept. Of MCA
Page 8
2014
OUTPUT Screen
Fig 2
Figure 2 shows the Balloons Created Using Bezeir Curves.
Dept. Of MCA
Page 9
2014
Fig 3
Figure 3 shows the Balloons Created Using Bezeir Curves.
Fig 4
Figure 4 shows the Balloons Created Using Bezeir Curves.
Dept. Of MCA
Page 10
2014
Fig 5
Figure 5 shows the Balloons Created Using Bezeir Curves.
Dept. Of MCA
Page 11
2014
Conclusion
Bouncing of Balloons using curves is a computer animated screen
saver. The use of bouncing technique helps in translation of the object with
animation. When the balloon hits the XMAX or YMAX of the screen, it
bounces back, this phenomenon is continued endlessly.
Another project is about designing a pattern of an Electrical Circuit.
Where Bresenhams' Line Drawing Algorithm is used to draw different line
styles.
The future enhancement of the bouncing technique can be done with
use of user input of co-ordinates system and use of keyboard/Mouse events for
the car travelling direction.
Dept. Of MCA
Page 12
2014
References
1. Steven M. Seitz, And Charles R. Dyer, "View Morphing" Proc.
SIGGRAPH 96. In Computer Graphics 2012 pp. 21-30.
2. William Armstrong, Mark Green, and R. Lake. Near-real-time control
of human gure models, 2013 IEEE Computer Graphics and
Applications, 7(6):52 61.
3. Donald Hearn; M. Pauline Baker. Computer graphics. Prentice-Hall.
ISBN 978-0-13-161530-4.
4. Cartography for Swiss Higher Education,
www.cartouche.com/1.6.1.BezierCurve.html
5. Weisstein, Eric W. "Bzier Curve." From MathWorld--A Wolfram
Web Resource. http://mathworld.wolfram.com/BezierCurve.html
6. Donald Hearn, M. Pauline Baker, Warren Carithers, Computer
graphics with OpenGL Fourth Edition, Pages 410-422, ISBN 978-93325-1871-1.
Dept. Of MCA
Page 13
2014
Source Code
/* Electrical Circuit using Bresenhams' Line Drawing Algorithm */
#include<stdio.h>
#include<GL/gl.h>
#include<GL/glu.h>
#include<GL/glut.h>
#include<math.h>
void myinit();
void putpixel();
void display();
int x1;
int x2,y2,y3;
int flag1=0, flag=0;
void putpixel(int x,int y)
{
glBegin(GL_POINTS);
glVertex2i(x,y);
glEnd();
glFlush();
}
Dept. Of MCA
Page 14
2014
if(flag1%2==1)
{
glBegin(GL_POINTS);
glVertex2i(x,y);
glEnd();
}
}
flag++;
flag1++;
glFlush();
}
Dept. Of MCA
Page 15
2014
if(x2<x1) {
incx=-1; }
incy=1;
if(y2<y1) {
incy=-1; }
x=x1;
y=y1;
if(dx>dy)
{
putpixel(x,y);
e=2*dy-dx;
inc1=2*(dy-dx);
inc2=2*dy;
for(i=0;i<dx;i++)
{
if(e>=0)
{
y=y+incy;
e=e+inc1;
}
else
e=e+inc2;
Dept. Of MCA
Page 16
2014
x=x+incx;
putpixel(x,y);
}
}
else
{
putpixel(x,y);
e=2*dx-dy;
inc1=2*(dx-dy);
inc2=2*dx;
for(i=0;i<dy;i++)
{
if(e>=0)
{
x=x+incx;
e=e+inc1;
}
else
e=e+inc2;
y=y+incy;
putpixel(x,y);
}
}
}
Dept. Of MCA
Page 17
2014
if(dx>dy)
{
putpixel1(x,y);
Dept. Of MCA
Page 18
2014
e=2*dy-dx;
inc1=2*(dy-dx);
inc2=2*dy;
for(i=0;i<dx;i+=2)
{
if(e>=0)
{
y=y+incy;
e=e+inc1;
}
else
e=e+inc2;
x=x+incx;
putpixel1(x,y);
}
}
else
{
putpixel1(x,y);
e=2*dx-dy;
inc1=2*(dx-dy);
inc2=2*dx;
Dept. Of MCA
Page 19
2014
for(i=0;i<dy;i+=2)
{
if(e>=0)
{
x=x+incx;
e=e+inc1;
}
else
e=e+inc2;
y=y+incy;
putpixel1(x,y);
}
}
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
//glFlush();
//glVertex2i(400,0);
//glVertex2i(-400,0);
//glVertex2i(0,400);
//glVertex2i(0,-400);
glColor3f(0.0,0.0,0.0);
Dept. Of MCA
Page 20
2014
brline(100,100,300,100);
//glutSolidSphere(3.0,100.0,100.0);
brline(500,100,800,100);
brline(1000,100,1300,100);
brline(1300,100,1300,500);
brline(1300,550,1300,1050);
brline(1300,1050,1000,1050);
brline(800,1050,500,1050);
brline(300,1050,100,1050);
brline(100,1050,100,550);
brline(100,500,100,100);
brlin(650,1050,650,50);
brlin(650,500,650,-300);
brline(300,1050,333,1000);
brline(333,1000,366,1100);
brline(366,1100,400,1000);
brline(400,1000,433,1100);
brline(433,1100,466,1000);
brline(466,1000,500,1050);
brline(800,1050,833,1000);
brline(833,1000,866,1100);
brline(866,1100,900,1000);
Dept. Of MCA
Page 21
2014
brline(900,1000,933,1100);
brline(933,1100,966,1000);
brline(966,1000,1000,1050);
brline(300,100,333,50);
brline(333,50,366,150);
brline(366,150,400,50);
brline(400,50,433,150);
brline(433,150,466,50);
brline(466,50,500,100);
brline(800,100,833,50);
brline(833,50,866,150);
brline(866,150,900,50);
brline(900,50,933,150);
brline(933,150,966,50);
brline(966,50,1000,100);
brline(75,500,125,500);
brline(50,550,150,550);
brline(600,500,700,500);
brline(625,550,675,550);
brline(1250,550,1350,550);
brline(1275,500,1325,500);
Dept. Of MCA
Page 22
2014
brline(0,600,0,550);
brline(-20,575,20,575);
brline(-20,475,20,475);
brline(530,575,570,575);
brline(550,500,550,450);
brline(530,475,570,475);
brline(1200,600,1200,550);
brline(1180,575,1220,575);
brline(1180,475,1220,475);
glEnd();
glBegin(GL_POINT);
glPointSize(6);
glVertex2i(100,100);
glVertex2i(650,100);
glVertex2i(1300,100);
glVertex2i(1300,1050);
glVertex2i(650,1050);
glVertex2i(100,1050);
glEnd();
glFlush();
}
Dept. Of MCA
Page 23
2014
void myinit()
{
glColor3f(1.0,1.0,1.0);
glClearColor(1,1,1,0);
glPointSize(2);
gluOrtho2D(-100,1400,-100,1300);
}
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(1500,1500);
glutInitWindowPosition(00,00);
glutCreateWindow("bresanhams");
glutDisplayFunc(display);
myinit();
glutMainLoop();
}
Dept. Of MCA
Page 24
2014
int Purple[18] = {
void delay()
{
Dept. Of MCA
}
Page 25
2014
void Curve_draw(GLint x0, GLint y0, GLint z0, GLint x1, GLint y1, GLint
z1, GLint x2, GLint y2, GLint z2, GLint x3, GLint y3, GLint z3 )
{
int ax, ay,az, bx, by, bz,cx, cy, cz,dx, dy,dz, x[100], y[100],z[100];
double numsteps, i, t;
int k;
float stepsize;
ax = -x0 + 3*x1 + (-3*x2) + x3;
ay = -y0 + 3*y1 + (-3*y2) + y3;
az = -z0 + 3*z1 + (-3*z2) + z3;
bx = 3*x0 + (-6*x1) + (3*x2);
by = 3*y0 + (-6*y1) + (3*y2);
bz = 3*z0 + (-6*z1) + (3*z2);
cx = -3*x0 + 3*x1;
cy = -3*y0 + 3*y1;
cz = -3*z0 + 3*z1;
Dept. Of MCA
Page 26
2014
dx = x0;
dy = y0;
dz = z0;
numsteps = 100.0;
stepsize = 1.0/ (double) numsteps;
for(i=1,k=1; i<numsteps;i++,k++)
{
t = (double)stepsize*(double) i;
void display(void) {
glClear (GL_COLOR_BUFFER_BIT);
glPushMatrix();
glTranslatef(tx,ty,0);
glRotatef(spin, 0.0, 0.0, 1.0);
glScalef(scale, scale, 0.0);
/*
for(int i=-40;i<=-20;i++)
{
Dept. Of MCA
Page 27
2014
glColor3d(1,0,1);
Curve_draw(0,200,100,60,190,100,i+80,120,100,0,0,100);
}
for(int i=-20;i<=0;i++)
{
glColor3d(1,1,0);
Curve_draw(0,200,100,60,190,100,i+80,120,100,0,0,100);
}
for(int k=0;k<=20;k++)
{
glColor3d(1,1,1);
Curve_draw(0,200,100,100,190,100,k+80,120,100,0,0,100);
}
for(int k=20;k<=40;k++)
{
glColor3d(1,0,1);
Curve_draw(0,200,100,100,190,100,k+80,120,100,0,0,100);
}
for(int j=-20;j<=0;j++)
{
glColor3d(0,0,1);
Curve_draw(0,200,100,80,190,100,80,120,100,0,0,100);
}
for(int l=0;l<=20;l++)
{
Dept. Of MCA
Page 28
2014
glColor3d(1,1,1);
Curve_draw(0,200,100,80,190,100,80,120,100,0,0,100);
}
*/
for(int i=-40;i<=-20;i++)
{
glColor3d(0,1,0);
Curve_draw(40,190,100,(i+40),190,100,(i+100),120,100,0,0,100);
}
for(int i=-20;i<=0;i++)
{
glColor3d(1,1,1);
Curve_draw(40,190,100,(i+40),190,100,(i+100),120,100,0,0,100);
}
for(int k=0;k<=20;k++)
{
glColor3d(0,1,0);
Curve_draw(40,190,100,(k+80),190,100,(k+100),120,100,0,0,100);
}
for(int k=20;k<=40;k++)
{
glColor3d(0,1,0.6);
Curve_draw(40,190,100,(k+80),190,100,(k+100),120,100,0,0,100);
}
for(int j=-20;j<=0;j++)
Dept. Of MCA
Page 29
2014
{
glColor3d(0,1,0.4);
Curve_draw(40,190,100,(j+60),190,100,100,120,100,0,0,100);
}
for(int l=0;l<=20;l++)
{
glColor3d(0,1,1);
Curve_draw(40,190,100,(l+60),190,100,100,120,100,0,0,100);
}
for(int i=-40;i<=-20;i++)
{
glColor3d(0,1,0);
Curve_draw(-40,190,100,-(i+40),190,100,-(i+100),120,100,0,0,100);
}
for(int i=-20;i<=0;i++)
{
glColor3d(1,1,1);
Curve_draw(-40,190,100,-(i+40),190,100,-(i+100),120,100,0,0,100);
}
for(int k=0;k<=20;k++)
{
glColor3d(0,1,0);
Curve_draw(-40,190,100,-(k+80),190,100,-(k+100),120,100,0,0,100);
Dept. Of MCA
Page 30
2014
}
for(int k=20;k<=40;k++)
{
glColor3d(0,1,0.6);
Curve_draw(-40,190,100,-(k+80),190,100,-(k+100),120,100,0,0,100);
}
for(int j=-20;j<=0;j++)
{
glColor3d(0,1,0.4);
Curve_draw(-40,190,100,-(j+60),190,100,-100,120,100,0,0,100);
}
for(int l=0;l<=20;l++)
{
glColor3d(0,1,1);
Curve_draw(-40,190,100,-(l+60),190,100,-100,120,100,0,0,100);
}
for(int i=-50;i<=-20;i++)
{
glColor3d(1,0,0);
Curve_draw(0,220,100,i-20,210,100,i,140,100,0,0,100);
}
for(int i=-20;i<=0;i++)
Dept. Of MCA
Page 31
2014
{
glColor3d(0,1,0);
Curve_draw(0,220,100,i-20,210,100,i,140,100,0,0,100);
}
for(int k=0;k<=20;k++)
{
glColor3d(0,0,1);
Curve_draw(0,220,100,k+20,210,100,k,140,100,0,0,100);
}
for(int k=20;k<=40;k++)
{
glColor3d(1,1,0);
Curve_draw(0,220,100,k+20,210,100,k,140,100,0,0,100);
}
for(int j=-20;j<=0;j++)
{
glColor3d(0,1,0);
Curve_draw(0,220,100,j,210,100,0,140,100,0,0,100);
}
for(int l=0;l<=20;l++)
{
glColor3d(0,0,1);
Curve_draw(0,220,100,l,210,100,0,140,100,0,0,100);
}
Dept. Of MCA
Page 32
2014
glColor3d(1,1,1);
glutSolidSphere(5.0,100.0,100.0);
Curve_draw(0,0,100,30,30,100,30,-30,100,0,0,100);
Curve_draw(0,0,100,-30,30,100,-30,-30,100,0,0,100);
Curve_draw(0,0,100,-30,-30,100,30,-60,100,0,-90,100);
Curve_draw(0,0,100,-15,-10,100,-20,-25,100,-40,-30,100);
Curve_draw(0,0,100,15,-10,100,20,-25,100,40,-30,100);
glPopMatrix();
glutSwapBuffers();
}
void BounceDisplay(void) {
Dept. Of MCA
Page 33
2014
else{
spin = spin + 2.0;
}
if(spin > 360.0){
spin = spin - 360.0;
}
if(spin < -360.0){
spin = spin + 360.0;
}
tx += dx;
ty += dy;
if((tx + Radius) > 700){
DIRspin *= -1;
dx*= -1;
tx -= (tx + Radius) - 700;
}
if((tx - Radius) < 0 ){
DIRspin *= -1;
dx*= -1;
tx += -1 * (tx - Radius);
}
if((ty + Radius) > 600){
DIRspin *= -1;
dy *= -1;
ty -= (ty + Radius) - 600;
Dept. Of MCA
Page 34
2014
}
if ((ty - Radius) < 0 ){
DIRspin *= -1;
dy *= -1;
ty += -1 * (ty - Radius);
}
glutPostRedisplay();
}
void init (void) {
glClearColor (0.0, 0.0, 0.0, 0.0);
glMatrixMode(GL_PROJECTION);
glPointSize(5.0);
glLoadIdentity();
glOrtho(0, 700, 0, 600, -1.0, 1.0);
glMatrixMode(GL_MODELVIEW);
}
void mouse(int button, int state, int Mx, int My) {
switch(button){
case GLUT_LEFT_BUTTON:
if (state == GLUT_DOWN){
tx = Mx;
ty = 400 - My;
break;
}
case GLUT_RIGHT_BUTTON:
Dept. Of MCA
Page 35
2014
if(state == GLUT_DOWN){
DIRspin *= -1;
break;
}
default:
break;
}
}
int main(int argc, char** argv) {
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize (700, 600);
glutInitWindowPosition (100, 100);
glutCreateWindow ("GLBounce! (point, click right,left)");
init();
glutDisplayFunc(display);
glutIdleFunc(BounceDisplay);
glutMouseFunc(mouse);
glutMainLoop();
return 0;
}
Dept. Of MCA
Page 36