Programming / Computing

Light Chaser Projects

This program demonstrates a graphical Light Chaser Project....................................................       

 

The code for the same is as follows................................................................................

 

 

 

import java.awt.*;

import java.util.*;

import java.awt.event.*;

class Screen extends Frame implements Runnable

{

double x,y,xx,yy,r,ang;

double x1,y1,r1;

double p=0.0;

double x2,y2,r2;

double x3,y3,r3;

double x4,y4,r4;

double x5,y5,r5;

double x6,y6,r6;

int w,h;

int n;

Bulb bulb[];

Thread timer;

public Screen() 

{

super("Light Chaser");

MyWindowAdapter adapter=new MyWindowAdapter(this);

timer=new Thread(this);

addWindowListener(adapter);

xx=0;yy=0;r=200.0;ang=0;n=0;

w=30;h=30;

x=500;y=300;

timer.start();

}

public void run()

{

Thread me = Thread.currentThread();

        while (true) 

        {

            try

            {

              

              

              me.sleep(100);

              

            } catch (InterruptedException e) {}

            repaint();

            

        }

    }

public void paint(Graphics g)

{

p+=10;

setBackground(Color.black);

circle(x,y,r,g);

 

}

public void circle(double x,double y,double r,Graphics g)

{

bulb=new Bulb[36];

for(int i=0;i<36;i++)

{

bulb[i]=new Bulb();

}

Random ran=new Random();

for(int i=0,ang=(int)p;ang

{

xx=x+r*Math.sin(ang*3.14/180);

yy=y+r*Math.cos(ang*3.14/180);

int red=ran.nextInt(205)+50;

int green=ran.nextInt(205)+50;

int blue=ran.nextInt(205)+50;

bulb[i].value(xx,yy,w,h,g,new Color(red,green,blue));

bulb[i].glow();

}

}

}

class Light 

{

public static void main(String arg[])

{

Screen s=new Screen();

s.setSize(1000,600);

s.setVisible(true);

}

}

class MyWindowAdapter extends WindowAdapter

{

Screen s;

public MyWindowAdapter(Screen s)

{

this.s=s;

}

public void windowClosing(WindowEvent we)

{

s.setVisible(false);

System.exit(0);

}

}

class Bulb

{

double x,y;

int w,h;

Color c;

Graphics g;

public Bulb()

{

x=0.0;

y=0.0;

w=10;

h=10;

Color c=Color.black;

}

public void value(double x,double y,int w,int h,Graphics g,Color c)

{

this.g=g;

this.x=x;

this.y=y;

this.w=w;

this.h=h;

this.c=c;

}

public void glow()

{

g.setColor(c);

g.fillOval((int)x,(int)y,w,h);

}

}

 

© 2010 All rights reserved.

Make a free websiteWebnode