Saturday, March 15, 2014

Spiral motion code in java

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

public class Sprial extends Applet{
public void paint(Graphics g){
int x=0,y=10,xrate=240,yrate=210;
setBackground(Color.green);
g.setColor(Color.black);
for(int i=1;i<=15;i++){
int m=x;
int n=y;
if(i%4==1){
x+=xrate;
xrate-=30;
}
else if(i%4==2){
y+=yrate;
yrate-=30;
}
else if(i%4==3){
x-=xrate;
xrate-=30;
}
else
{
y-=yrate;
yrate-=30;
}
g.drawLine(m, n, x, y);
}
}
}

No comments:

Post a Comment

Contributors

Translate