You are on page 1of 29

Ex.

no :1
IMPLEMENTATION OF LINE, CIRCLE AND ELLIPSE
DRAWING
Date:30-07-2019

AIM:

To write a program to implement Bresenham’s algorithms for line, circle and ellipse drawing.

ALGORITHM:

Step1: Create a function for line circle and ellipse.

Step2: calculate contents Ax, Ay, 2Ay, 2Ay-2Ax and P0=2Ay-Ax to draw the line.

Step3: Calculate the initial value parameter as q=q+(4*m)+10 ,q=q+(4*(m-n))+10 and draw circle using
cplot(x,y,m,n).

Step4: Calculate putpixel(xc+rx*cos(i*3.14/180),yc+ry*sin(i*3.14/180),15) to draw the ellipse drawing.

Step5: Display line, circle and ellipse drawing of Bresenham’s algorithm.

1
PROGRAM:

#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<graphics.h>
void lined(int, int, int, int);
void circled(int, int, int);
void ellipsed(int, int, int, int);
void main( )
{
int x, y, xe, ye, r, rx, ry, n;
int gd=DETECT, gm;
initgraph(&gd, &gm, "e:\\tc\\bgi");
do
{
clrscr( );
printf("\n1. Line\n2. Circle\n3. Ellipse\n");
printf("Enter the Choice:");
scanf("%d",&n);
switch(n)
{
case 1:
printf("\nLINE DRAWING\nEnter the x and y axis:");
scanf("\n%d%d",&x,&y);
printf("\nEnter the Xend and yend:");
scanf("%d%d",&xe,&ye);
lined(x,y,xe,ye);
break;
case 2:
printf("\nCIRCLE DRAWING”);
printf(“\nEnter the x and y axis and also Radius:");
scanf("%d%d%d",&x,&y,&r);
circled(x,y,r);
break;
case 3:
printf("\nELLIPSE DRAWING”)
printf(“\nEnter the x,y and rx,ry:");
scanf("%d%d%d%d",&x,&y,&rx,&ry);
ellipsed(x,y,rx,ry);
break;
default:
exit(0);
break;
}
}
while(n<=3);
getch();

2
closegraph( );
}
void lined(int xa,int ya,int xb,int yb)
{
int dx=abs(xa-xb);
int dy=abs(ya-yb);
int p=2*dy-dx;
int xend=2*dy;
int yend=2*(dy-dx);
int x,y,end;
if(xa>xb)
{
x=xb;
y=yb;
xend=xa;
}
else
{
x=xa;
y=ya;
yend=xb;
}
while(x<xend)
{
x++;
if(p<0)
p+=xend;
else
{
y++;
p+=yend;
}
putpixel(x,y,10);
}
getch( );
}
void circled(int x,int y,int r)
{
int m=0,n=r, q;
void cplot(int,int,int,int);
q=3-(2*r);
while(m<n)
{
cplot(x,y,m,n);
if(q<0)
q=q+(4*m)+10;
else
{

3
q=q+(4*(m-n))+10;
n--;
}
m++;
}
if(m==n)
cplot(x,y,m,n);
getch( );
}
void cplot(int xc,int yc,int x,int y)
{
putpixel(xc+x,yc+y,15);
putpixel(xc-x,yc+y,15);
putpixel(xc+x,yc-y,15);
putpixel(xc-x,yc-y,15);
putpixel(xc+y,yc+x,15);
putpixel(xc-y,yc+x,15);
putpixel(xc+y,yc-x,15);
putpixel(xc-y,yc-x,15);
}
void ellipsed(int xc,int yc,int rx,int ry)
{
int i;
for(i=0;i<=360;i++)
{
putpixel(xc+rx*cos(i*3.14/180),yc+ry*sin(i*3.14/180),15);
}
getch( );
}

4
OUTPUT:-

1. Line

2. Circle

3. Ellipse

Enter the Choice:1

LINE DRAWING

Enter the x and y axis:10

15

Enter the Xend and yend:

45

60

1. Line

2. Circle

3. Ellipse

Enter the Choice:2

CIRCLE DRAWING

Enter the x and y axis and also Radius:45

45

45

5
1. Line

2. Circle

3. Ellipse

Enter the Choice:3

ELLIPSE DRAWING

Enter the x,y and rx,ry:45

45
45
45

RESULT:

Thus the program implementation of Bresenham’s algorithm for line, circle and ellipse drawing is done
successfully.

6
Ex.no :2
IMPLEMENTATION OF POLYGON CLIPPING AND POLYGON FILLING
Date:13-08-2019

AIM:
To create a program to implement polygon clipping and polygon filling Using algorithm.

ALGORITHM:

Step 1: Start the Program.

Step 2: Include the graphics header file

Step 3: Create a function to get the line co-ordinates and window co-ordinate values.

Step4: Check all the co-ordinates of the lines are within the window co-ordinate or not.

Step5: Clip the lines which are all outside of the window co-ordinates.

Step6: After the clipping draw all the lines along with the window.

7
PROGRAM:
import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.image.BufferedImage;
import java.util.*;
public class Application extends JPanel
implements MouseListener
{
private static final int WIDTH = 720;
private static final int HEIGHT = 480;
private static final int BOUNDARY_RGB=Color.blue.getRGB();
private static final Color BLUE=Color.BLUE;
private BufferedImage mImage;
private ArrayList<Point> mVertices;
private Integer mFloodPoint;
private static Point point;
private void clearImage()
{
mVertices = new ArrayList<>();
Graphics2D graphics2D = mImage.createGraphics();
graphics2D.setBackground(Color.black);
graphics2D.clearRect(0,0,WIDTH,HEIGHT);
repaint();
revalidate();
}
Application()
{
mImage = new BufferedImage(WIDTH, HEIGHT,BufferedImage.TYPE_3BYTE_BGR);

8
mVertices = new ArrayList<>();
mFloodPoint = 0;
point = new Point(0,0);
addMouseListener(this);
}@Override
protected void paintComponent(Graphics g)
{
super.paintComponent(g);
Graphics2D graphics2D = mImage.createGraphics();
graphics2D.setBackground(Color.black);
g.drawImage(mImage,0,0,this);
}@Override
public void mouseClicked(MouseEvent e)
{
}
private boolean isVertexPoint(int x, int y)
{
for(Point point :mVertices)
if(point.X == x && point.Y == y)
return true;
return false;
}
private boolean isInside(int x, int y)
{
boolean result = false;
int i,j;
for (i = 0, j = mVertices.size()- 1; i < mVertices.size(); j = i++)
{
if ((mVertices.get(i).Y > y) != (mVertices.get(j).Y > y) &&
(x < (mVertices.get(j).X - mVertices.get(i).X) *(y - mVertices.get(i).Y)

9
(mVertices.get(j).Y-mVertices.get(i).Y) + mVertices.get(i).X))
{
result = !result;
}
}
return result;
}
private void drawPolygon()
{
if(mVertices.size() >= 3)
{
int totalVertices = mVertices.size();
Graphics2D graphics2D = mImage.createGraphics();
graphics2D.setColor(BLUE);
for(int i = 0 ; i < totalVertices - 1; ++i)
{
Point current = mVertices.get(i);
Point next = mVertices.get(i+1);
graphics2D.drawLine(current.X,current.Y,next.X, next.Y);
}
Point first = mVertices.get(0);
Point last = mVertices.get(totalVertices -1);
graphics2D.drawLine(first.X,first.Y,last.X,last.Y);
repaint();
revalidate();
}
}@Override
public void mousePressed(MouseEvent e)
{
if(e.getButton() == MouseEvent.BUTTON1)

10
{
System.out.println("Adding point : " + e.getX()+" "+e.getY());
mVertices.add(new Point(e.getX(),e.getY()));
}
else if(e.getButton() == MouseEvent.BUTTON3)
{
if(mFloodPoint==0)
{
System.out.println("Drawing polygon");
drawPolygon();
mFloodPoint = 1;
}
else if(mFloodPoint==1)
{
System.out.println("Filling polygon");
floodFill(e.getX(),e.getY(),Color.green);
mFloodPoint = 2;
else if(mFloodPoint==2)
{
Scanner in = new Scanner(System.in);
System.out.println("Enter first corner point of clip window, width height x y h w: ");
point.X = in.nextInt(); point.Y = in.nextInt();
int h = in.nextInt();
int w = in.nextInt();
in.close();
System.out.println("Clipping polygon");
clip(w, h);
mFloodPoint = 2;
System.out.println("Clipping polygon finished");
}

11
}
else if(e.getButton() == MouseEvent.BUTTON2)
{
clearImage();
}
}
private void floodFill(int x, int y, Color fillColor)
{
Stack<Point> callStack = new Stack<>();
callStack.add(new Point(x,y));
while(!callStack.isEmpty())
{
Point point = callStack.pop();
if(isInside(point.X, point.Y))
{
if(mImage.getRGB(point.X, point.Y) != fillColor.getRGB() /*&&
mImage.getRGB(point.X, point.Y) != BOUNDARY_RGB*/)
{
mImage.setRGB(point.X, point.Y, fillColor.getRGB());
repaint();
revalidate();
callStack.add(new Point(point.X + 1, point.Y));
callStack.add(new Point(point.X - 1, point.Y));
callStack.add(new Point(point.X, point.Y + 1));
callStack.add(new Point(point.X, point.Y - 1));
}
}
}
repaint();
}

12
private void clip(int w, int h)
{
for(int i=0;i<mImage.getWidth(); i++)
{
for(int j=0;j<mImage.getHeight(); j++)
{
if((i<=point.X || i>=point.X + w) || (j<=point.Y || j>=point.Y + h))
{
mImage.setRGB(i, j, Color.black.getRGB());
}
}
}
repaint();
}@Override
public void mouseReleased(MouseEvent e)
{
}@Override
public void mouseEntered(MouseEvent e)
{
}@Override
public void mouseExited(MouseEvent e)
{
}
class Point{
int X, Y;
Point(int X, int Y)
{
this.X = X;
this.Y = Y;
}

13
}
public static void main(String[] args)
{
Application app = new Application();
JFrame jFrame = new JFrame();
jFrame.setSize(720, 480);
jFrame.setBackground(Color.BLUE);
jFrame.add(app);
jFrame.setVisible(true);
}

14
OUTPUT:-

15
RESULT:

Thus the program implementation of Sutherland Hodgeman algorithm for polygon fill and clip the
polygon is done successfully.

16
Ex.no:3
IMPLEMENTATION OF 2D AND 3D TRANSFORMATION
Date:03-09-2-19

AIM:

To write a program to implement of 2d and 3d transformation using Blender Tool.

ALGORITHM:

Step1: Install the Blender application then Install Inscape Application too.

Step2: Download circle image and open it in inscape Application and make it as .svg file.

Step3: Open Blender Import the Circle.svg file Place it in the center of the plane and also insert the
plane first then resize the circle by using shortcut ‘S’ for scaling the circle’R’ for resizing the
the image.

Step4: Set the scale in’1’ and Rotation X=90 Y&Z=0 scale=0.

Step5: Set the scale in’39’ and Rotation X=90 Y&Z=0 scale=0.

Step6: Set the scale in ‘40’ and make 2D image into 3D by extrude the image and set the key in Rotation X=90
Y&Z=0 and scale=3.

Step7: Set the scale in ‘80’ and Rotation X=180 Y&Z=0 and scale=3 then Run the open GL Animation the 2D
to 3D convertion will happen.

Step8: Now time to save the project, with .blender extension

17
OUTPUT:-
2D

3D

RESULT:
Thus the program implementation of 2D and 3D graphic transformation is done successfully.

18
Ex.no :4 ANIMATION CREATION – 1

Date:17-09-2019

AIM:

To create a program to implement the graphic animation using C programming language.


.
ALGORITHM:

Step 1: Include the necessary library functions for graphic c program.

Step 2: Declare the necessary variables.

Step 3: Create the main function, in that function to initialize graph.

Step 4: Using line, rectangle function for creating house.

Step 5: Using Ellipse function for creating cloud.

Step 6: Similarly, using line, circle function for creating man

Step 7: For making a man to walking using delay function.

Step 8: Stop the program.

19
PROGRAM:
#include<iostream.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
//using namespace std;
int main()
{
int gd=DETECT, gm;
initgraph(&gd, &gm,"C://TURBOC3/BGI");
int i,walk=0;
int c=200,d=-190;
// cloud
ellipse(40,30,60,240,10,15);
ellipse(65,20,345,165,20,15);
ellipse(105,27,340,160,20,10);
ellipse(109,42,230,50,20,10);
ellipse(66,46,163,340,31,17);
setcolor(BROWN);
bar3d(10,280,getmaxx()-50,320,10,50);
outtextxy(200,300,"road");
setcolor(WHITE);
circle(70,140,30);
circle(60,130,3);
circle(80,130,3);
line(70,135,70,145);
//line(65,155,75,155);
arc(70,140,60,120,15);
line(70,170,70,220);
line(70,170,50,220);
line(70,170,90,220);
line(70,220,55,270);
line(70,220,85,270);
setcolor(9);
fillellipse(150,100,60,40);
outtextxy(110,90,"hi," );
outtextxy(110,100,"go for a walk?");
delay(5000);
for(i=0;i<30;i++)
{
walk+=5;
cleardevice();
line(100,40,300,40);
line(100,40,50,80);
line(100,40,160,80);
line(100,80,160,80);
20
line(300,40,350,80);
line(50,80,50,200);
line(160,80,160,200);
line(50,200,160,200);
line(160,200,350,200);
line(350,80,350,200);
rectangle(200,100,230,130);
rectangle(300,100,230,130);
rectangle(90,100,120,200);
ellipse(40,30,60,240,10,15);
ellipse(65,20,345,165,20,15);
ellipse(105,27,340,160,20,10);
ellipse(109,42,230,50,20,10);
ellipse(66,46,163,340,31,17);
line(240,420,275,420);
line(240,420,245,405);
line(275,420,270,405);
line(245,405,240,405);
line(270,405,275,405);
line(240,405,245,390);
line(275,405,270,390);
line(245,390,275,390);
line(270,390,275,390);
line(240,390,258,370);
line(275,390,257,370);
line(250,460,250,420);
line(265,460,265,420);
line(250,460,265,460);
line(250,420,265,420);
line(240+c,420+d,275+c,420+d);
line(240+c,420+d,245+c,405+d);
line(275+c,420+d,270+c,405+d);
line(245+c,405+d,240+c,405+d);
line(270+c,405+d,275+c,405+d);
line(240+c,405+d,245+c,390+d);
line(275+c,405+d,270+c,390+d);
line(245+c,390+d,275+c,390+d);
line(270+c,390+d,275+c,390+d);
line(240+c,390+d,258+c,370+d);
line(275+c,390+d,257+c,370+d);
line(250+c,460+d,250+c,420+d);
line(265+c,460+d,265+c,420+d);
line(250+c,460+d,265+c,460+d);
line(250+c,420+d,265+c,420+d);
setcolor(BROWN);

21
bar3d(10,280,getmaxx()-50,320,10,50);
outtextxy(200,300,"PUDUCHERRY");
setcolor(WHITE);
circle(70+walk,140,30);
line(70+walk,170,70+walk,220);
line(70+walk,170,50+walk,220);
line(70+walk,170,90+walk,220);
line(70+walk,220,55+walk,270);
line(70+walk,220,85+walk,270);
delay(250);
walk+=5;
cleardevice();
circle(70+walk,140,30);
line(70+walk,170,70+walk,270);
setcolor(BROWN);
bar3d(10,280,getmaxx()-50,320,10,50);
outtextxy(200,300,"MG ROAD");
delay(250);
walk+=5;
cleardevice();
bar3d(10,280,getmaxx()-50,320,10,50);
outtextxy(200,300,"JN STREET");
setcolor(WHITE);
circle(70+walk,140,30);
line(70+walk,170,70+walk,220);
line(70+walk,170,60+walk,220);
line(70+walk,170,80+walk,220);
line(70+walk,220,55+walk,270);
line(70+walk,220,85+walk,270);
delay(250);
}
circle(60+walk,130,3);
circle(80+walk,130,3);
line(70+walk,135,70+walk,145);
line(65+walk,155,75+walk,155);
//arc(70,140,60,120,15);
// cloud 1
ellipse(40,30,60,240,10,15);
ellipse(65,20,345,165,20,15);
ellipse(105,27,340,160,20,10);
ellipse(109,42,230,50,20,10);
ellipse(66,46,163,340,31,17);
// cloud 2
ellipse(450,30,60,240,10,15);

22
ellipse(475,20,345,165,20,15);
ellipse(512,27,340,160,20,15);
ellipse(518,42,230,50,20,10);
ellipse(476,46,163,340,31,15);
line(240,420,275,420);
line(240,420,245,405);
line(275,420,270,405);
line(245,405,240,405);
line(270,405,275,405);
line(240,405,245,390);
line(275,405,270,390);
line(245,390,275,390);
line(270,390,275,390);
line(240,390,258,370);
line(275,390,257,370);
line(250,460,250,420);
line(265,460,265,420);
line(250,460,265,460);
line(250,420,265,420);
line(240+c,420+d,275+c,420+d);
line(240+c,420+d,245+c,405+d);
line(275+c,420+d,270+c,405+d);
line(245+c,405+d,240+c,405+d);
line(270+c,405+d,275+c,405+d);
line(240+c,405+d,245+c,390+d);
line(275+c,405+d,270+c,390+d);
line(245+c,390+d,275+c,390+d);
line(270+c,390+d,275+c,390+d);
line(240+c,390+d,258+c,370+d);
line(275+c,390+d,257+c,370+d);
line(250+c,460+d,250+c,420+d);
line(265+c,460+d,265+c,420+d);
line(250+c,460+d,265+c,460+d);
line(250+c,420+d,265+c,420+d);
setcolor(8);
fillellipse(walk-10,100,60,40);
outtextxy(walk-30,100,"REACHED...");
delay(2500);
getch();
closegraph();
return 0;
}

23
OUTPUT:

RESULT:
Thus the program implementation of person walking in the city road is done successfully.

24
Ex.no :5
ANIMATION CREATION - 2
Date:15-10-2019

AIM:

To create a man cycling animation program using C#.NET.

Procedure:
Choice of tool: Visual Studio 2010
Choice of language : C#.NET

Step1: Open visual studio and create a project file via file menu. File -> New -> Project.

Step2: create a file directory/ project directory to store your files and resource regarding for making cycling
animation.

Step3: Insert cycling animation of picture in the Picture box from tool bar on the left of project window.

Step4: Insert Timer from the tool base which will handle the motion of cycling Animation.

Step5: In timer where we used for motion graphic for the movement cycling animation.

Step6: Here we use two timer 1 for cycling animation.in Behavior check the enable is True.Increase/ decrease
the time interval for cycling animation.

Step 7: Timer 2 used for animating cycling motion where to increase/decrease interval speed for cyclic motion.

Step 8: In the event click Behavior under tick the timer 2 for animation to move the cycle.

Step 9: Picture box2. Location = new point (picture box2.Location.X+10, pictureBox2.Location y);

Step 10: The above piece code of C# move the cycling image horizontally from left to right.

Step11: The Picture box1 is used to environment view park where the cycling animation to be created for
moving animation.

25
OUTPUT:

RESULT:

Thus the program implementation of a man cycling in the park is done successfully.

26
Ex.no :6
ANIMATION CREATION - 3
Date:30-10-2019

AIM:

To create a 3D animation cartoon character using blender tool.

Procedure:

Step1: Install the Blender Application(version 2.78).open a new page and delete the cube by pressing’X’ to
Delete the selected object.

Step2: ‘Shift+S’ cursor to center and press ‘Shift+A’ select mesh option and select plane.

Step3: Select plane left mouse click subdivide number of cuts 5.

Step4: Go to properties click modifier solidify.

Step5: Select thickness0.1000.

Step6: Select Add Modifier select subdivision Surface change view=2.Select smooth in shading.

Step7: Select Material at the top Blender Render select cycle Render. Select surface principled BSDF.

Step8: Change Base color as e7a100. Select Roughness 0.300.

Step9: ‘Shift+A’ and select uv sphere press’s’to resize the image and Rotate the image R press .Take it into
Corner.Make as Material.

Step10: Shift+D to copy the same uv sphere and make it in another end.
.
Step11: Select the Middle portion of plane and the edge also.

Step12: Select the plane and group and Assign and shift the name.

Step13: Select cloth, select the pinning make end 168.

Step14: select scale location Z=1.o Rotation Z=-90 coc layout.

27
Step15: Select scale 15 location lock layout.

Step16: Select scale 60 location& rotation lock layout z=90

Step17: Select scale 80 location& rotation lock layout.

Step18: Select scale 90 location& rotation lock layout.

Step19: Select scale 120 location y=-4.5, z=2.0 Rotation x=-100,y=-25 z=-90 locrot save the file.

Step20: Particle system Type=Hair. Hair length=1.00 use modifier stack select rotation in plane.

Step21: Select material for add new and color e7bd5c Roughness=1.0.

Step22: Make it Render. Go to Render and select render animation. It take some time to complete for me it
take 7hours.

Step23: Play Render Animation ‘Ctrl+F11’ the animation runs.

28
OUTPUT:

RESULT:
Thus the program implementation of Animation Creation is done successfully.

29

You might also like