You are on page 1of 52

VISVESVARAYA TECHNOLOGICAL UNIVERSITY

BELGAUM, KARNATAKA -570014

A Project Report on

CHEMICAL REACTION
Submitted in partial fulfillment of VI semester course of
Bachelor of Engineering in Computer Science &
Engineering during the year 2014-2015
By

Shreya Shetty R(1GC12CS049)


Sushmitha K S (1GC12CS052)
Under the guidance of
Mr.DEEPAK N.A
Head of dept,
Dept of CSE,
GCE,Ramanagaram

DEPARTMENT OF COMPUTER SCIENCE & ENGG.


GHOUSIA COLLEGE OF ENGINEERING
RAMANAGARAM-562 159
2014-2015

GHOUSIA COLLEGE OF ENGINEERING

Chemical Reaction

RAMANAGARAM-562 159

CERTIFICATE
This is to certify that SHREYA
SHETTY
R(1GC12CS049),SUSHMITHA K S(1GC12CS052)
has satisfactorily completed the mini project on
CHEMICAL REACTION that has been approved as
it satisfies the academic requirements in view of
the
project
work
prescribed
for
partial
completion of the 6th semester B.E. degree in
Computer science course awarded by the
Vishveshvaraya Technological University,Belgaum
in the year 2013-2014.
Signature of the
Signature of the
Guide
Head of department

Signature of the Examiners

1.

Dept of CSE,GCE Ramanagaram

Chemical Reaction

2.

ABSTRACT
CHEMICAL REACTION

Objective of this project is to show the chemical reaction that


takes place between the acid and the base. A chemical reaction is a
process that leads to the transformation of one set of chemical
substances to another. This project has been implemented by using
different primitives available in OpenGL library and combining them
together in a required manner.

When an acid reacts with the base, the mixture of these two
solutions gets neutralized
And this reaction is indicated by the color change in the resultant
solution.

TEAM: Shreya Shetty R (1GC12CS049)


Sushmitha K.S (1GC12CS052)

Dept of CSE,GCE Ramanagaram

Chemical Reaction

ACKNOWLEDGEMENT
It is the time to acknowledge all those who have extended their guidance, inspiration and their
whole hearted co-operation all along our project work.
At the outset we express our most sincere grateful thanks to the holy sanctum
GHOUSIA COLLEGE OF ENGINEERING for giving us an opportunity to pursue the
degree course in Computer Science and Engineering thus helping in shaping our career.
We are also grateful to Dr.Mr.MOHAMED HANEEF the principal, and also
Prof.Mr.DEEPAK N.A, HOD of CSE Department for having provided us academic
environment which nurtured our practical skills contributing to the success of our project.
We wish to place a deep sense of gratitude to our beloved project guide,
Prof.Mr.DEEPAK N.A, HOD of CSE Department for his whole-hearted guidance and constant
support without which Endeavour would not have been possible.
Our gratitude will not be complete without thanking the Almighty God and our beloved
Parents and also our Friends, who have been a constant source of blessings and aspirations.

Dept of CSE,GCE Ramanagaram

Chemical Reaction

TABLE OF CONTENTS

CHAPTER

PAGE NO:

1. Introduction

6-7

1.1. About Computer Graphics

1.2. About OpenGL

1.3. About Project Title

2. System Requirements

2.1 Hardware Requirements

2.2 Software Requirements

3. Design

9-13

3.1. High Level Design

9-13

3.2. Algorithm

13-14

4. Implementation

15-19

5.Source code

20-38

6. Snapshot and Result Discussion

39-46

7.Appendix

47-51

8.References

52

Dept of CSE,GCE Ramanagaram

Chemical Reaction

Chapter 1

INTRODUCTION
1.1

About Computer Graphics

Computer graphics are graphics created using computers and, more generally, the
representation

and

manipulation

of image data

by a

computer

with

help

from

specialized software and hardware.


The development of computer graphics has made computers easier to interact with,
and better for understanding and interpreting many types of data. Developments in computer
graphics

have

had

profound

impact

on

many types

of

media

and

have

revolutionized animation, movies and the video game industry.


Typically, the term computer graphics refers to several different things:

the representation and manipulation of image data by a computer

the various technologies used to create and manipulate images

the sub-field of computer science which studies methods for digitally synthesizing
and manipulating visual content.

1.2

About OpenGL
OpenGL is the industrys most widely used, supported and best documented 2D/3D

graphics API, making it inexpensive and easy to obtain information on implementing


OpenGL in hardware and software.
OpenGL is a low-level, procedural API, requiring the programmer to dictate the exact
steps required to render a scene. This contrast with descriptive APIs, where a programmer
Dept of CSE,GCE Ramanagaram

Chemical Reaction
only needs to describe a scene and can let the library manage the details of rendering it.
OpenGL's low-level design requires programmers to have a good knowledge of the graphics
pipeline, but also gives a certain amount of freedom to implement novel rendering
algorithms.

1.3

About Project
In this project, we demonstrate the chemical reaction which takes place between 2

different chemicals placed in 2 different conical flasks. Here the 2 chemicals used are acid
and base.
We pipette in base from the conical flask using a standard pipette. Then we move this
pipette which is containing base to the other conical flask which contains acid so that we can
pipette out the base into the conical flask containing acid.
As the base solution is dropped into the acid solution contained in a flask, reaction
takes places between the 2 solutions and the resultant solution gets neutralized.

Dept of CSE,GCE Ramanagaram

Chemical Reaction

Chapter 2

SYSTEM REQUIREMENTS
This chapter specifies the requirements needed in a system in order to run this
project in computer graphics using OpenGL interface.

2.1 Software Requirements


Operating system

: Microsoft Windows XP

Language

: Visual Studio 2010

API

: OpenGL

2.2 Hardware Requirements


Processor
RAM
Hard disk
Display card

: Intel core 2 duo or dual core 2.0 GHz & above


: 2GB DDR3
: 80GB
: with 1GB internal graphics memory

Dept of CSE,GCE Ramanagaram

Chemical Reaction

Chapter 3

DESIGN
3.1 High Level Design
3.1.1 Block Diagram

Objects
(2 conical flasks
filled with
solutions, 1 pipette)

Pipette the base


Solution

Base solution
reacts with acid
solution

Reaction

Fig 3.1: Block Diagram of Chemical Reaction

Dept of CSE,GCE Ramanagaram

Resultant solution
gets
Neutralized

Chemical Reaction

3.1.2. Data Flow Diagram


exit( )

Main( )

Press p

Press m

Press d

display( )

display0( )

display1( )

display2( )

Output of
display( )

Output of
display0( )

Output of
display1( )

Output of
display2( )

Output

Input
Right
mouse
button

Mouse

Press 1

displaya()

Output of
displaya( )

Pressing
specified keys

Output is
sent to

Keyboard
Press 2

Dept of CSE,GCE Ramanagaram

displayb()

displayc( )
10

display3( )

Output of
displayb( )

Output of
displayc( )

Standard Output

Chemical Reaction
Press 3

Output of
display3( )

Press r

3.1.3. Control Flow


Flowchart/Control Flow is the diagrammatic representation of algorithm showing the
steps as boxes and their order by connecting with arrows. It shows the flow of execution
when different options are specified.
(continued in the next page)

Dept of CSE,GCE Ramanagaram

11

Chemical Reaction

Start

main( )

DisplayFunc( )
display( )
CreateMenu( )

demo_menu( )

KeyboardFunc( )

If(key==p)
display0( )

if(key==m)

display1( )

if(key==d)

display2( )

if(key==1)

displaya( )

if(key==2)

displayb( )

if(key==3)

displayc( )

Dept of CSE,GCE Ramanagaram

12

Chemical Reaction
A

if(key==r)

display3( )

Stop

Fig 3.3 Control Flow of Chemical Reaction

3.2. Algorithm
Algorithm is a step by step procedure for solving a problem in finite no of steps that
frequently involves repetition of operation.
Algorithm for Chemical Reaction
Step 1: Start
Step 2: [Initialize the output window]
glutCreateWindow( ) func is called.
Step 3: [Output window consisting of 2 conical flasks and a pipette is displayed.]
The display( ) function is called.
Step 4: [Keyboard is used to interact with the user]
If selected key is pressed then
glutKeyboardFunc( ) function gets called
Dept of CSE,GCE Ramanagaram

13

Chemical Reaction
Step 5: if (key==p) then
the base solution gets pipetted.
Step 7: if (key==m) then
The pipette containing base solution moves towards the conical flask
containing acid solution using for( ) loop.
Step 8: if (key ==d) is pressed then
the base solution is pipetted out into the conical flask drop by drop.
Step 9: if (key ==1 || key==2||key==3) then
drop by drop movement of the solution is seen.
Step 10: if (key==r) then
the reaction between the acid and the base is seen.
Step 11:[ To display the popup menu & to exit ]
if(GLUT_RIGHT_BUTTON && GLUT_DOWN==Quit) then
The control comes out of the output window.
Step 12: Stop.

Dept of CSE,GCE Ramanagaram

14

Chemical Reaction

Chapter 4

IMPLEMENTATION
4.1. Pseudo Code
Pseudo Code is a compact and informal high level description of
computer programming algorithm that uses the structural connections of a programming
language, but is intended for human reading rather than machine reading.
Initialize the Header files.
Void main(int argc, char**argv)
{
Initialize GLUT using glutInit( );
Set the display mode by enabling single buffer and use RGB colour by using
glutInitDisplayMode( );
Initialize the window size by the function glutInitWindowSize( );

Set the window position by using the function glutInitWindowPosition( );


Create window using glutCreateWindow( );
Set display function using glutDisplayFunc( );
Create menu using glutCreateMenu( );
Set keyboard function using glutKeyboardFunc( );
Call myinit( ) function;
Start execution using glutMainLoop( );
Dept of CSE,GCE Ramanagaram

15

Chemical Reaction
}
void display( )
{
Clear the color buffer;
Call conical1( ) function;
Call conical2( ) function;
Call pipette( ) function;
Flush the frames into the buffer.
}
void draw_text(int x, int y, char *s )
{
Initialise the character;
Set the position of the character;
Set the font type & font size of the character;
Flush the frames into the buffer;
}
void conical1( )
{
Clear the colour buffer;
Set the colour of the conical flask and the solution;
Create a conical flask containing solution;
Flush the frames into the buffer;
Call the draw_text( ) function with the name Base;
}
void conical2( )
{
Clear the colour buffer;
Set the colour of the conical flask and the solution;
Create a conical flask containing solution;
Flush the frames into the buffer;
Call the draw_text( ) function with the name Acid;
Dept of CSE,GCE Ramanagaram

16

Chemical Reaction
}
void pipette( int x, int y)
{
Clear the colour buffer;
Call conical1( ) & conical2( ) functions;
Initialise i & j;
Set the conditions for x & y using if & else loop;
Set the colour of the pipette;
Create the pipette along with the i & j values;
Flush the frames into the buffer;
Call draw_text( ) function with the name p;
}
void keys(unsigned character key, int x, int y)
{
Interface the keyboard with the program in such a way that when we :
Press p display0( ) function is called;
Press m display1( ) function is called;
Press d display2( ) function is called;
Press 1 displaya( ) function is called;
Press 2 displayb( ) function is called;
Press 3 displayc( ) function is called;
Press r display3( ) function is called;
}
void display0( )
{
Clear the colour buffer.
Set the colour of the conical flasks, pipette and also the solutions placed inside them;\
Create the conical flasks and pipette containing the solutions;
Flush the frames into the buffer;
Call draw_text( ) function for conical flasks and pipette;
}
Dept of CSE,GCE Ramanagaram

17

Chemical Reaction
void display1( )
{
Initialize i & j;
Set the condition for i & j using for loop;
Create and set the colour of the conical flask;
Create and move the pipette from one conical flask to the other;
Reduction in the amount of base solution inside the conical flask is shown;
Flush the frames into the buffer;
}
void display2( )
{
Create and set the colour of the conical flask & the pipette;
Pipette out the solution into the conical flask;
Flush the frames into the buffer;
}
void displaya( )
{
Create and set the colour of the conical flask & the pipette;
Drop the solution into the conical flask;
Show the reduction in the amount of the solution inside the pipette;
Flush the frames into the buffer;
}
void displayb( )
{
Create and set the colour of the conical flask & the pipette;
Drop the solution into the conical flask;
Show some more reduction in the amount of the solution inside the pipette;
Show the increase in the amount of the solution inside the 2nd conical flask.
Flush the frames into the buffer;
}
void displayc( )
Dept of CSE,GCE Ramanagaram

18

Chemical Reaction
{
Create and set the colour of the conical flask & the pipette;
Drop the solution into the conical flask;
Pipette is emptied and the whole solution is transferred into the conical flask;
Flush the frames into the buffer;
}
void display3( )
{
Create and set the colour of the conical flask & the pipette;
Reaction is indicated by changing the colour in the solution;
Flush the frames into the buffer;
}
void demo_menu( int id)
{
switch(id)
{
In case 1, if the right button of the mouse is clicked, then the control comes out of the
loop;
}
}
void myinit( )
{
Set the background colour of the output window to black;
Set the matrix mode to the projection matrix;
Load the identity matrix;
Call gluOrtho2D( ) function;
}

Dept of CSE,GCE Ramanagaram

19

Chemical Reaction

SOURCE CODE
#include<stdio.h>
#include<time.h>
#include<math.h>
#include<GL/glut.h>
void display();
void draw_text(int x,int y,char *s)
{
char *p;
glRasterPos2f(x,y);
for(p=s;*p;++p)
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18,*p);
glFlush();
}
void conical1()
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0.3,0.4,1.0);
glBegin(GL_POLYGON);
glVertex2f(70,25);
glVertex2f(200,25);
glVertex2f(177.5,100);
glVertex2f(97.5,100);
glEnd();
glColor3f(0.0,0.0,1.0);
glBegin(GL_LINE_LOOP);
glVertex2f(177.5,100);
glVertex2f(162.5,150);
glVertex2f(162.5,200);
glVertex2f(112.5,200);
glVertex2f(112.5,150);
glVertex2f(97.5,100);
glEnd();
glFlush();
glColor3f(0.0,0.0,0.0);
draw_text(117.5,55,"Base");
glColor3f(1.0,0.0,0.0);
draw_text(40,95,"Level1");
glColor3f(1.0,0.0,0.0);
draw_text(30,65,"Level2");
}
void conical2()
{
glColor3f(1.0,0.3,0.4);
glBegin(GL_POLYGON);

Dept of CSE,GCE Ramanagaram

20

Chemical Reaction

glVertex2f(275,25);
glVertex2f(400,25);
glVertex2f(377.5,100);
glVertex2f(297.5,100);
glEnd();
glBegin(GL_LINE_LOOP);
glColor3f(0.0,0.0,1.0);
glVertex2f(377.5,100);
glVertex2f(362.5,150);
glVertex2f(362.5,200);
glVertex2f(312.5,200);
glVertex2f(312.5,150);
glVertex2f(297.5,100);
glEnd();
glFlush();
glColor3f(0.0,0.0,0.0);
draw_text(320,55,"Acid");
glColor3f(1.0,0.0,0.0);
draw_text(270,90,"L1");
glColor3f(1.0,0.0,0.0);
draw_text(275,110,"L2");
glColor3f(1.0,0.0,0.0);
draw_text(280,135,"L3");
void pipette(int x,int y)
{
glClear(GL_COLOR_BUFFER_BIT);
conical1();
conical2();
int i,j;
if(x!=0&&y==0)
{
i=x;
j=0;
}
else if(x==0&&y!=0)
{
i=0;
j=y;
}
else if(x!=0&&y!=0)
{
i=x;
j=y;
}
else
{
i=0;
j=0;
}
glColor3f(1.0,0.0,0.0);
glBegin(GL_LINE_LOOP);
glVertex2f(137.5+i,100+j);
glVertex2f(142.5+i,107.5+j);
glVertex2f(142.5+i,132.5+j);

Dept of CSE,GCE Ramanagaram

21

Chemical Reaction
glVertex2f(147.5+i,145+j);
glVertex2f(147.5+i,182.5+j);
glVertex2f(142.5+i,195+j);
glVertex2f(142.5+i,232.5+j);
glVertex2f(135+i,232.5+j);
glVertex2f(135+i,195+j);
glVertex2f(130+i,182.5+j);
glVertex2f(130+i,145+j);
glVertex2f(135+i,132.5+j);
glVertex2f(135+i,107.5+j);
glEnd();
glColor3f(1.0,0.0,0.0);
glBegin(GL_LINE_LOOP);
glVertex2f(142.5+i,232.5+j);
glVertex2f(142.5+i,257.5+j);
glVertex2f(135+i,257.5+j);
glVertex2f(135+i,232.5+j);
glEnd();
glColor3f(1.0,0.0,0.0);
draw_text(133.5+i,157.5+j,"P");
glFlush();
}
void display0()
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0,0.0,0.0);
glBegin(GL_LINE_LOOP);
glVertex2f(137.5,100);
glVertex2f(142.5,107.5);
glVertex2f(142.5,132.5);
glVertex2f(147.5,145);
glVertex2f(147.5,182.5);
glVertex2f(142.5,195);
glVertex2f(142.5,232.5);
glVertex2f(135,232.5);
glVertex2f(135,195);
glVertex2f(130,182.5);
glVertex2f(130,145);
glVertex2f(135,132.5);
glVertex2f(135,107.5);
glEnd();
glColor3f(0.3,0.4,1.0);
glBegin(GL_POLYGON);
glVertex2f(137.5,100);
glVertex2f(142.5,107.5);
glVertex2f(135,107.5);
glEnd();
glColor3f(0.3,0.4,1.0);
glBegin(GL_POLYGON);
glVertex2f(135,107.5);
glVertex2f(142.5,107.5);
glVertex2f(142.5,132.5);
glVertex2f(135,132.5);
glEnd();

Dept of CSE,GCE Ramanagaram

22

Chemical Reaction
glColor3f(0.3,0.4,1.0);
glBegin(GL_POLYGON);
glVertex2f(142.5,132.5);
glVertex2f(147.5,145);
glVertex2f(147.5,182.5);
glVertex2f(142.5,195);
glVertex2f(135,195);
glVertex2f(130,182.5);
glVertex2f(130,145);
glVertex2f(135,132.5);
glEnd();
glColor3f(0.3,0.4,1.0);
glBegin(GL_POLYGON);
glVertex2f(135,195);
glVertex2f(142.5,195);
glVertex2f(142.5,232.5);
glVertex2f(135,232.5);
glEnd();
glColor3f(1.0,0.0,0.0);
glBegin(GL_LINE_LOOP);
glVertex2f(142.5,232.5);
glVertex2f(142.5,257.5);
glVertex2f(135,257.5);
glVertex2f(135,232.5);
glEnd();
glColor3f(0.0,0.0,0.0);
draw_text(133.5,157.5,"P");
glColor3f(1.0,0.3,0.4);
glBegin(GL_POLYGON);
glVertex2f(275,25);
glVertex2f(400,25);
glVertex2f(377.5,100);
glVertex2f(297.5,100);
glEnd();
glBegin(GL_LINE_LOOP);
glColor3f(0.0,0.0,1.0);
glVertex2f(377.5,100);
glVertex2f(362.5,150);
glVertex2f(362.5,200);
glVertex2f(312.5,200);
glVertex2f(312.5,150);
glVertex2f(297.5,100);
glEnd();
glColor3f(0.0,0.0,0.0);
draw_text(320,55,"Acid");
glColor3f(1.0,0.0,0.0);
draw_text(270,90,"L1");
glColor3f(1.0,0.0,0.0);
draw_text(275,110,"L2");
glColor3f(1.0,0.0,0.0);
draw_text(280,135,"L3");
glColor3f(0.3,0.4,1.0);
glBegin(GL_POLYGON);
glVertex2f(70,25);
glVertex2f(200,25);

Dept of CSE,GCE Ramanagaram

23

Chemical Reaction
glVertex2f(185,75);
glVertex2f(90,75);
glEnd();
glColor3f(0.0,0.0,1.0);
glBegin(GL_LINE_LOOP);
glVertex2f(185,75);
glVertex2f(162.5,150);
glVertex2f(162.5,200);
glVertex2f(112.5,200);
glVertex2f(112.5,150);
glVertex2f(90,75);
glEnd();
glColor3f(0.0,0.0,0.0);
draw_text(117.5,55,"Base");
glColor3f(1.0,0.0,0.0);
draw_text(40,95,"Level1");
glColor3f(1.0,0.0,0.0);
draw_text(30,65,"Level2");
glFlush();

}
void display1()
{
int i,j;
for(j=0;j<150;j++)
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0,0.0,0.0);
glBegin(GL_LINE_LOOP);
glVertex2f(137.5,100+j);
glVertex2f(142.5,107.5+j);
glVertex2f(142.5,132.5+j);
glVertex2f(147.5,145+j);
glVertex2f(147.5,182.5+j);
glVertex2f(142.5,195+j);
glVertex2f(142.5,232.5+j);
glVertex2f(135,232.5+j);
glVertex2f(135,195+j);
glVertex2f(130,182.5+j);
glVertex2f(130,145+j);
glVertex2f(135,132.5+j);
glVertex2f(135,107.5+j);
glEnd();
glColor3f(0.3,0.4,1.0);
glBegin(GL_POLYGON);
glVertex2f(137.5,100+j);
glVertex2f(142.5,107.5+j);
glVertex2f(135,107.5+j);
glEnd();
glColor3f(0.3,0.4,1.0);
glBegin(GL_POLYGON);
glVertex2f(135,107.5+j);
glVertex2f(142.5,107.5+j);
glVertex2f(142.5,132.5+j);
glVertex2f(135,132.5+j);
glEnd();

Dept of CSE,GCE Ramanagaram

24

Chemical Reaction
glColor3f(0.3,0.4,1.0);
glBegin(GL_POLYGON);
glVertex2f(142.5,132.5+j);
glVertex2f(147.5,145+j);
glVertex2f(147.5,182.5+j);
glVertex2f(142.5,195+j);
glVertex2f(135,195+j);
glVertex2f(130,182.5+j);
glVertex2f(130,145+j);
glVertex2f(135,132.5+j);
glEnd();
glColor3f(0.3,0.4,1.0);
glBegin(GL_POLYGON);
glVertex2f(135,195+j);
glVertex2f(142.5,195+j);
glVertex2f(142.5,232.5+j);
glVertex2f(135,232.5+j);
glEnd();
glColor3f(1.0,0.0,0.0);
glBegin(GL_LINE_LOOP);
glVertex2f(142.5,232.5+j);
glVertex2f(142.5,257.5+j);
glVertex2f(135,257.5+j);
glVertex2f(135,232.5+j);
glEnd();
glColor3f(0.0,0.0,0.0);
draw_text(133.5,157.5+j,"P");
glColor3f(1.0,0.3,0.4);
glBegin(GL_POLYGON);
glVertex2f(275,25);
glVertex2f(400,25);
glVertex2f(377.5,100);
glVertex2f(297.5,100);
glEnd();
glBegin(GL_LINE_LOOP);
glColor3f(0.0,0.0,1.0);
glVertex2f(377.5,100);
glVertex2f(362.5,150);
glVertex2f(362.5,200);
glVertex2f(312.5,200);
glVertex2f(312.5,150);
glVertex2f(297.5,100);
glEnd();
glColor3f(0.0,0.0,0.0);
draw_text(320,55,"Acid");
glColor3f(1.0,0.0,0.0);
draw_text(270,90,"L1");
glColor3f(1.0,0.0,0.0);
draw_text(275,110,"L2");
glColor3f(1.0,0.0,0.0);
draw_text(280,135,"L3");
glColor3f(0.3,0.4,1.0);
glBegin(GL_POLYGON);
glVertex2f(70,25);
glVertex2f(200,25);

Dept of CSE,GCE Ramanagaram

25

Chemical Reaction
glVertex2f(185,75);
glVertex2f(90,75);
glEnd();
glColor3f(0.0,0.0,1.0);
glBegin(GL_LINE_LOOP);
glVertex2f(185,75);
glVertex2f(162.5,150);
glVertex2f(162.5,200);
glVertex2f(112.5,200);
glVertex2f(112.5,150);
glVertex2f(90,75);
glEnd();
glColor3f(0.0,0.0,0.0);
draw_text(117.5,55,"Base");
glColor3f(1.0,0.0,0.0);
draw_text(40,95,"Level1");
glColor3f(1.0,0.0,0.0);
draw_text(30,65,"Level2");
}
for(i=0;i<200;i++)
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0,0.0,0.0);
glBegin(GL_LINE_LOOP);
glVertex2f(137.5+i,100+j);
glVertex2f(142.5+i,107.5+j);
glVertex2f(142.5+i,132.5+j);
glVertex2f(147.5+i,145+j);
glVertex2f(147.5+i,182.5+j);
glVertex2f(142.5+i,195+j);
glVertex2f(142.5+i,232.5+j);
glVertex2f(135+i,232.5+j);
glVertex2f(135+i,195+j);
glVertex2f(130+i,182.5+j);
glVertex2f(130+i,145+j);
glVertex2f(135+i,132.5+j);
glVertex2f(135+i,107.5+j);
glEnd();
glColor3f(0.3,0.4,1.0);
glBegin(GL_POLYGON);
glVertex2f(137.5+i,100+j);
glVertex2f(142.5+i,107.5+j);
glVertex2f(135+i,107.5+j);
glEnd();
glColor3f(0.3,0.4,1.0);
glBegin(GL_POLYGON);
glVertex2f(135+i,107.5+j);
glVertex2f(142.5+i,107.5+j);
glVertex2f(142.5+i,132.5+j);
glVertex2f(135+i,132.5+j);
glEnd();
glColor3f(0.3,0.4,1.0);
glBegin(GL_POLYGON);
glVertex2f(142.5+i,132.5+j);
glVertex2f(147.5+i,145+j);

Dept of CSE,GCE Ramanagaram

26

Chemical Reaction
glVertex2f(147.5+i,182.5+j);
glVertex2f(142.5+i,195+j);
glVertex2f(135+i,195+j);
glVertex2f(130+i,182.5+j);
glVertex2f(130+i,145+j);
glVertex2f(135+i,132.5+j);
glEnd();
glColor3f(0.3,0.4,1.0);
glBegin(GL_POLYGON);
glVertex2f(135+i,195+j);
glVertex2f(142.5+i,195+j);
glVertex2f(142.5+i,232.5+j);
glVertex2f(135+i,232.5+j);
glEnd();
glColor3f(1.0,0.0,0.0);
glBegin(GL_LINE_LOOP);
glVertex2f(142.5+i,232.5+j);
glVertex2f(142.5+i,257.5+j);
glVertex2f(135+i,257.5+j);
glVertex2f(135+i,232.5+j);
glEnd();
glColor3f(0.0,0.0,0.0);
draw_text(133.5+i,157.5+j,"P");
glColor3f(1.0,0.3,0.4);
glBegin(GL_POLYGON);
glVertex2f(275,25);
glVertex2f(400,25);
glVertex2f(377.5,100);
glVertex2f(297.5,100);
glEnd();
glBegin(GL_LINE_LOOP);
glColor3f(0.0,0.0,1.0);
glVertex2f(377.5,100);
glVertex2f(362.5,150);
glVertex2f(362.5,200);
glVertex2f(312.5,200);
glVertex2f(312.5,150);
glVertex2f(297.5,100);
glEnd();
glColor3f(0.0,0.0,0.0);
draw_text(320,55,"Acid");
glColor3f(1.0,0.0,0.0);
draw_text(270,90,"L1");
glColor3f(1.0,0.0,0.0);
draw_text(275,110,"L2");
glColor3f(1.0,0.0,0.0);
draw_text(280,135,"L3");
glColor3f(0.3,0.4,1.0);
glBegin(GL_POLYGON);
glVertex2f(70,25);
glVertex2f(200,25);
glVertex2f(185,75);
glVertex2f(90,75);
glEnd();
glColor3f(0.0,0.0,1.0);

Dept of CSE,GCE Ramanagaram

27

Chemical Reaction
glBegin(GL_LINE_LOOP);
glVertex2f(185,75);
glVertex2f(162.5,150);
glVertex2f(162.5,200);
glVertex2f(112.5,200);
glVertex2f(112.5,150);
glVertex2f(90,75);
glEnd();
glColor3f(0.0,0.0,0.0);
draw_text(117.5,55,"Base");
glColor3f(1.0,0.0,0.0);
draw_text(40,95,"Level1");
glColor3f(1.0,0.0,0.0);
draw_text(30,65,"Level2");
glFlush();
}
}
void display2()
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0.3,0.4,1.0);
glBegin(GL_POLYGON);
glVertex2f(70,25);
glVertex2f(200,25);
glVertex2f(185,75);
glVertex2f(90,75);
glEnd();
glColor3f(0.0,0.0,1.0);
glBegin(GL_LINE_LOOP);
glVertex2f(185,75);
glVertex2f(162.5,150);
glVertex2f(162.5,200);
glVertex2f(112.5,200);
glVertex2f(112.5,150);
glVertex2f(90,75);
glEnd();
glColor3f(0.0,0.0,0.0);
draw_text(117.5,55,"Base");
glColor3f(1.0,0.0,0.0);
draw_text(40,95,"Level1");
glColor3f(1.0,0.0,0.0);
draw_text(30,65,"Level2");
glColor3f(1.0,0.3,0.4);
glBegin(GL_POLYGON);
glVertex2f(275,25);
glVertex2f(400,25);
glVertex2f(377.5,100);
glVertex2f(297.5,100);
glEnd();
glBegin(GL_LINE_LOOP);
glColor3f(0.0,0.0,1.0);
glVertex2f(377.5,100);
glVertex2f(362.5,150);
glVertex2f(362.5,200);
glVertex2f(312.5,200);

Dept of CSE,GCE Ramanagaram

28

Chemical Reaction
glVertex2f(312.5,150);
glVertex2f(297.5,100);
glEnd();
glColor3f(0.0,0.0,0.0);
draw_text(320,55,"Acid");
glColor3f(1.0,0.0,0.0);
draw_text(270,90,"L1");
glColor3f(1.0,0.0,0.0);
draw_text(275,110,"L2");
glColor3f(1.0,0.0,0.0);
draw_text(280,135,"L3");
glBegin(GL_LINE_LOOP);
glColor3f(1.0,0.0,0.0);
glVertex2f(337.5,192.5);
glVertex2f(342.5,200);
glVertex2f(342.5,237.5);
glVertex2f(347.5,250);
glVertex2f(347.5,300);
glVertex2f(342.5,312.5);
glVertex2f(342.5,350);
glVertex2f(335,350);
glVertex2f(335,312.5);
glVertex2f(330,300);
glVertex2f(330,250);
glVertex2f(335,237.5);
glVertex2f(335,200);
glEnd();
glBegin(GL_POLYGON);
glColor3f(0.3,0.4,1.0);
glVertex2f(337.5,192.5);
glVertex2f(342.5,200);
glVertex2f(335,200);
glEnd();
glBegin(GL_POLYGON);
glColor3f(0.3,0.4,1.0);
glVertex2f(335,200);
glVertex2f(342.5,200);
glVertex2f(342.5,237.5);
glVertex2f(335,237.5);
glEnd();
glBegin(GL_POLYGON);
glColor3f(0.3,0.4,1.0);
glVertex2f(335,237.5);
glVertex2f(342.5,237.5);
glVertex2f(347.5,250);
glVertex2f(347.5,300);
glVertex2f(342.5,312.5);
glVertex2f(335,312.5);
glVertex2f(330,300);
glVertex2f(330,250);
glEnd();
glBegin(GL_POLYGON);
glColor3f(0.3,0.4,1.0);
glVertex2f(335,312.5);
glVertex2f(342.5,312.5);

Dept of CSE,GCE Ramanagaram

29

Chemical Reaction
glVertex2f(342.5,350);
glVertex2f(335,350);
glEnd();
glBegin(GL_LINE_LOOP);
glColor3f(1.0,0.0,0.0);
glVertex2f(342.5,350);
glVertex2f(342.5,375);
glVertex2f(335,375);
glVertex2f(335,350);
glEnd();
glColor3f(1.0,0.0,0.0);
draw_text(333.9,265,"P");
glColor3f(0.3,0.4,1.0);
glBegin(GL_LINES);
glVertex2f(337.5,187.5);
glVertex2f(337.5,175);
glVertex2f(337.5,170);
glVertex2f(337.5,160);
glVertex2f(337.5,155);
glVertex2f(337.5,142.5);
glVertex2f(337.5,135);
glVertex2f(337.5,125);
glVertex2f(337.5,117.5);
glVertex2f(337.5,105);
glEnd();
glFlush();
}
void displaya()
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0.3,0.4,1.0);
glBegin(GL_POLYGON);
glVertex2f(70,25);
glVertex2f(200,25);
glVertex2f(185,75);
glVertex2f(90,75);
glEnd();
glColor3f(0.0,0.0,1.0);
glBegin(GL_LINE_LOOP);
glVertex2f(185,75);
glVertex2f(162.5,150);
glVertex2f(162.5,200);
glVertex2f(112.5,200);
glVertex2f(112.5,150);
glVertex2f(90,75);
glEnd();
glColor3f(0.0,0.0,0.0);
draw_text(117.5,55,"Base");
glColor3f(1.0,0.0,0.0);
draw_text(40,95,"Level1");
glColor3f(1.0,0.0,0.0);
draw_text(30,65,"Level2");
glColor3f(1.0,0.3,0.4);
glBegin(GL_POLYGON);
glVertex2f(275,25);

Dept of CSE,GCE Ramanagaram

30

Chemical Reaction
glVertex2f(400,25);
glVertex2f(377.5,100);
glVertex2f(297.5,100);
glEnd();
glBegin(GL_LINE_LOOP);
glColor3f(0.0,0.0,1.0);
glVertex2f(377.5,100);
glVertex2f(362.5,150);
glVertex2f(362.5,200);
glVertex2f(312.5,200);
glVertex2f(312.5,150);
glVertex2f(297.5,100);
glEnd();
glColor3f(0.0,0.0,0.0);
draw_text(320,55,"Acid");
glColor3f(1.0,0.0,0.0);
draw_text(270,90,"L1");
glColor3f(1.0,0.0,0.0);
draw_text(275,110,"L2");
glColor3f(1.0,0.0,0.0);
draw_text(280,135,"L3");
glBegin(GL_LINE_LOOP);
glColor3f(1.0,0.0,0.0);
glVertex2f(337.5,192.5);
glVertex2f(342.5,200);
glVertex2f(342.5,237.5);
glVertex2f(347.5,250);
glVertex2f(347.5,300);
glVertex2f(342.5,312.5);
glVertex2f(342.5,350);
glVertex2f(335,350);
glVertex2f(335,312.5);
glVertex2f(330,300);
glVertex2f(330,250);
glVertex2f(335,237.5);
glVertex2f(335,200);
glEnd();
glBegin(GL_POLYGON);
glColor3f(0.3,0.4,1.0);
glVertex2f(337.5,192.5);
glVertex2f(342.5,200);
glVertex2f(335,200);
glEnd();
glBegin(GL_POLYGON);
glColor3f(0.3,0.4,1.0);
glVertex2f(335,200);
glVertex2f(342.5,200);
glVertex2f(342.5,237.5);
glVertex2f(335,237.5);
glEnd();
glBegin(GL_POLYGON);
glColor3f(0.3,0.4,1.0);
glVertex2f(335,237.5);
glVertex2f(342.5,237.5);
glVertex2f(347.5,250);

Dept of CSE,GCE Ramanagaram

31

Chemical Reaction
glVertex2f(347.5,300);
glVertex2f(342.5,312.5);
glVertex2f(335,312.5);
glVertex2f(330,300);
glVertex2f(330,250);
glEnd();
glBegin(GL_LINE_LOOP);
glColor3f(1.0,0.0,0.0);
glVertex2f(342.5,350);
glVertex2f(342.5,375);
glVertex2f(335,375);
glVertex2f(335,350);
glEnd();
glColor3f(1.0,0.0,0.0);
draw_text(333.9,265,"P");
glColor3f(0.3,0.4,1.0);
glBegin(GL_LINES);
glVertex2f(337.5,187.5);
glVertex2f(337.5,175);
glVertex2f(337.5,170);
glVertex2f(337.5,160);
glVertex2f(337.5,155);
glVertex2f(337.5,142.5);
glVertex2f(337.5,135);
glVertex2f(337.5,125);
glVertex2f(337.5,117.5);
glVertex2f(337.5,105);
glEnd();
glFlush();

}
void displayb()
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0.3,0.4,1.0);
glBegin(GL_POLYGON);
glVertex2f(70,25);
glVertex2f(200,25);
glVertex2f(185,75);
glVertex2f(90,75);
glEnd();
glColor3f(0.0,0.0,1.0);
glBegin(GL_LINE_LOOP);
glVertex2f(185,75);
glVertex2f(162.5,150);
glVertex2f(162.5,200);
glVertex2f(112.5,200);
glVertex2f(112.5,150);
glVertex2f(90,75);
glEnd();
glColor3f(0.0,0.0,0.0);
draw_text(117.5,55,"Base");
glColor3f(1.0,0.0,0.0);
draw_text(40,95,"Level1");
glColor3f(1.0,0.0,0.0);
draw_text(30,65,"Level2");

Dept of CSE,GCE Ramanagaram

32

Chemical Reaction
glColor3f(1.0,0.3,0.4);
glBegin(GL_POLYGON);
glVertex2f(275,25);
glVertex2f(400,25);
glVertex2f(372.5,112.5);
glVertex2f(302.5,112.5);
glEnd();
glBegin(GL_LINE_LOOP);
glColor3f(0.0,0.0,1.0);
glVertex2f(372.5,112.5);
glVertex2f(362.5,150);
glVertex2f(362.5,200);
glVertex2f(312.5,200);
glVertex2f(312.5,150);
glVertex2f(302.5,112.5);
glEnd();
glColor3f(0.0,0.0,0.0);
draw_text(320,55,"Acid");
glColor3f(1.0,0.0,0.0);
draw_text(270,90,"L1");
glColor3f(1.0,0.0,0.0);
draw_text(275,110,"L2");
glColor3f(1.0,0.0,0.0);
draw_text(280,135,"L3");
glBegin(GL_LINE_LOOP);
glColor3f(1.0,0.0,0.0);
glVertex2f(337.5,192.5);
glVertex2f(342.5,200);
glVertex2f(342.5,237.5);
glVertex2f(347.5,250);
glVertex2f(347.5,300);
glVertex2f(342.5,312.5);
glVertex2f(342.5,350);
glVertex2f(335,350);
glVertex2f(335,312.5);
glVertex2f(330,300);
glVertex2f(330,250);
glVertex2f(335,237.5);
glVertex2f(335,200);
glEnd();
glBegin(GL_POLYGON);
glColor3f(0.3,0.4,1.0);
glVertex2f(337.5,192.5);
glVertex2f(342.5,200);
glVertex2f(335,200);
glEnd();
glBegin(GL_POLYGON);
glColor3f(0.3,0.4,1.0);
glVertex2f(335,200);
glVertex2f(342.5,200);
glVertex2f(342.5,237.5);
glVertex2f(335,237.5);
glEnd();
glBegin(GL_LINE_LOOP);
glColor3f(1.0,0.0,0.0);

Dept of CSE,GCE Ramanagaram

33

Chemical Reaction
glVertex2f(342.5,350);
glVertex2f(342.5,375);
glVertex2f(335,375);
glVertex2f(335,350);
glEnd();
glColor3f(1.0,0.0,0.0);
draw_text(333.9,265,"P");
glColor3f(0.3,0.4,1.0);
glBegin(GL_LINES);
glVertex2f(337.5,187.5);
glVertex2f(337.5,175);
glVertex2f(337.5,170);
glVertex2f(337.5,160);
glVertex2f(337.5,155);
glVertex2f(337.5,142.5);
glVertex2f(337.5,135);
glVertex2f(337.5,125);
glEnd();
glFlush();

}
void displayc()
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0.3,0.4,1.0);
glBegin(GL_POLYGON);
glVertex2f(70,25);
glVertex2f(200,25);
glVertex2f(185,75);
glVertex2f(90,75);
glEnd();
glColor3f(0.0,0.0,1.0);
glBegin(GL_LINE_LOOP);
glVertex2f(185,75);
glVertex2f(162.5,150);
glVertex2f(162.5,200);
glVertex2f(112.5,200);
glVertex2f(112.5,150);
glVertex2f(90,75);
glEnd();
glColor3f(0.0,0.0,0.0);
draw_text(117.5,55,"Base");
glColor3f(1.0,0.0,0.0);
draw_text(40,95,"Level1");
glColor3f(1.0,0.0,0.0);
draw_text(30,65,"Level2");
glColor3f(1.0,0.3,0.4);
glBegin(GL_POLYGON);
glVertex2f(275,25);
glVertex2f(400,25);
glVertex2f(367.5,137.5);
glVertex2f(310,137.5);
glEnd();
glBegin(GL_LINE_LOOP);
glColor3f(0.0,0.0,1.0);
glVertex2f(367.5,137.5);

Dept of CSE,GCE Ramanagaram

34

Chemical Reaction
glVertex2f(362.5,150);
glVertex2f(362.5,200);
glVertex2f(312.5,200);
glVertex2f(312.5,150);
glVertex2f(310,137.5);
glEnd();
glColor3f(0.0,0.0,0.0);
draw_text(320,55,"Acid");
glColor3f(1.0,0.0,0.0);
draw_text(270,90,"L1");
glColor3f(1.0,0.0,0.0);
draw_text(275,110,"L2");
glColor3f(1.0,0.0,0.0);
draw_text(280,135,"L3");
glBegin(GL_LINE_LOOP);
glColor3f(1.0,0.0,0.0);
glVertex2f(337.5,192.5);
glVertex2f(342.5,200);
glVertex2f(342.5,237.5);
glVertex2f(347.5,250);
glVertex2f(347.5,300);
glVertex2f(342.5,312.5);
glVertex2f(342.5,350);
glVertex2f(335,350);
glVertex2f(335,312.5);
glVertex2f(330,300);
glVertex2f(330,250);
glVertex2f(335,237.5);
glVertex2f(335,200);
glEnd();
glBegin(GL_POLYGON);
glColor3f(0.3,0.4,1.0);
glVertex2f(337.5,192.5);
glVertex2f(342.5,200);
glVertex2f(335,200);
glEnd();
glBegin(GL_LINE_LOOP);
glColor3f(1.0,0.0,0.0);
glVertex2f(342.5,350);
glVertex2f(342.5,375);
glVertex2f(335,375);
glVertex2f(335,350);
glEnd();
glColor3f(1.0,0.0,0.0);
draw_text(333.9,265,"P");
glColor3f(0.3,0.4,1.0);
glBegin(GL_LINES);
glVertex2f(337.5,187.5);
glVertex2f(337.5,175);
glVertex2f(337.5,170);
glVertex2f(337.5,160);
glVertex2f(337.5,155);
glVertex2f(337.5,142.5);
glEnd();
glFlush();

Dept of CSE,GCE Ramanagaram

35

Chemical Reaction
}
void display3()
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0.3,0.4,1.0);
glBegin(GL_POLYGON);
glVertex2f(70,25);
glVertex2f(200,25);
glVertex2f(185,75);
glVertex2f(90,75);
glEnd();
glColor3f(0.0,0.0,1.0);
glBegin(GL_LINE_LOOP);
glVertex2f(185,75);
glVertex2f(162.5,150);
glVertex2f(162.5,200);
glVertex2f(112.5,200);
glVertex2f(112.5,150);
glVertex2f(90,75);
glEnd();
glColor3f(0.0,0.0,0.0);
draw_text(117.5,55,"Base");
glColor3f(1.0,0.0,0.0);
draw_text(40,95,"Level1");
glColor3f(1.0,0.0,0.0);
draw_text(30,65,"Level2");
glColor3f(0.9,456.0,0.5);
glBegin(GL_POLYGON);
glVertex2f(275,25);
glVertex2f(400,25);
glVertex2f(367.5,137.5);
glVertex2f(310,137.5);
glEnd();
glBegin(GL_LINE_LOOP);
glColor3f(0.0,0.0,1.0);
glVertex2f(367.5,137.5);
glVertex2f(362.5,150);
glVertex2f(362.5,200);
glVertex2f(312.5,200);
glVertex2f(312.5,150);
glVertex2f(310,137.5);
glEnd();
glColor3f(0.0,0.0,0.0);
draw_text(293.5,55,"Neutralized");
glColor3f(1.0,0.0,0.0);
draw_text(270,90,"L1");
glColor3f(1.0,0.0,0.0);
draw_text(275,110,"L2");
glColor3f(1.0,0.0,0.0);
draw_text(280,135,"L3");
glBegin(GL_LINE_LOOP);
glColor3f(1.0,0.0,0.0);
glVertex2f(337.5,192.5);
glVertex2f(342.5,200);
glVertex2f(342.5,237.5);

Dept of CSE,GCE Ramanagaram

36

Chemical Reaction
glVertex2f(347.5,250);
glVertex2f(347.5,300);
glVertex2f(342.5,312.5);
glVertex2f(342.5,350);
glVertex2f(335,350);
glVertex2f(335,312.5);
glVertex2f(330,300);
glVertex2f(330,250);
glVertex2f(335,237.5);
glVertex2f(335,200);
glEnd();
glBegin(GL_LINE_LOOP);
glColor3f(1.0,0.0,0.0);
glVertex2f(342.5,350);
glVertex2f(342.5,375);
glVertex2f(335,375);
glVertex2f(335,350);
glEnd();
glColor3f(1.0,0.0,0.0);
draw_text(333.9,265,"P");
glFlush();

}
void demo_menu(int id)
{
switch(id)
{
case 1:exit(0);
break;
}
}
void keys(unsigned char key,int x,int y)
{
if(key=='p') display0();
if(key=='m') display1();
if(key=='d') display2();
if(key=='1') displaya();
if(key=='2') displayb();
if(key=='3') displayc();
if(key=='r') display3();
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
conical1();
conical2();
pipette(0,0);
glFlush();
}
void myinit()
{
glClearColor(0.0,0.0,0.0,1.0);
glColor3f(1.0,0.0,0.0);
glPointSize(1.0);

Dept of CSE,GCE Ramanagaram

37

Chemical Reaction
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0,499.0,0.0,499.0);

}
void main(int argc,char**argv)
{
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(500,500);
glutInitWindowPosition(0,0);
glutCreateWindow("chemical Reaction");
glutDisplayFunc(display);
glutCreateMenu(demo_menu);
glutAddMenuEntry("Quit",1);
glutAttachMenu(GLUT_RIGHT_BUTTON);
glutKeyboardFunc(keys);
myinit();
glutMainLoop();
}

Dept of CSE,GCE Ramanagaram

38

Chemical Reaction

Chapter 5
SNAPSHOT AND RESULT DISCUSSION

Snapshot 5.1: Initial output window when the display( ) function is called.

When the display() function gets called, the o/p window displays the 2 conical flask, one
containing base solution and other one containing acid solution. And also, a pipette is
immersed in a conical flask containing base solution.

Dept of CSE,GCE Ramanagaram

39

Chemical Reaction

Snapshot 5.2: The base solution is pipetted in when the key p is pressed.

When the key p is pressed, the base solution gets pipetted into the pipette. As the base
solution gets pipetted, the decrease in the level of the base solution is shown in the conical
flask.

Dept of CSE,GCE Ramanagaram

40

Chemical Reaction

Snapshot 5.3: The pipette moves towards the conical flask containing acid when the key m
is pressed.

When the key m is pressed, the pipette moves from the conical flask containing
base solution to the conical flask containing acid solution.

Dept of CSE,GCE Ramanagaram

41

Chemical Reaction

Snapshot 5.4: The base solution is pipetted out into the conical flask containing acid when the
key 1 is pressed.

When the key 1 is pressed, the base solution is pipetted out into the acid solution.
Also we can see that there is an increase in the level of the solution in the conical flask
containing acid.

Dept of CSE,GCE Ramanagaram

42

Chemical Reaction

Snapshot 5.5: The base solution is pipetted out into the conical flask containing acid when the
key 2 is pressed.

When the key 2 is pressed, some more amount of base solution gets pippetted out
into the conical flask, and also we can see some more increase in the level of the acid
solution.

Dept of CSE,GCE Ramanagaram

43

Chemical Reaction

Snapshot 5.6: The base solution is pipetted out into the conical flask containing acid when the
key 3 is pressed.

When the key 3 is pressed, the base solution is completely pipette out into the
conical flask containing acid solution. And thus we can see further more increase in the level
of the acid solution in the conical flask.

Dept of CSE,GCE Ramanagaram

44

Chemical Reaction

Snapshot 5.7: Acid and base solution reacts and the resultant solution gets neutralized.

Finally when the key r is pressed, we can see the change in the colour of the acid
solution. This indicates that, there is a reaction between the base and the acid solution, and
the resultant solution gets neutralised.

Dept of CSE,GCE Ramanagaram

45

Chemical Reaction

Conclusion and Future Enhancements


Conclusion
The present project is an interactive project since it is based on the user
input.Chemical Reaction is effectively implemented in computer graphics using OpenGL
API.
Our mini project is only an attempt to understand some of the concepts of using
Computer Graphics using OpenGL.
The package also has a user-friendly interface that may be menu-oriented, iconic or
the combination of both. All the basic editing features are made available with minimum
complexity.

Future Enhancement
We can add these future enhancements to our mini project:

With complex interior structures, we can add the capabilities of lighting, shadows and

camera view.
Usage of complex graphics so that the appearance of the output can be beautified.
We can use different objects to make it more attractive.
We can create scenes with realistic atmospheric effects.
There can be future enhancements in the project like designing of a detailed 3D
chemical apparatus.

Dept of CSE,GCE Ramanagaram

46

Chemical Reaction

Appendix
OpenGL functions used in Project:
Built In Functions used:
All these functions have been prototyped in the file GL/glut.h. Hence this file have to
be included whenever we use these functions in the program.

glutInit( ) : glutInit is used to initialize the GLUT library.


void glutInit(int *argcp, char **argv);
argcp
A pointer to the program's unmodified argc variable from main. Upon return, the value
pointed to by argcp will be updated, because glutInit extracts any command line options
intended for the GLUT library.
argv
The program's unmodified argv variable from main. Like argcp, the data for argv will
be updated because glutInit extracts any command line options understood by the GLUT
library.
glutInit will initialize the GLUT library and negotiate a session with the window
system. During this process, glutInit may cause the termination of the GLUT program
with an error message to the user if GLUT cannot be properly initialized. Examples of
this situation include the failure to connect to the window system, the lack of window
system support for OpenGL, and invalid command line options.
glutInit also processes command line options, but the specific options parse are
window system dependent.

glutDisplayFunc( ) : glutDisplayFunc sets the display callback for the current window.
void glutDisplayFunc(void (*func)(void));
func
The new display callback function.

Dept of CSE,GCE Ramanagaram

47

Chemical Reaction
glutDisplayFunc sets the display callback for the current window. When GLUT
determines that the normal plane for the window needs to be redisplayed, the display
callback for the window is called. Before the callback, the current window is set to the
window needing to be redisplayed and (if no overlay display callback is registered)
the layer in use is set to the normal plane. The display callback is called with no
parameters. The entire normal plane region should be redisplayed in response to the
callback (this includes ancillary buffers if your program depends on their state).
GLUT determines when the display callback should be triggered based on the
window's redisplay state. The redisplay state for a window can be either set explicitly by
calling glutPostRedisplay or implicitly as the result of window damage reported by the
window system. Multiple posted redisplays for a window are coalesced by GLUT to
minimize the number of display callbacks called.

glutKeyboardFunc ( ) : glutKeyboardFunc sets the keyboard callback for the current


window.
void glutKeyboardFunc(void (*func)(unsigned char key, int x, int y));
func
The new keyboard callback function.
glutKeyboardFunc sets the keyboard callback for the current window. When a
user types into the window, each key press generating an ASCII character will generate a
keyboard callback. The key callback parameter is the generated ASCII character. The
state of modifier keys such as Shift cannot be determined directly; their only effect will be
on the returned ASCII data. The x and y callback parameters indicate the mouse location
in window relative coordinates when the key was pressed. When a new window is
created, no keyboard callback is initially registered, and ASCII key strokes in the window
are ignored. Passing NULL to glutKeyboardFunc disables the generation of keyboard
callbacks.

glutMainLoop( ) : glutMainLoop enters the GLUT event processing loop.


void glutMainLoop(void);

Dept of CSE,GCE Ramanagaram

48

Chemical Reaction
glutMainLoop enters the GLUT event processing loop. This routine should be called
at most once in a GLUT program. Once called, this routine will never return. It will call
as necessary any callbacks that have been registered.

glLoadIdentity ( ): glLoadIdentity replace the current matrix with the identity matrix
void glLoadIdentity(

void);

glLoadIdentity replaces the current matrix with the identity matrix. It is semantically
equivalent to calling glLoadMatrix with the identity matrix
1000010000100001
but in some cases it is more efficient.

gluOrtho2D( ): gluOrtho2D define a 2D orthographic projection matrix


void gluOrtho2D( GLdouble left, GLdouble right, GLdouble bottom, GLdouble top);
left, right
Specify the coordinates for the left and right vertical clipping planes.
bottom, top
Specify the coordinates for the bottom and top horizontal clipping planes.
gluOrtho2D sets up a two-dimensional orthographic viewing region. This is
equivalent to calling glOrtho with near = -1 and far = 1 .

glClearColor( ): glClearColor specify clear values for the color buffers


void glClearColor(GLclampf red, GLclampf green, GLclampf blue ,GLclampf alpha);
red, green, blue, alpha
Specify the red, green, blue, and alpha values are used wen the color buffers are
cleared. The initial values are all 0.

Dept of CSE,GCE Ramanagaram

49

Chemical Reaction
glClearColor specifies the red, green, blue, and alpha values used by glClear to
clear the color buffers. Values specified by glClearColor are clamped to the range 0 1.

glutInitDisplayMode():glutInitDisplayMode sets the initial display mode.


void glutInitDisplayMode(unsigned int mode);
mode
Display mode, normally the bitwise OR-ing of GLUT display mode bit masks.
The initial display mode is used when creating top-level windows, subwindows,
and overlays to determine the OpenGL display mode for the to-be-created window or
overlay.

glutBitMapCharacter( ): glutBitmapCharacter renders a bitmap character using


OpenGL.
void glutBitmapCharacter(void *font, int character);
font
Bitmap font to use.
character
Character to render (not confined to 8 bits)
Without using any display lists, glutBitmapCharacter renders the character in the
named bitmap font.

glBegin( ): glBegin delimit the vertices of a primitive or a group of like primitives.


void glBegin(GLenum mode);
mode
Specifies the primitive or primitives that will be created from vertices presented
between glBegin and

the

subsequent glEnd.

Ten

symbolic

constants

are

accepted: GL_POINTS, GL_LINES, GL_LINE_STRIP, GL_LINE_LOOP, GL_TRIANG


LES, GL_TRIANGLE_STRIP, GL_TRIANGLE_FAN, GL_QUADS,GL_QUAD_STRIP
, and GL_POLYGON.

glEnd( ): Ends the list of vertices.


void glEnd(

Dept of CSE,GCE Ramanagaram

void);

50

Chemical Reaction

glBegin and glEnd delimit the vertices that define a primitive or a group of like
primitives. glBegin accepts a single argument that specifies in which of ten ways the
vertices are interpreted.

glFlush( ): glFlush force execution of GL commands in finite time


void glFlush

( );

Different GL implementations buffer commands in several different locations,


including network buffers and the graphics accelerator itself. glFlush empties all of these
buffers, causing all issued commands to be executed as quickly as they are accepted by
the actual rendering engine. Though this execution may not be completed in any
particular time period, it does complete in finite time.

Dept of CSE,GCE Ramanagaram

51

Chemical Reaction

References
[1] Interactive Computer Graphics a Top down Approach with OpenGL 5th Edition,
Addison- Wesley,2008 Edward Angel.
[2] Computer Graphics Using OpenGL 2nd Edition, Pearson Education, 2001- F.S.
Hill,Jr.
[3] Computer Graphics - OpenGL Version 2nd Edition, Pearson Education, 2003Donald Hearn and Pauline Baker,

http:// www.opengl.org/

Dept of CSE,GCE Ramanagaram

52

You might also like