We can draw rainbow using
1. fillArc
2. drawArc
Following code is using drawArc.
for fillArc click Here...
Code :-
import java.applet.*;
import java.awt.*;
import java.lang.*;
/*<applet code="rainbow" height=800 width=700>
</applet> */
public class rainbow extends Applet
void slep()
{
try {
Thread.sleep(100);
} catch(InterruptedException ex) {
Thread.currentThread().interrupt();
}
}
public void init()
{
}
public void paint(Graphics g)
{
int x,y,z;
x=0;y=50;z=100;
for(int i=0;i<200;i++)
{
if(i%20==0)
{
Color c1=new Color(z,x,y);
x=(x+50)%255;
y=(y+70)%255;
z=(z+100)%255;
g.setColor(c1);
}
g.drawArc(400-(i),400-(i),1+(i*2),1+(i*2),0,180);
slep();
}
}
}
Comments