Professional Documents
Culture Documents
AIM:
To write a program to implement Midpoint algorithms for line, circle and ellipse drawing.
ALGORITHM:
Step2: Take two input coordinates(x1,y1) and (x2,y2).Calculate dx,dy and d=dy-dx/2,then draw the line.
Step3: Input radius r and center(x,y).Calculate the initial value parameter as p0=5/4-r and draw the circle using
putpixel(x+a,y+b).
}
}
3
p2=yrad*yrad*(x+0.5)*(x+0.5)+(xrad*xrad*(y-1)*(y-1))-xrad*xrad*yrad*yrad;
while(y>=0){
putpixel(x+a,y+b,RED);
putpixel(x+a,-y+b,RED);
putpixel(-x+a,-y+b,RED);
putpixel(-x+a,y+b,RED);
if(p2>0){
y-=1;
dy=2*xrad*xrad*y;
p2-=dy+xrad*xrad;
}
else{
x+=1;
y-=1;
dx+=2*yrad*yrad;
dy-=2*xrad*xrad;
p2+=dx-dy+xrad*xrad;
}
} getch();
}
void main()
{ int ch,x,y,r,x1,x2,y1,y2,a,b;
float dx,dy,xrad=100,yrad=50,d;
int gd =DETECT ,gm;
char chdraw;
initgraph(&gd,&gm,"C:\\TURBOC3\\BGI");
while(1){
clearviewport();
cout<<"1.draw line\n2.draw circle\n3.draw ellipse\n4.exit\n";
cin>>ch;
switch(ch){
Case 1: clrscr();
cout<<"Enter the coordinates of first point:";
cin>>x1>>y1;
cout<<"Enter the coordinates of second point:";
cin>>x2>>y2;
drawline(x1,y1,x2,y2);
break;
4
Case 2: clrscr();
cout<<"Enter the coordinates of center of circle:";
cin>>a>>b;
cout<<"Enter the radius of circle:";
cin>>r;
drawcircle(a,b,r);
break;
Case 3: clrscr();
cout<<"Enter the coordinates of center of ellipse:";
cin>>a>>b;
cout<<"Enter the major axis and minor axis values:";
cin>>xrad>>yrad;
drawellipse(a,b,xrad,yrad);
break;
Case 4: exit(0);
break;
Default: cout<<"\n Invalid input";
}
}
}
5
OUTPUT:-
1.Line
2. Circle
3. Ellipse
4. Exit
6
Enter the Choice:3
RESULT:
Thus the program implementation of Midpoint algorithm for line, circle and ellipse drawing is done
successfully.
7
AIM:
To create a program to implement polygon clipping and polygon filling Using flood fill algorithm.
Ex.no :2
IMPLEMENTATION OF POLYGON CLIPPING AND POLYGON FILLING
Date:13-08-2019
ALGORITHM:
Step 3: Create a function to get the line co-ordinates and window co-ordinate values.
Step 4: Fill the polygon using flood fill algorithm,flood fill(x,y,new color,old color)
Step 5: Check all the co-ordinates of the lines are within the window co-ordinate or
not.
Step 6: Clip the lines which are all outside of the window co-ordinates using Sutherland- Holygon polygon
clipping algortthm.
Step 7: After the clipping draw all the lines along with the window.
8
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.*;
graphics2D.setBackground(Color.black);
graphics2D.clearRect(0,0,WIDTH,HEIGHT);
repaint();
revalidate();
9
Application(){
mFloodPoint = 0;
addMouseListener(this);
}@Override
super.paintComponent(g);
graphics2D.setBackground(Color.black);
g.drawImage(mImage,0,0,this);
}@Override
return true;
return false;
int i,j;
for (i = 0, j = mVertices.size()- 1; i < mVertices.size(); j = i++) {
10
(mVertices.get(j).Y-mVertices.get(i).Y) + mVertices.get(i).X))
result = !result;
return result;
graphics2D.setColor(BLUE);
graphics2D.drawLine(current.X,current.Y,next.X, next.Y);
graphics2D.drawLine(first.X,first.Y,last.X,last.Y);
repaint();
revalidate();
11
if(e.getButton() == MouseEvent.BUTTON1) {
mVertices.add(new Point(e.getX(),e.getY()));
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){
int h = in.nextInt();
int w = in.nextInt();
in.close();
System.out.println("Clipping polygon");
clip(w, h);
12
clearImage();
callStack.add(new Point(x,y));
while(!callStack.isEmpty()) {
if(isInside(point.X, point.Y)) {
repaint();
revalidate();
}
}
13
repaint();
mImage.setRGB(i, j, Color.black.getRGB());
repaint();
}@Override
@Override
@Override
class Point{
int X, Y;
this.X = X;
this.Y = Y;
}
}
14
jFrame.setSize(720, 480);
jFrame.setBackground(Color.BLUE);
jFrame.add(app);
jFrame.setVisible(true);
}
15
OUTPUT:-
16
RESULT:
Thus the program implementation of Sutherland Hodgeman algorithm for polygon fill and clip the
polygon is done successfully.
17
Ex.no:3
IMPLEMENTATION OF 2D AND 3D TRANSFORMATION
Date:03-09-2-19
AIM:
ALGORITHM:
Step3: Insert models of a helicopter model for 2d transformation and Rectangle,Cone and cubic surface for 3d
Step4: Open video stream and apply scale,rotation and drag transformations with the specified time locations .
Step5: Set fixed value for scaling,rotation,drag and X,Y co-ordinates and set Z=0 for 2d transformation.
Step6: Set fixed value for scaling,rotation,drag and X,Y,Z co-ordinates for 3d transformation.
18
OUTPUT:-
2D
3D
RESULT:
Thus the program implementation of 2D and 3D graphic transformation is done successfully.
19
Ex.no :4 ANIMATION CREATION – 1
Date:17-09-2019
AIM:
PROGRAM:
#include<stdio.h>
#include<graphics.h>
int ldisp=0;
void Rain(int x)
{
int i,rx,ry;
for(i=0;i<400;i++)
{
rx=rand() % ScreenWidth;
ry=rand() % ScreenHeight;
if(ry<GroundY-4)
{
//if(ry<GroundY-120 || (ry>GroundY-120 && (rx<x-20 || rx>x+60)))
line(rx,ry,rx+0.5,ry+4);
}
}
}
void main()
{
int gd=DETECT,gm,x=0;
//Change BGI directory according to yours
initgraph(&gd,&gm,"C:\\TurboC3\\BGI");
while(!kbhit())
{
//Draw Ground
line(0,GroundY,ScreenWidth,GroundY);
//Rain(x);
ldisp=(ldisp+2)%20;
DrawManAndUmbrella(x,ldisp);
delay(75);
cleardevice();
x=(x+2)%ScreenWidth;
}
getch();
}
22
OUTPUT:
RESULT:
Thus the program implementation of person walking in the city road is done successfully.
23
Ex.no :5
ANIMATION CREATION - 2
Date:15-10-2019
AIM:
PROCEDURE:
Choice of language : java
Step 1: Include the necessary library functions for graphic java program.
Step 3: Create the main function, in that function include the paint() method.
import javax.swing.*;
import java.awt.*;
import java.util.concurrent.TimeUnit;
public class MoveImages extends JFrame {
private int frameWidth = 700, frameHeight = 500;
private Image image = new ImageIcon("/home/ubais/PycharmProjects/minipro3/Car
Images/park11.jpg").getImage();
private Image image1 = new ImageIcon("/home/ubais/Desktop/cycle.gif").getImage();
public MoveImages() {
setBounds(100, 100, frameWidth, frameHeight);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
g.drawImage(image, 0,0,getWidth(),getHeight(),this);
//image = resize(image1,500,500);
for(int i=0;i<=getWidth();i++)
{
g.drawImage(image, 0,0,getWidth(),getHeight(),this);
g.drawImage(image1, i,300,100,100,this);
try
{
Thread.sleep(10);
}
catch(InterruptedException ex)
{
Thread.currentThread().interrupt();
}
}
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
PROCEDURE:
Building a Adventurer
Step1 : Open the blender software for deleting the default cube by Alt + X.
Step 2: for adding press shift + A to add UV sphere.
Step 3: for recompress the UV sphere.
Step 4: Add duplicate of the UV sphere to place the body for the Adventure.
Step 5: Repeat the step for creating face.
Step 6: To move the mirror to place a eye.
Step 7: Repeat to create another eye.
Step 8: Press Shift + A to add cone to create a nose like structure.
Step 9: Press S to resize the cone.
Step 10: Add cylinder to create hat like structure
Step 11: Repeat the step to create a hat and make duplicate by press Shift + D.
OUTPUT: