Implementation of Circle, Line and Ellipse Drawing Algorithm
Implementation of Circle, Line and Ellipse Drawing Algorithm
PROCEDURE:
1. Input radius r and circle center(x,y) and obtain the first point in the
circumference of a circle centered on the origin as (X0, Y0)= (0, r).
3. At each xk position, starting at k=0, perform the following nest. if pk<0, the
next point along the circle centered as (0,0) is (xk+1,yk) and
pk+1=pk+2xk+1+1 otherwise next point along the circle is (xk+1,yk-1) and
pk+1=pk+2xk+1+1-2yk+1 where 2xk+1=2xk+2 and 2yk+1=2yk-2.
7. Input the two line end points and store the left endpoint in (x0,y0).
8. Load (x0,y0) into the frame buffer, that is plot the first point.×
9. Calculate constants and obtain the starting value for the decision parameter.
10. At each x 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
pot is (xk+1,yk+1) and pk+1=pk+2y-2x.
12. Input xy and ellipse center(xc,yc) and obtain the first point on an ellipse
centered on the origin as (x0,y0)=(0,ry)
13. Calculate the initial value of the decision parameter in region, as p0=x2y-
r2x ry+1/4r2x
14. At each xk position in region1, starting at k=0, perform the following test if
pk<0, the next point along the ellipse centered on(0,0) is(xk+1,yk) and
Pk+1=pk+2r2yxk+1+r2y Otherwise, the next point along the circle is (xk+1, yk-
1) .
15. Calculate the initial value of the decision parameter in region 2 using the
last point(x0,y0) calculated in region1.
16. At each yk position in region2, stating at k=0, perform the following test.tff
p2k>0, the next point along the ellipse centered on(0,0) is(xk,yk-1).
18. Move each calculated pixel position(x,y) Onto the elliptical path centered
on(xc,yc) and plot the co-ordinated values:
X=x+xc
Yy=y+yc
PROGRAM CODING:
#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, "C:\\TURBOC3\\BGI");
do
3
{
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("\n Enter 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();
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);
4
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
{
q=q+(4*(m-n))+10;
n--;
}
m++;
}
if(m==n)
5
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( );
6
OUTPUT:
Line drawing
Circle drawing
ellipse drawing
RESULT:
Thus the program is executed successfully and the output has been
verified.
7
AIM:
To write a program to implement a polygon fill and clip the polygon.
PROCEDURE:
2. Reassign the pixel values that are currently set to given interior color with the
desire fill color.
5. A convex polygon and a convex clipping area are given. The task is to clip
polygon in clock wise order clip given polygon against e.
6. Input is in the form of vertices of the polygon in clock wise order. Clip given
polygon against e.
7. The edge of clipping area is extended infinitely to create a boundary and all
the vertices are clipped using the boundary. The new list of vertices generated is
passed to the next edge of the clip polygon in clock wise until all the edges have
been used.
8. There are for possible cases for any given edge given polygon against current
clipping edge.
9. Both vertices are inside only the second vertex is added to the output list
10. First vertex is outside while second one is inside both the point of
intersection of the edge with the clip boundary and the second vertex are added
to the output list.
11. First vertex is inside while second one is outside only the point of
intersection of the edge with the clip boundary is added to the output list.
12. Both vertices are outside no vertices are added to the output list.
8
13. There are two subproblems that need to be discussed before implementing
the algorithm.
15. If the vertices of the clipper polygon are given in clockwise order then all
the points lying on the right side of the clipper edges are inside that polygon.
18. If two points of each line (1,2,3,4) are known then their point of intersection
can be calculated using formula.
PROGRAM CODING:
import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.image.BufferedImage;
import java.util.*;
Application(){
mImage = new BufferedImage(WIDTH,
HEIGHT,BufferedImage.TYPE_3BYTE_BGR);
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) /
(mVertices.get(j).Y-mVertices.get(i).Y) + mVertices.get(i).X))
{
result = !result;
}
}
return result;
10
}
private void drawPolygon() {
if(mVertices.size() >= 3){
int totalVertices = mVertices.size();
Graphics2D graphics2D = mImage.createGraphics();
graphics2D.setColor(RED);
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) {
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);
11
}
repaint();
}
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;
}
}
public static void main(String[] args) {
Application app = new Application();
JFrame jFrame = new JFrame();
jFrame.setSize(720, 480);
jFrame.setBackground(Color.BLUE);
13
jFrame.add(app);
jFrame.setVisible(true);
}
}
OUTPUT:
Javac polygon2.java
Java polygon
Adding point: 142 170,236 70,344 73,449 182,442 257,292 290,163 216
Drawing polygon
Filling polygon
14
Clipping polygon
RESULT:
AIM:
PROCEDURE:
3D ANIMATION
1. Install blender application(version 2.78) open a new page and delete the cube
by pressing ‘x’ to delete the selected object or insert in that object itself.
3. The monkey will appear in the screen and then press ‘Z’ to hide the box and
numpad1 for ‘front’ view and numpad5 for pers/ortho view.
4. And then press “ctrl+three” for the select of the object and goto tools and
addmodifier and shrinkwrap.
5. Press “shift+D” to display the two objects for the edit mode.
8. Atlast goto toggle edit mode and select “numpad slash” and press “z” and
press “A”.
9. Enable the edit mode and press “G” to select the object and stretch the object.
10. Press “B” to make it as a perfect cube a nd press “B*2”.Select and make it
as a perfect cube.
11. And press “numpad slash” to view the object and press tab to select the
object.
12. Press shift key+right click to select the both the objects.
14. Now we can increase and decrease the value by changing the shapes.
17
15. And now finally the output comes. The cube is converted to monkey by
morphing.
2D-ANIMATION
18. Select another frame and select the object by pressing G and move the
object to appropriate position.
OUTPUT:
3D ANIMATION
18
2D ANIMATION
RESULT:
Thus the program is executed successfully and the output has been
verified.
19
AIM:
PROCEDURE:
CREATING MAN
1. For creating man we should measure a pixel rate on creating a man head with
three points.
2. Enter the leg and hand length using graphic line with three length
CREATING HOUSE
7. In these we use two clouds scenery animation measure the pixel point and
ellipse creating with different co-ordinates.
8. For right cloud measure the animation on scenery measure the ellipse with
five coordinates.
CREATING MOON
9. Hence we create a cycle using lines scenery animation measure the pixel
point and lines and ellipse creating with different co-ordinates.
20
PROGRAM CODING:
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
void main()
int gdriver=DETECT,gmode,i;
int x1=100,t1=x1-30,t2=x1+30;
int a1=t1,a2=t2;
initgraph(&gdriver,&gmode,"c:\\turboC3\\BGI");
//road
line(10,401,630,401);
//wheels
circle(40,370,30);
circle(150,370,30);
line(40,370,100,370);
line(40,370,60,340);
line(100,370,120,340);
line(120,340,60,340);
line(60,340,60,335);
line(55,335,65,335);
line(150,370,100,320);
21
line(100,320,90,320);
//
for(i=0;i<30;i++)
for(;t1<x1+30&&t2>x1-30;t1++,x1++,t2--)
delay(50);
clrscr();
line(0,310,1366,310);
circle(x1,100,30);
line(
x1,130,x1,220);
line(x1,150,a1=a1+5,200);
line(x1,150,a2=a2-3,200);
line(x1,220,t1=t1+4,310);
line(x1,220,t2=t2-2,310);
t1=x1-30;t2=x1+30;a1=t1;a2=t2;
getch();
22
OUTPUT:
RESULT:
Thus the program is executed successfully and the output has been
verified.
23
AIM:
PROCEDURE:
5. Select the image by right click the arrow button of the picturebox and choose
image from local folder.
6. Load the picturebox, run the file by click the run button.
7. Add the size of the image to stretch the image like PictureBox1.SizeMode =
PictureBoxSizeMode.StretchImage.
Timer1.Interval = 500
PictureBox1.Left = PictureBox1.Left + 10
PROGRAM CODING:
PictureBox1.Image = Image.FromFile("d:\summer-city-park-with-street-
lights_1262-16617.jpg")
PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
End Sub
PictureBox2.Image = Image.FromFile("d:\IgnorantMintyAlbatross-
size_restricted.gif")
PictureBox2.SizeMode = PictureBoxSizeMode.StretchImage
End Sub
End Sub
End Sub
Timer1.Interval = 500
PictureBox1.Left = PictureBox1.Left + 10
25
Else
Timer1.Enabled = False
End If
End Sub
End Class
OUTPUT:
RESULT:
Thus the program is executed successfully and the output has been
verified.
Experiment 6
26
AIM:
PROCEDURE:
1. In html code , select all the items to create the image using the tools and tags
used in the html code.
2. Type the tag <html> code and insert all the tags inside the html code.
3. Load the animation by run the code using the chrome browser.
4. To run the code right click and run the code by using chrome tab.
5. To run this save as give file name and save as .html code.
PROGRAM CODING:
<HTML>
<head>
<title>Minions CSS</title>
<link href="style.css" rel="stylesheet" type="text/css" media="screen" />
</head>
<body>
<div class="container">
<h1> </h1>
<h6> <a href="www.amrzek.com"></a></h6>
<div class="bill">
<div class="lights">
<span class="white_light"></span>
27
<span class="dark_light"></span>
</div>
<div class="hair">
<span class="hair1"></span>
<span class="hair1
make_it_left_hair1"></span>
<span class="hair2"></span>
</div>
<div class="eyes">
<div class="eye_animate"></div>
<div class="glasses"></div>
<div class="white_part">
<div class="brown_eye">
<spanclass="black_part"></span>
</div>
</div>
</div>
<div class="black_tie">
<span class="right_tie">
<div class="top_tie"></div>
<div class="down_tie"></div>
</span>
<span class="left_tie">
<div class="top_tie"></div>
<div class="down_tie"></div>
</span>
</div>
28
<div class="smile"></div>
<div class="arm"></div>
<div class="hand"><span
class="hand_parts"><span></div>
<div class="shoes"><span
class="small_shoes"></span></div>
<div class="shoes make_it_left_shoes"><span
class="small_shoes"></span></div>
</div>
<h2>Bill</h2>
</div>
<div class="jerry">
<div class="lights">
<span class="white_light"></span>
<span class="dark_light"></span>
</div>
<div class="jerry_hair">
<ul>
<li class="h1"></li>
<li class="h2"></li>
<li class="h3"></li>
<li class="h4"></li>
<li class="h5"></li>
<li class="h6"></li>
<li class="h7"></li>
<li class="h8"></li>
<li class="h9"></li>
<li class="h10"></li>
<li class="h11"></li>
<li class="h12"></li>
</ul>
30
</div>
<div class="eyes1">
<div class="eye_animate"></div>
<div class="glasses"></div>
<div class="white_part">
<div class="brown_eye">
<span
class="black_part"></span>
</div>
</div>
</div>
<div class="eyes2">
<div class="eye_animate"></div>
<div class="glasses"></div>
<div class="white_part">
<div class="brown_eye">
<span
class="black_part"></span>
</div>
</div>
</div>
<div class="jerry_hand">
<div class="jerry_lh"></div>
<div class="animated_lh">
<span class="gloves_lh"></span>
<span class="gloves_lh2"></span>
31
</div>
<div class="jerry_rh"></div>
<span class="gloves_rh"></span>
</div>
<div class="black_tie">
<span class="right_tie">
<div class="top_tie"></div>
<div class="down_tie"></div>
</span>
<span class="left_tie">
<div class="top_tie"></div>
<div class="down_tie"></div>
</span>
</div>
<div class="jerry_smile">
<span class="teeth1"></span>
<span class="teeth2"></span>
</div>
<div class="curves">
<span class="jerry_curve1"></span>
<span class="jerry_curve1
jerry_left_curve"></span>
<span class="jerry_curve2"></span>
</div>
<div class="clothes">
<div class="main_jerry"></div>
32
<div class="right_shirt
jerry_right_shirt"></div>
<div class="right_shirt jerry_left_shirt"></div>
<div class="jerry_bottom"></div>
</div>
<div class="pocket">
<div class="logo"></div>
<span class="lines"></span>
</div>
<div class="legs">
<div class="jerry_shoes"><span
class="jerry_small_shoes"></span></div>
<div class="jerry_shoes
jerry_left_shoes"><span class="jerry_small_shoes"></span></div>
</div>
<h2>Jerry</h2></div>
<div class="evil">
<ul class="evil_hair">
<li class="eh1"></li>
<li class="eh2"></li>
<li class="eh3"></li>
<li class="eh4"></li>
<li class="eh5"></li>
</ul>
<div class="eyes">
<div class="eye_animate"></div>
<div class="glasses"></div>
<div class="white_part">
33
<div class="brown_eye">
<span
class="black_part"></span>
</div>
</div>
</div>
<div class="black_tie">
<span class="right_tie">
<div class="top_tie"></div>
<div class="down_tie"></div>
</span>
<span class="left_tie">
<div class="top_tie"></div>
<div class="down_tie"></div>
</span>
</div>
<div class="evil_mouth">
<span class="evil_teeth"></span>
<span class="evil_teeth1"></span>
</div>
<div class="clothes">
<div class="right_shirt evil_right_shirt"></div>
<div class="right_shirt evil_left_shirt"></div>
<div class="evil_bottom"></div>
<div class="evil_logo"><p>M</p></div>
</div>
<div class="legs">
34
<div class="evil_right_leg"></div>
<div class="evil_right_leg
evil_left_leg"></div>
<div class="shoes evil_right_shoes"><span
class="small_shoes"></span></div>
<div class="shoes evil_left_shoes"><span
class="small_shoes"></span></div>
</div>
<div class="evil_hand">
<div class="evil_rh">
<span class="evil_gloves_rh"></span>
</div>
<div class="evil_lh">
<span class="evil_gloves_lh"></span>
</div>
</div>
<h2>Evil</h2>
</div>
</div>
</body>
</HTML>
35
OUTPUT:
RESULT:
Thus the program is executed successfully and the output has been
verified.