Showing posts with label COMPUTER GRAPHICS. Show all posts
Showing posts with label COMPUTER GRAPHICS. Show all posts

Tuesday, October 29, 2013

IMPLEMENTATION OF BRESNHAM LINE DRAWING ALGORITHM IN JAVA

/*
DATE:29TH JULY 2013
TITLE:IMPLEMENTATION OF BRESNHAM LINE DRAWING ALGORITHM IN JAVA
*/

import java.applet.*;
import java.awt.*;
import java.util.*;

public class bresnham extends Applet
{
    double x1,y1,x2,y2;
    double dx,dy,steps,x,y,k;

    Scanner sc=new Scanner(System.in);
    double xc,yc;
   
    public bresnham(){
    System.out.println("ENTER X1 Y1");
    x1=sc.nextDouble();
    y1=sc.nextDouble();
    System.out.println("ENTER X2 Y2");
    x2=sc.nextDouble();
    y2=sc.nextDouble();
    }
  
    public void paint(Graphics g)
    {
    int ch=6;
            dx=Math.abs(x2-x1);
        dy=Math.abs(y2-y1);
        x=x1;
        y=y1;
        double e=(2*dy)-(dx);
        int i=1;
        //THIS PROGRAM IS CODED BY TG6483
        one: for(int j=10;ch==6;j++)
        {
            g.fillOval((int)x,(int)y,5,5);
            while(e>=0)
            {
                y=y+1;
                e=e-(2*dx);
            }
            x=x+1;
            e=e+(2*dy);
            i++;
            if(i<=dx)
            ch=6;
            else
            break one;
        }
    }
}
/*<applet code="bresnham.class" width="1000" height="1000">
 </applet>*/
 /*
 OUTPUT:
 bash-3.00$ appletviewer bresnham.java
ENTER X1 Y1
500
200
ENTER X2 Y2
200
600
*/


Saturday, October 26, 2013

SUTHERLAND HODGEMAN POLYGON CLIPPING ALGORITHM IN JAVA

/*
TOPIC: SUTHERLAND HODGEMAN POLYGON CLIPPING
*/

import java.awt.*;
import java.applet.*;
import java.math.*;
import java.io.*;
import java.util.*;

public class Polyclip extends Applet
{

Scanner d=new Scanner(System.in);
public void paint(Graphics g)
{
int a[];
int b[];
int k=0;
System.out.println("Enter no. of points ");
int n=d.nextInt();
a=new int[n];
b=new int[n];
for(int i=0;i<n;i++)
{
System.out.println("Enter value of x : ");
a[i]=d.nextInt();
System.out.println("Enter value of y : ");
b[i]=d.nextInt();
}
g.drawPolygon(a,b,n);

System.out.println("Enter value of x(min) : ");
int xmn=d.nextInt();
System.out.println("Enter value of y(min) : ");
int ymn=d.nextInt();
System.out.println("Enter value of x(max) : ");
int xmx=d.nextInt();
System.out.println("Enter value of y(max) : ");
int ymx=d.nextInt();

g.drawLine(xmn,ymn,xmx,ymn);
g.drawLine(xmn,ymx,xmx,ymx);
g.drawLine(xmn,ymn,xmn,ymx);
g.drawLine(xmx,ymn,xmx,ymx);

for(int i=0;i<4;i++)
{
if(b[i]>ymx)
{
int temp=b[i];
b[i]=ymx;
a[i]= a[i] +(((a[i+1]-a[i])/(b[i+1]-temp))*(b[i]-temp));
}
else if(b[i]<ymn)
{
int temp=b[i];
b[i]=ymn;
a[i]= a[i] +(((a[i+1]-a[i])/(b[i+1]-temp))*(b[i]-temp));

 }
else if(a[i]>xmx)
{
 int temp=a[i];
 a[i]=xmx;
 b[i]=b[i]+(((b[i+1]-b[i])/(a[i+1]-a[i]))*(a[i]-temp));
}
else if(a[i]<xmn)
{
 if(a[i]==a[i+1])
 {
 k=a[0];
a[i]=xmn;
b[i]=b[i];
 }
else  if(a[i+1]<xmn)
  {
   a[i]=xmn;
b[i]=ymx;
}
 else
{
int temp=a[i];
 a[i]=xmn;
 b[i]=b[i]+(((b[i+1]-b[i])/(a[i+1]-a[i]))*(a[i]-temp));
 }
}
 }
if(b[n-1]>ymx)
{
int temp=b[n-1];
b[n-1]=ymx;
a[n-1]= a[n-1]+(((a[0]-a[n-1])/(b[0]-temp))*(b[n-1]-temp));
}
else if(b[n-1]<ymn)
{
int temp=b[n-1];
b[n-1]=ymn;
a[n-1]= a[n-1] +(((a[0]-a[n-1])/(b[0]-temp))*(b[n-1]-temp));

 }
else if(a[n-1]>xmx)
{
 int temp=a[n-1];
 a[n-1]=xmx;
 b[n-1]=b[n-1]+(((b[0]-b[n-1])/(a[0]-a[n-1]))*(a[n-1]-temp));
}
else if(a[n-1]<xmn)
{
 if(a[n-1]==a[0])
 {
 int temp=a[n-1];
a[n-1]=xmn;
b[n-1]=ymn;
 }
else if(a[0]<xmn)
  {
   a[n-1]=xmn;
   b[n-1]=ymx;
}
 else
{
 int temp=a[n-1];
 a[n-1]=xmn;
 b[n-1]=b[n-1]+(((b[0]-b[n-1])/(k-a[n-1]))*(a[n-1]-temp));
 }
 }

for(int i=0;i<n;i++)
{
a[i]=a[i]+400;
b[i]=b[i]+400;
}
g.drawPolygon(a,b,n);
ymn+=400;
ymx+=400;


xmn+=400;
xmx+=400;


g.drawLine(xmn,ymn,xmx,ymn);
g.drawLine(xmn,ymx,xmx,ymx);
g.drawLine(xmn,ymn,xmn,ymx);
g.drawLine(xmx,ymn,xmx,ymx);

}
}

/*
<applet code="Polyclip.class" width="1000" height="1000">
</applet>
*/

LIYAN BASKY LINE CLIPPING ALGORITHM IN JAVA

/*
Topic-LIYAN BASKY LINE CLIPPING ALGORITHM IN JAVA
*/
import java.awt.*;
import java.applet.*;
import java.math.*;
import java.io.*;
import java.util.*;

public class LB extends Applet
{
Scanner d=new Scanner(System.in);
 public void paint(Graphics g)
 {
  System.out.println("enter value of xmin");
  int xmin=d.nextInt();
   System.out.println("enter value of ymin");
  int ymin=d.nextInt();
  System.out.println("enter value of xmax");
  int xmax=d.nextInt();
  System.out.println("enter value of ymax");
  int ymax=d.nextInt();
  int p[]=new int[4];
  int q[]=new int[4];
  System.out.println("enter value of x1");
  int x1=d.nextInt();
System.out.println("enter value of y1");
  int y1=d.nextInt();
  System.out.println("enter value of x2");
  int x2=d.nextInt();
  System.out.println("enter value of y2");
  int y2=d.nextInt();
  g.drawLine(xmin,ymin,xmin,ymax);
  g.drawLine(xmin,ymax,xmax,ymax);
  g.drawLine(xmax,ymax,xmax,ymin);
  g.drawLine(xmax,ymin,xmin,ymin);
  g.drawLine(x1,y1,x2,y2);
  p[0]=-(x2-x1);
  p[1]=x2-x1;
  p[2]=-(y2-y1);
  p[3]=y2-y1;
  q[0]=x1-xmin;
  q[1]=xmax-x1;
  q[2]=y1-ymin;
  q[3]=ymax-y1;
  float t1=0,t2=1;
  int flag=0;
  for(int i=0;i<4;i++)
  {
   if(p[i]==0)
   {
    if(q[i]>=0)
    {
     if(i<2)
     {
      if(y1<ymin)
       y1=ymin;
      if(y2>ymax)
       y2=ymax;
     }
     if(i>1)
     {
      if(x1<xmin)
      x1=xmin;
      if(x2>xmax)
      x2=xmax;
     }
     flag=1;
     g.drawLine(x1,y1,x2,y2);
    }
   }
  }
  if(flag==0)
  {
   for(int i=0;i<4;i++)
   {
    float t=(float)q[i]/(float)p[i];
    if(p[i]<0)
    {
     if(t1<t)
     t1=t;
    }
    else
    {
     if(t2>t)
     t2=t;
    }
   }
  if(t1<t2)
  {
   int xx1=(int)(x1+t1*p[1]);
   int xx2=(int)(x1+t2*p[1]);
   int yy1=(int)(y1+t1*p[3]);
   int yy2=(int)(y1+t2*p[3]);
  xmin =xmin + 200;
   ymin =ymin + 400;
  xmax =xmax + 200;
  ymax =ymax + 400;
   xx1 =xx1 + 200;
   xx2 =xx2 + 200;
   yy1 =yy1 + 400;
   yy2 =yy2 + 400;
    g.drawLine(xmin,ymin,xmin,ymax);
  g.drawLine(xmin,ymax,xmax,ymax);
  g.drawLine(xmax,ymax,xmax,ymin);
  g.drawLine(xmax,ymin,xmin,ymin);
  g.drawLine(xx1,yy1,xx2,yy2);
  }
  }
 }
}
/*
<applet code="LB.class" width=700 height=700>
</applet>
*/



TO IMPLEMENT CHARACTER GENERATION IN JAVA

/*
TOPIC:TO IMPLEMENT CHARACTER GENERATION IN JAVA
WRITE A PROGRAM TO GENERATE INDIA
*/
import java.awt.*;
import java.util.*;
import java.applet.*;

public class Chargen extends Applet
{
  public void paint(Graphics g)
  {

int d[][] = {

 { 0, 0, 0, 0, 1, 0, 0, 0, 0},

 { 0, 0, 0, 0, 1, 0, 0, 0, 0},

 { 0, 0,0 , 0, 1, 0,0 , 0, 0},

 { 0, 0, 0, 0, 1, 0, 0, 0, 0},

 { 0, 0, 0, 0, 1, 0, 0, 0, 0},

 { 0, 0, 0, 0, 1, 0, 0, 0, 0},

 { 0, 0, 0, 0, 1, 0, 0, 0, 0},

 { 0, 0, 0, 0, 1, 0, 0, 0, 0},

 { 0, 0, 0, 0, 1, 0, 0, 0, 0},

 { 0, 0, 0, 0, 1, 0, 0, 0, 0},

 { 0, 0, 0, 0, 1, 0, 0, 0, 0},

 { 0, 0, 0, 0, 1, 0, 0, 0, 0},

 { 0, 0, 0, 0, 1, 0, 0, 0, 0},

      };

for(int P=0;P<13;P++)
 {
   for(int W=0;W<9;W++)
   {
   if(d[P][W]==1)
    {
    g.fillOval(200+(15*W),200+(15*P),5,5);
    }
   else
    continue;
   }
  }

int e[][] = {

 { 0, 1, 0, 0, 0, 0, 0, 1, 0},

 { 0, 1, 1, 0, 0, 0, 0, 1, 0},

 { 0, 1, 1, 0, 0, 0, 0, 1, 0},

 { 0, 1, 0, 1, 0, 0, 0, 1, 0},

 { 0, 1, 0, 0, 0, 0, 0, 1, 0},

 { 0, 1, 0, 0, 1, 0, 0, 1, 0},

 { 0, 1, 0, 0, 0, 0, 0, 1, 0},

 { 0, 1, 0, 0, 0, 1, 0, 1, 0},

 { 0, 1, 0, 0, 0, 0, 0, 1, 0},

 { 0, 1, 0, 0, 0, 0, 1, 1, 0},

 { 0, 1, 0, 0, 0, 0, 0, 1, 0},

 { 0, 1, 0, 0, 0, 0, 1, 1, 0},

 { 0, 1, 0, 0, 0, 0, 0, 1, 0},

      };

for(int q=0;q<13;q++)
 {
   for(int x=0;x<9;x++)
   {
   if(e[q][x]==1)
    {
    g.fillOval(300+(15*x),200+(15*q),5,5);
    }
   else
    continue;
   }
  }


   int b[][] = {

 { 1, 1, 1, 1, 1, 1, 1, 1, 0},

 { 0, 1, 0, 0, 0, 0, 0, 1, 0},

 { 0, 1, 0, 0, 0, 0, 0, 1, 0},

 { 0, 1, 0, 0, 0, 0, 0, 1, 0},

 { 0, 1, 0, 0, 0, 0, 0, 1, 0},

 { 0, 1, 0, 0, 0, 0, 0, 1, 0},

 { 0, 1, 0, 0, 0, 0, 0, 1, 0},

 { 0, 1, 0, 0, 0, 0, 0, 1, 0},

 { 0, 1, 0, 0, 0, 0, 0, 1, 0},

 { 0, 1, 0, 0, 0, 0, 0, 1, 0},

 { 0, 1, 0, 0, 0, 0, 0, 1, 0},

 { 0, 1, 0, 0, 0, 0, 0, 1, 0},

 { 1, 1, 1, 1, 1, 1, 1, 1, 0},

      };

for(int k=0;k<13;k++)
 {
   for(int n=0;n<9;n++)
   {
   if(b[k][n]==1)
    {
    g.fillOval(450+(15*n),200+(15*k),5,5);
    }
   else
    continue;
   }
  }

 int c[][] = {

 { 0, 0, 0, 0, 1, 0, 0, 0, 0},

 { 0, 0, 0, 0, 1, 0, 0, 0, 0},

 { 0, 0,0 , 0, 1, 0,0 , 0, 0},

 { 0, 0, 0, 0, 1, 0, 0, 0, 0},

 { 0, 0, 0, 0, 1, 0, 0, 0, 0},

 { 0, 0, 0, 0, 1, 0, 0, 0, 0},

 { 0, 0, 0, 0, 1, 0, 0, 0, 0},

 { 0, 0, 0, 0, 1, 0, 0, 0, 0},

 { 0, 0, 0, 0, 1, 0, 0, 0, 0},

 { 0, 0, 0, 0, 1, 0, 0, 0, 0},

 { 0, 0, 0, 0, 1, 0, 0, 0, 0},

 { 0, 0, 0, 0, 1, 0, 0, 0, 0},

 { 0, 0, 0, 0, 1, 0, 0, 0, 0},

      };

for(int l=0;l<13;l++)
 {
   for(int o=0;o<9;o++)
   {
   if(c[l][o]==1)
    {
    g.fillOval(550+(15*o),200+(15*l),5,5);
    }
   else
    continue;
   }
  }
int a[][] = {

 { 0, 0, 0, 0, 1, 0, 0, 0, 0},

 { 0, 0, 0, 1, 0, 1, 0, 0, 0},

 { 0, 0, 1, 0, 0, 0, 1, 0, 0},

 { 0, 1, 0, 0, 0, 0, 0, 1, 0},

 { 0, 1, 0, 0, 0, 0, 0, 1, 0},

 { 0, 1, 0, 0, 0, 0, 0, 1, 0},

 { 0, 1, 1, 1, 1, 1, 1, 1, 0},

 { 0, 1, 0, 0, 0, 0, 0, 1, 0},

 { 0, 1, 0, 0, 0, 0, 0, 1, 0},

 { 0, 1, 0, 0, 0, 0, 0, 1, 0},

 { 0, 1, 0, 0, 0, 0, 0, 1, 0},

 { 0, 1, 0, 0, 0, 0, 0, 1, 0},

 { 0, 1, 0, 0, 0, 0, 0, 1, 0},

      };

for(int j=0;j<13;j++)
 {
   for(int m=0;m<9;m++)
   {
   if(a[j][m]==1)
    {
    g.fillOval(650+(15*m),200+(15*j),5,5);
    }
   else
    continue;
   }
  }

 }
}

/*
<applet code="Chargen.class" width="2000" height="2000">
</applet>
*/

TO IMPLEMENT BEIZER CURVE IN JAVA

/*
TOPIC:TO IMPLEMENT BEIZER CURVE IN JAVA
*/
import java.awt.*;
import java.lang.*;
import java.util.*;
import java.applet.*;

public class Beizer extends Applet
{
  public void paint(Graphics g)
  {
    Scanner s=new Scanner(System.in);
int i;
int temp1,temp2;

int c[][]=new int[4][2];

for(i=0;i<4;i++)
{
 System.out.println("Enter x coordinate of point");
 c[i][0]=s.nextInt();
 c[i][0]=100*c[i][0];
 System.out.println("Enter y coordinate of point");
 c[i][1]=s.nextInt();
 c[i][1]=100*c[i][1];
}
for(int m=0;m<3;m++)
{
 g.drawLine(c[m][0],c[m][1],c[m+1][0],c[m+1][1]);
}

int a[] = new int [52];
int b[] = new int [52];

int j=0;
double u=0;

try{
do
{
double d = (((1-u)*(1-u)*(1-u))*c[0][0]) + ((3*u)*(1-u)*(1-u)*c[1][0]) + ((3*u*u)*(1-u)*c[2][0]) + (u*u*u*c[3][0]);
double e = (((1-u)*(1-u)*(1-u))*c[0][1]) + ((3*u)*(1-u)*(1-u)*c[1][1]) + ((3*u*u)*(1-u)*c[2][1]) + (u*u*u*c[3][1]);
a[j] = (int)Math.round(d);
b[j] = (int)Math.round(e);
u=u +.02;
j=j+1;

}while(u!=1);
}
catch(Exception e){}
for(int k=0;k<51;k++)
 {
  g.setColor(Color.red);
  g.drawLine(a[k],b[k],a[k+1],b[k+1]);
}
 }
}
/*
<applet code="Beizer.class" width="1000" height="1000">
</applet>
*/

COHEN-SUTHERLAND LINE CLIPPING ALGORITHM IN JAVA

/*
COHEN-SUTHERLAND ALGORITHM
*/
import java.applet.*;
import java.awt.*;
import java.util.*;
public class CohenS extends Applet
{
    Scanner sc=new Scanner(System.in);
            int xmax,ymax,xmin,ymin;
            public int[] set(int x,int y)
            {
                        int a[]=new int[4];
                        if(x<xmin)
                                    a[3]=1;
                        else
                                    a[3]=0;
                        if(x>xmax)
                                    a[2]=1;
                        else
                                    a[2]=0;
                        if(y<ymin)
                                    a[0]=1;
                        else
                                    a[0]=0;
                        if(y>ymax)
                                    a[1]=1;
                        else
                                    a[1]=0;
                        return a;
            }
            void setminmax()
            {
            System.out.println("Enter xmax of the Rectangle");
            xmax=sc.nextInt();
            System.out.println("Enter ymax of the Rectangle");
            ymax=sc.nextInt();
            System.out.println("Enter xmin of the Rectangle");
            xmin=sc.nextInt();
            System.out.println("Enter ymin of the Rectangle");
            ymin=sc.nextInt();
           
            }
            boolean check(int a[])
            {
                        for(int i=0;i<a.length;i++)
                                    if(a[i]==1)
                                                return false;
                        return true;
            }
            int[] produceXY(int i,int x1,int y1,float m)
            {
                        int a[]=new int [2];
                        float x=0,y=0;
                        switch(i)
                        {
                                    case 0:
                                                x=xmin;
                                                y=y1+m*(x-x1);
                                                break;
                                  
                                    case 1:
                                                x=xmax;         
                                                y=y1+m*(x-x1);
                                                break;
                                    case 3:
                                                y=ymin;
                                                x=x1+(y-y1)/m;
                                                break;
                                    case 2:
                                                y=ymax;
                                                x=x1+(y-y1)/m;
                                                break;
                        }
                        a[0]=(int)x;
                        a[1]=(int)y;
                        return a;
            }
            boolean doAnd(int a[],int b[])
            {
                        for(int i=0;i<a.length;i++)
                        {
                                    int k=a[i]&b[i];
                                    if(k==1)
                                                return false;
                        }
                        return true;
            }
            public void paint(Graphics g)
            {
                setminmax();
                        g.drawRect(xmin,ymin,xmax-xmin,ymax-ymin);
                       g.drawRect(xmin+100,ymin,xmax-xmin,ymax-ymin);
                        int a[][]=new int[2][4];
                        int b[][]=new int[2][4];
                        int c[]=new int[2];
                        int c1=20;
                        int x1,y1,x2,y2;
                        System.out.println("Enter x1 of the line");
                x1=sc.nextInt();
                    System.out.println("Enter y1");
                    y1=sc.nextInt();
                    System.out.println("Enter x2");
                    x2=sc.nextInt();
                    System.out.println("Enter y2");
                y2=sc.nextInt();
           
                        float m=(y2-y1)*1.0f/(x2-x1);
                       
                        g.drawLine(x1,y1,x2,y2);
                        a[0]=set(x1,y1);
                        a[1]=set(x2,y2);
                        if(check(a[0])&&check(a[1]))
                        {
                                    g.drawLine(x1,y1,x2,y2);
                        }
                        else
                        {
                                    if( doAnd(a[0]  , b[1]) )
                                    {
                                                for(int i=a[0].length-1;i>=0;i--)
                                                {
                                                            if(a[0][i]==1)

                                                            {
                                                                        c=produceXY(a[0].length-1-i,x1,y1,m);
                                                                        b[0]=set(c[0],c[1]);
                                                         
                                                                        if(check(b[0]))
                                                                        {
                                                                                    x1=c[0];
                                                                                    y1=c[1];
                                                                                    break;
                                                                        }
                                                                        c1+=20;
                                                            }
                                                }
                                                for(int i=a[0].length-1;i>=0;i--)
                                                {
                                                            if(a[1][i]==1)
                                                            {
                                                                        c=produceXY(a[0].length-1-i,x1,y1,m);
                                                                        b[1]=set(c[0],c[1]);
                                              
                                                                        if(check(b[1]))
                                                                        {
                                                                                    x2=c[0];
                                                                                    y2=c[1];
                                                                                    break;
                                                                        }
                                                                        c1+=20;
                                                            }
                                                }
                                                g.drawLine(x1+100,y1,x2+100,y2);
                                    }
                        }
            }
}
/*<applet code="CohenS.class" width=1000 height=1000>
</applet>*/



IMPLEMENTATION OF DDA LINE DRAWING ALGORITHM

/*
NAME:TEJAS J GHALSASI
DATE:29TH JULY 2013
TITLE:IMPLEMENTATION OF DDA LINE DRAWING ALGORITHM IN JAVA
*/
import java.applet.*;
import java.awt.*;
import java.util.*;

public class dda extends Applet
{
double x1,y1,x2,y2;
    double dx,dy,steps,x,y,k;

    Scanner sc=new Scanner(System.in);
    double xc,yc;
   
    public dda(){
    System.out.println("ENTER X1 Y1");
    x1=sc.nextDouble();
    y1=sc.nextDouble();
    System.out.println("ENTER X2 Y2");
    x2=sc.nextDouble();
    y2=sc.nextDouble();
    }
  
    public void paint(Graphics g)
    {
            try{
            dx=x2-x1;
        dy=y2-y1;
    if(Math.abs(dx)>Math.abs(dy))
        steps=Math.abs(dx);
        else
        steps=Math.abs(dy);
        xc=(dx/steps);
        yc=(dy/steps);
        x=x1;
        y=y1;
    //CODED BY TEJAS GHALSASI
        for(k=1;k<=steps;k++)
        {
            x=x+xc;
            y=y+yc;
            g.fillOval((int)x,(int)y,5,5);
           
        }
    }catch(Exception e){}
    }
}
/*<applet code="dda.class" width="1000" height="1000">
 </applet>*/

 /*
 OUTPUT:
 bash-3.00$ javac dda.java
bash-3.00$ appletviewer dda.java
ENTER X1 Y1
500
200
ENTER X2 Y2
600
500
*/

TO DISPLAY BOUNCING OF A BALL IN JAVA

/*
 CG
TOPIC: TO DISPLAY BOUNCING OF A BALL IN JAVA
*/
import java.applet.*;
import java.awt.*;

public class ball extends Applet implements Runnable
 {
 Thread t;
 int x = 0;
 int y = 0;

public void start()
 {
 t = new Thread(this);
 t.start();
 }

public void paint(Graphics g)
   {
      System.out.println("CODED BY TG ");
      g.fillOval(x,y,100,100);
    }

public void run()
 {
   try
      {
    for(;;)
         {
                for(;;)
              {
               if(y == 300)
                   {
                   System.out.print("\007");
                    break;
                   }
                      else
                   {
                       y = y +3;
                    x = x;
                        Thread.sleep(100);
               repaint();
                }
              }
        for(;;)
                {
             if(y==0)
                 {
                     System.out.print("\007");
                        break;
                           }
     
else
                {
 y = y-3;
            x = x+3;
            Thread.sleep(100);
                 repaint();
                }
                  }
              run();
       }
  }

catch(InterruptedException e)
    {

    }
 }
}
 /* CODED BY TG
 <applet code = "ball" width = 1000 height = 1000> </applet> */




COLLISION OF 2 BODIES IN JAVA

/*
CG
Program to show collision of 2 bodies in java
*/
import java.io.*;
import java.util.*;
import java.awt.*;
import java.applet.*;
public class collision extends Applet
{
int x=0;
int y=100;
int z=500;
int a=100;
int n=0;
Thread t=new Thread();

public void paint(Graphics g)
{
try{
if(x==200)
{
n=100;
}
if(n!=100)
{
g.fillOval(x,y,100,100);
g.fillOval(z,a,100,100);

x=x+1;
z=z-1;
t.sleep(10);
repaint();

}
       }
    catch(Exception e)
{}
   }
}
/*<applet code = "collision" width = 1000 height = 1000> </applet>*/