/*<applet code=wheelrot width=1000 height=600></applet>*/
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class wheelrot extends Applet implements ActionListener
{
TextField t1,t2,t3;
Button b;
public void init()
{
//setBackground(Color.red);
Label l1=new Label("xc(0to1000)");
Label l2=new Label("yc(0to600)");
Label l3=new Label("radius");
t1=new TextField(4);
t2=new TextField(4);
t3=new TextField(4);
b=new Button("start");
add(l1);add(t1);
add(l2);add(t2);
add(l3);add(t3);
add(b);
b.addActionListener(this);
}
public void paint(Graphics g)
{
Graphics g1=g;
int xc,yc,i,r,k;
double angle,pi,d;
pi=3.14;
angle=pi/180;
xc=Integer.parseInt(t1.getText());
yc=Integer.parseInt(t2.getText());
r=Integer.parseInt(t3.getText());
while(xc!=0)
{
for(double j=0;j<100000;j+=.005);
g.setColor(Color.black);
g.fillRect(1,1,1360,1000);
g.setColor(Color.green);
drwLine(1,yc+r,1360,yc+r,g1);
drwOval(xc,yc,r,g1);
drwLine((int)(xc+r*Math.sin(angle)),(int)(yc-r*Math.cos(angle)),(int)(xc-r*Math.sin(angle)),(int)(yc+r*Math.cos(angle)),g1);
drwLine((int)(xc-r*Math.cos(angle)),(int)(yc-r*Math.sin(angle)),(int)(xc+r*Math.cos(angle)),(int)(yc+r*Math.sin(angle)),g1);
//drwLine((int)(xc+r*Math.sin(angle+3.14/4)),(int)(yc-r*Math.cos(angle+3.14/4)),(int)(xc-r*Math.sin(angle+3.14/4)),(int)(yc+r*Math.cos(angle+3.14/4)),g1);
//drwLine((int)(xc-r*Math.cos(angle-3.14/4)),(int)(yc-r*Math.sin(angle-3.14/4)),(int)(xc+r*Math.cos(angle-3.14/4)),(int)(yc+r*Math.sin(angle-3.14/4)) ,g1);
xc+=10*pi*r/180;
angle=angle+10*pi/180;
if(xc>(1000-r))
xc=20;
}
}
public void actionPerformed(ActionEvent awt)
{
repaint();
}
public void drwLine(int c,int d,int e,int f,Graphics g2)
{
int x1=c;
int y1=d;
int x2=e;
int y2=f;
int step;
float xinc,yinc,x,y;
int dy=y2-y1;
int dx=x2-x1;
if(dx>dy)
step=dx;
else
step=dy;
xinc=(float)dx/step;
yinc=(float)dy/step;
x=x1;
y=y1;
g2.drawString(".",(int)x,(int)y);
for(int k=1;k<=step;k++)
{
x=x+xinc;
y=y+yinc;
g2.drawString(".",(int)x,(int)y);
}
}
public void drwOval( int a, int b , int r, Graphics g1)
{
int xc=a;
int yc=b;
int radious=r;
int x=0;
int y=radious;
float p=5/4 - r;
do
{
g1.drawString(".",Math.round(xc+x),Math.round(yc-y));
g1.drawString(".",Math.round(xc+y),Math.round(yc-x));
g1.drawString(".",Math.round(xc+y),Math.round(yc+x));
g1.drawString(".",Math.round(xc+x),Math.round(yc+y));
g1.drawString(".",Math.round(xc-x),Math.round( yc+y));
g1.drawString(".",Math.round(xc-y),Math.round(yc+x));
g1.drawString(".",Math.round(xc-y),Math.round(yc-x));
g1.drawString(".",Math.round(xc-x),Math.round( yc-y));
if(p<0)
{
x=x+1;
p=p+(2*x)+3;
}
else
{
x=x+1;
y=y-1;
p=p-2*y+2*x+5;
}
}
while(x<=y);
}
}
No comments:
Post a Comment