Posts

Showing posts from March 22, 2014

Animated Face in java

import java.applet.*;
import java.awt.*;
import java.lang.*;
import java.math.*;
import java.awt.Color;


/*<applet code="face" height=578 width=678></applet>
  */
public class face extends Applet implements Runnable

{
int i=0,j=0,p=1;

Thread t;
public void init()
{
t=new Thread(this);
t.start();
}
public void run()
{
int sec=0;
try
{
while(true)
{
repaint();
sec+=1;

t.sleep(100);

}
}catch(Exception e)
{
System.out.println(e);
}
}

public void update(Graphics g)
{
paint(g);
}

public void paint(Graphics g)
{
Dimension d=this.getSize();
double x=Math.random()*d.width;
double y=Math.random()*d.height;
setBackground(Color.black);


g.setColor(Color.yellow);
g.fillOval(118,118,500,400);

g.setColor(Color.white);
g.fillOval(219,158,90,90);
g.fillOval(419,158,90,90);
g.fillOval(319,258,80,150);
g.setColor(Color.red);

g.fillArc(219,418,300,50,180,180);

g.setColor(Color.black);

g.fillOval(219+j*p,188,30,30);
g.fillOval(479-j*p,188,30,30);

if(i==0)
{
j=j+10;

if(j==60)
{
i=1;

}

Animated Rainbow in Applet

import java.applet.*;
import java.awt.*;
import java.lang.*;
import java.math.*;
import java.awt.Color;


/*<applet code="rainbow" height=1200 width=1200></applet>
  */
public class rainbow extends Applet implements Runnable

{
int i=0,j=0;
int rr[]={148,75,0,0,255,255,255};
int gg[]={0,0,0,255,255,127,0};
int bb[]={211,130,255,0,0,0,0};
Thread t;
public void init()
{
t=new Thread(this);
t.start();
}
public void run()
{
int sec=0;
setSize(1200,1200);
try
{
while(true)
{
repaint();
sec+=1;

t.sleep(1000);

}
}catch(Exception e)
{
System.out.println(e);
}
}

public void update(Graphics g)
{
paint(g);
}
public void paint(Graphics g)
{

setBackground(Color.black);


for(i=0;i<7;i++)
{
Color r=new Color((int)rr[i],(int)gg[i],(int)bb[i]);
g.setColor(r);
g.fillArc(8+30*i,8+30*i,1000-60*i,1000-60*i,0,j);
}
g.setColor(Color.black);
g.fillArc(218,218,580,580,0,180);
if(j==180)
t.stop();
j+=10;


}
}