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>
*/
No comments:
Post a Comment