/******************************************* Pieces applet 1.0 by Tatiana Konstantnova,1999 *******************************************/ import java.applet.*; import java.awt.*; import java.awt.image.*; class PiecesFilter extends RGBImageFilter{ int saturation; public PiecesFilter (int saturation) { canFilterIndexColorModel=true; this.saturation=saturation; } public int filterRGB (int x,int y,int rgb) { int pixcolor=rgb & 0x00FF0000FF; int n = (saturation<<24) & 0xFF0000FF; return (n | pixcolor); } } public class Pieces extends Applet implements Runnable { int halfw; int halfh; int x1=0; int x2=51; int x3=0; int x4=51; int y1=0; int y2=0; int y3=51; int y4=51; int oval_x=0; int oval_y=0; Image p1,p2,p3,p4; Thread animation=null; boolean flag=true; boolean filtered=false; int use_filter=1; String tst; public void init() { p1=getImage(getCodeBase(),getParameter("ImgLT")); p2=getImage(getCodeBase(),getParameter("ImgRT")); p3=getImage(getCodeBase(),getParameter("ImgLB")); p4=getImage(getCodeBase(),getParameter("ImgRB")); halfw=size().width/2; halfh=size().height/2; String s=getParameter("Filter"); if (s==null) use_filter=1; else use_filter=Integer.parseInt(s); } public boolean mouseDown(Event evt,int x,int y){ repaint(); if (flag) flag=false; else flag=true; return(true); } public boolean mouseMove (Event evt,int x,int y) { x1=0; x2=halfw; x3=0; x4=halfw; y1=0; y2=0; y3=halfh; y4=halfh; return(true); } public void start() { if (animation==null) { animation=new Thread (this); animation.start(); } } public void paint (Graphics g) { int red,green,blue; /*get background color */ String Red=getParameter("Red"); String Green=getParameter("Green"); String Blue=getParameter("Blue"); if ((Red==null)||(Green==null)||(Blue==null)) { /* set default background if no parameteres entered*/ red=0; green=0; blue=4; } else { red=Integer.parseInt(Red); green=Integer.parseInt(Green); blue=Integer.parseInt(Blue); } /*draw background*/ Color color=new Color(red,green,blue);// default=0,0,4 for (int i=0;i<32;i++) { g.setColor(color); g.fillRect(0,i*5,2*halfw,5); color=color.brighter(); } /*draw ball*/ oval_x+=15; if (oval_x>2*halfw) oval_x=0; oval_y+=10; if (oval_y>2*halfh) oval_y=0; g.fillOval(oval_x,oval_y,15,15); /* draw pieces */ g.drawImage(p1,x1,y1,this); g.drawImage(p2,x2,y2,this); g.drawImage(p3,x3,y3,this); g.drawImage(p4,x4,y4,this); if (!flag) { /* about information when mouse clicked */ g.setColor(Color.white); g.drawString("welcome.to/lunya",10,10); Font default_font=g.getFont(); g.setColor( new Color(255,234,10)); Font font =new Font("Helvetica",Font.BOLD,14); g.setFont(font); g.drawString("Tanya's page",10,50); g.setColor(Color.white); g.setFont(default_font); g.drawString("by Tatiana",10,90); g.drawString("Konstantinova",10,100); } g.drawString(tst,20,30); } public void update(Graphics g){ paint(g); } public void run (){ while (animation!=null) { if (x1<0) if (use_filter==1 ) if (filtered) { /* use filter */ for (int i=0;i<256;i+=32) { ImageFilter f=new PiecesFilter(i); ImageProducer producer=new FilteredImageSource(p3.getSource(),f); p3=createImage(producer); producer=new FilteredImageSource(p2.getSource(),f); p2=createImage(producer); producer=new FilteredImageSource(p1.getSource(),f); p1=createImage(producer); producer=new FilteredImageSource(p4.getSource(),f); p4=createImage(producer); } filtered=false; } else { /* paint without filter */ p1=getImage(getCodeBase(),getParameter("ImgLT")); p2=getImage(getCodeBase(),getParameter("ImgRT")); p3=getImage(getCodeBase(),getParameter("ImgLB")); p4=getImage(getCodeBase(),getParameter("ImgRB")); filtered=true; } /* move pieces */ x1-=10; if (x1<-halfw) x1=0; y1-=10; if (y1<-halfh) y1=0; x2+=10; if (x2>2*halfw) x2=halfw; y2-=10; if (y2<-halfh) y2=0; x3-=10; if (x3<-halfw) x3=0; y3+=10; if (y3>2*halfh) y3=halfh; x4+=10; if (x4>2*halfw) x4=halfw; y4+=10; if (y4>2*halfh) y4=halfh; repaint(); try { int wait; if ((x1==0)&&(x4==halfw)) //pieces united wait=2000; else wait=300; if (!flag) wait=3000;//clicked for about information Thread.sleep(wait); } catch (InterruptedException e) {} } } }