★ wanayoo — archive 1999 http://java.webdeveloper.com/Morph/source.htmlNouvelle recherche | Portail wanayoo
Computer Digital Expo


Find a Web Host With:
CGI Access
DB Support
NT Servers
UNIX Servers
Telnet Access

advanced search
Internet News
Internet Investing
IT
Windows Technology
Linux/Open Source
Developer
Interactive Marketing
xSP Resources
Small Business
Wireless Internet
Downloads
Internet Resources
Internet Lists
International
EarthWeb
Career Resources

Search internet.com
Advertise
Corporate Info
Newsletters
E-mail Offers
Be a Commerce Partner
Build an Online Store
Find a Consultant
Promote Your Website
Tech Magazines - FREE
Internet Jobs
Track Defects Online
Compare Prices & Shop
Breathing Problems?
IT Training
Best Deals on PDAs!
FlashKit
Gif.com
HierMenusCentral
JavaBoutique
JavaScript.com
JavaScriptSource
WebDev Jobs
JustSMIL
ScriptSearch
StreamingMediaWorld
Web Hosts
WebDevelopersJournal WDVL
WebDeveloper.com
WebReference.com
XMLFiles.com
CGI
HTML
Java
JavaScript
Web Design and Promotion
Web Site Development
E-mail Address:


Can you receive
HTML e-mail?

Yes   No

Zip Code:


Morph


//Applet : Morph  -  Sep 11 '99.
//Author : Laxmi Narayana .Kota
// E-mail id: laxmikota@hotmail.com

import java.awt.*;
import java.awt.image.*;
import java.awt.event.*;
import java.applet.*;


public class Morph extends Applet implements Runnable{
  boolean isStandalone = false;
  int w,h,cnt=0,cnt1=0,totalpictures,temp,max,delay;
  int buf[],clearbuf[],bufimg[][],imagewidth,imageheight;
  static int zoomout=1;
  int lsmargin[],rsmargin[],ldmargin[],rdmargin[],lscnt=0,rscnt=0,clear[],ldcnt=0,rdcnt=0;
  int srcdif,dstdif,tempdif,xdif,xinc;
  int tcnt=0, bcnt=0,tsmargin=0,bsmargin=0,tdmargin=0,bdmargin=0;
  int dsthdif,srchdif,preh,yinc;
// l - left ; r- right; ls - left source; rs - right source
// t- top of the image; b - bottom of the image
// ld - left margin of destination image
// rd - right margin 0f destination image

  Thread t;
  Image img[],img1;
  MediaTracker med;
  PixelGrabber pg[];
  String imagenames[],bgcolor,fontcolor,author;

  Graphics offscreengraphics;
  Image offscreenimage=null;

  public String getParameter(String key, String def) {
    return isStandalone ? System.getProperty(key, def) :
      (getParameter(key) != null ? getParameter(key) : def);
  }

  public Morph() {
  }

  public void init() {
    //t=new Thread(this);
    try{
        totalpictures=Integer.parseInt(getParameter("totalpictures","0"));
        bgcolor=this.getParameter("bgcolor","0x000000");
        fontcolor=this.getParameter("fontcolor","0x00ff00");
        max=Integer.parseInt(getParameter("fadecount","30"));
	      delay=Integer.parseInt(getParameter("delay","30"));
        author=getParameter("author","");
    }catch(Exception exce){}
    if(!author.equalsIgnoreCase("Laxminarayana.kota"))
    System.exit(0);
    this.setBackground(new Color(Integer.parseInt(bgcolor.substring(2),16)));
    img=new Image[totalpictures];
    imagenames=new String[totalpictures];
    if(totalpictures >0 )
    { try{
           for(int i=0;i<totalpictures;i++)
           imagenames[i]=getParameter("imagenames["+i+"]","");
         }catch(Exception exce){}
    }

  for(int i=0;i<totalpictures;i++)
    img[i]=getImage(getCodeBase(),imagenames[i]);

  med=new MediaTracker(this);
  for(int i=0;i<img.length;i++)
  med.addImage(img[i],0);

  //t.start();
  }
  public void start() {
   t= new Thread(this);
   t.start();
  }
  public void run()
  {
    try{
     med.waitForAll();
     imagewidth=img[0].getWidth(null);imageheight=img[0].getHeight(null);
     buf=new int[imagewidth*imageheight];clearbuf=new int[imagewidth*imageheight];
     lsmargin=new int[imageheight];rsmargin=new int[imageheight];
     ldmargin=new int[imageheight];rdmargin=new int[imageheight];
     clear=new int[imageheight];

     for(int i=0;i<imageheight;i++)
     for(int j=0;j<imagewidth;j++)
      {buf[imagewidth*i+j]=0xffffff; clearbuf[imagewidth*i+j]=0xffffff;}

     for(int i=0; i<imageheight; ++i)
      clear[i]=0;

     bufimg=new int[img.length][imagewidth*imageheight];
     clear=new int[imageheight];pg=new PixelGrabber[img.length];

     for(int i=0;i<img.length;i++)
     {pg[i]=new PixelGrabber(img[i],0,0,imagewidth,imageheight,bufimg[i],0,imagewidth);
      pg[i].grabPixels();
     }

   }catch (InterruptedException exce){getAppletContext().showStatus("Loading images is failed");}

   try{
    for(;;){
     cnt++;
     if(cnt>max)
     { cnt1++; if(cnt1>img.length-1)cnt1=0;
       cnt=0;
     }
     temp=(cnt1 <(img.length-1)) ? 1+cnt1 : 0;



   System.arraycopy(clearbuf,0,buf,0,imagewidth*imageheight);
   tcnt=0;

  /* System.arraycopy(clear,0,lsmargin,0,imageheight);
   System.arraycopy(clear,0,rsmargin,0,imageheight);
   System.arraycopy(clear,0,ldmargin,0,imageheight);
   System.arraycopy(clear,0,rdmargin,0,imageheight);*/
  if(cnt>=0 && cnt<=1){
   for(int i=0; i<imageheight; ++i) // left margin of source image
   {lscnt=0;rscnt=0;
    for(int j=0; j<zoomout*imagewidth; ++j)
    { if(lscnt==0 && j>0){
       if( filter(bufimg[cnt1][imagewidth*i+j*imagewidth/(zoomout*imagewidth)],11) != filter(bufimg[cnt1][imagewidth*i],11) ){
       lsmargin[i]=j/zoomout;lscnt++;
       if(tcnt==0){tsmargin=i;tcnt++;}else tcnt++;}
      }
    }
   }
   bsmargin=tcnt + tsmargin;tcnt=0; // takes up the bottom margin of the image

   for(int i=0; i<imageheight; ++i) // for right margin of soure image
   {rscnt=0;
    for(int j=0; j<zoomout*imagewidth; ++j)
    { if (rscnt==0 && j<zoomout*imagewidth){
       if( filter(bufimg[cnt1][imagewidth*i+(zoomout*imagewidth-1-j)*imagewidth/(zoomout*imagewidth)],11) != filter(bufimg[cnt1][imagewidth*i+imagewidth-1],11) ){
       rsmargin[i]=j/zoomout;rscnt++;}
      }
     }
    }

   for(int i=0; i<imageheight; ++i)// left margin of destination image
   {ldcnt=0;rdcnt=0;
    for(int j=0; j<zoomout*imagewidth; ++j)
    { if(ldcnt==0 && j>0){
       if( filter(bufimg[temp][imagewidth*i+j*imagewidth/(zoomout*imagewidth)],11) != filter(bufimg[temp][imagewidth*i],11) ){
       ldmargin[i]=j/zoomout;ldcnt++;
        if(tcnt==0){tdmargin=i;tcnt++;}else tcnt++; }
      }
    }
   }
  bdmargin=tcnt+tdmargin;tcnt=0; // bottom margin of the destination image

  for(int i=0; i<imageheight; ++i) //right margin of destination image
  { rdcnt=0;
    for(int j=0; j<zoomout*imagewidth; ++j)
    {  if (rdcnt==0 && j<zoomout*imagewidth){
       if( filter(bufimg[temp][imagewidth*i+(zoomout*imagewidth-1-j)*imagewidth/(zoomout*imagewidth)],11) != filter(bufimg[temp][imagewidth*i+imagewidth-1],11) ){
       rdmargin[i]=j/zoomout;rdcnt++;}
      }
    }
  }
  }
  for(int k=0;k<imageheight;++k)
  { dsthdif=bdmargin-tdmargin; //132
    srchdif=bsmargin-tsmargin; // 76
    yinc=tsmargin - (tsmargin - tdmargin)*cnt/max;//27-25*30/30=2
    preh=srchdif - (srchdif - dsthdif)*cnt/max;//76- (-56)*30/30=134
   if(k>=yinc && k<=yinc+preh)
   {for(int j=0;j<imagewidth;++j)
    {int scalehsrc,scalehdst;
      scalehsrc=/old?u=http%3A%2F%2Fjava.webdeveloper.com%2FMorph%2Ftsmargin%2B%28k-yinc%29%2Asrchdif%2Fpreh%3B%2F27%2B%28132%29%2A76%2F132&y=1999
      scalehdst=tdmargin+(k-yinc)*dsthdif/preh;//2+76*132/76
      dstdif=(imagewidth-1-rdmargin[scalehdst]) - ldmargin[scalehdst];
      srcdif=(imagewidth-1-rsmargin[scalehsrc]) - lsmargin[scalehsrc];
      xdif=lsmargin[scalehsrc] - ldmargin[scalehdst];
      xinc=lsmargin[scalehsrc] - xdif*(cnt)/max; //(max-cnt)/max;
      tempdif=srcdif - (srcdif-dstdif)*(cnt)/max;
      if(j>xinc && j<=xinc+tempdif)
      {int x1,x;
       x=imagewidth*scalehsrc+lsmargin[scalehsrc]+(j-xinc)*srcdif/tempdif;// for src image
       x1=imagewidth*scalehdst+ldmargin[scalehdst]+(j-xinc)*dstdif/tempdif;// for dst image
       buf[imagewidth*k+j]=0xff<<24 |( compositefilter(bufimg[cnt1][x],max-cnt)+compositefilter(bufimg[temp][x1],cnt));
      }else   buf[imagewidth*k+j]=0xff000000;
    }
   }
   }
	   img1=createImage(new MemoryImageSource(imagewidth,imageheight,buf,0,imagewidth));
     if(cnt==max)  t.sleep(1000);
     else  t.sleep(delay);
     repaint();
    }
  }catch(InterruptedException e){}

  }
   public synchronized void update(Graphics g)
  {
   Dimension d = getSize();
    if((offscreenimage == null))
    {
      offscreenimage = createImage(d.width, d.height);
      offscreengraphics= offscreenimage.getGraphics();
    }
    offscreengraphics.setColor(getBackground());
    offscreengraphics.fillRect(0, 0, d.width, d.height);
    paint(offscreengraphics);
    g.drawImage(offscreenimage, 0, 0,this);
  }

  public void paint(Graphics g)
  {
   if(med.statusAll(false)==med.COMPLETE)
    g.drawImage(img1,0,0,this);
   else
   { g.setColor(new Color(Integer.parseInt(fontcolor.substring(2),16)));
     g.drawString("Loading Images Please wait...",20,100);
   }
  }

  public void stop() {
  t.interrupt();
  }
  public void destroy() {
  if(t != null){t=null;}
  }

  public String getAppletInfo() {
    return "Morph  by LaxmiNarayana.Kota, Java vesion 1.0.2 - 11 Sep '99";
  }

  public String[][] getParameterInfo() {
    return null;
  }

  public int filter(int rgb,int percent)
  { int r,g,b,temp;
    r=rgb>>16 & 0xff; g=rgb>>8 & 0xff; b=rgb & 0xff;
    r=r*8/100;g=g*8/100;b=b*8/100;
    return (0xff<<24 | r<<16 | g<<8 | b) ;
  }
 public int compositefilter(int rgb, int percent)
 { int r,g,b;
   r=rgb>>16 & 0xff; g=rgb>>8 & 0xff; b=rgb & 0xff;
   r=r*percent/max;g=g*percent/max;b=b*percent/max;
   return (0xff<<24 | r<<16 | g<<8 | b) ;

 }

}

Back to the Morph applet page


Applet Index
(sorted alphabetically)

A B C D E F G H I J K
L M N O P Q R S T U
V W X Y Z #s
The Java Source
(applets w/source code)

A B C D E F G H I J K
L M N O P Q R S T U
V W X Y Z

How to Add Java Applets to Your Site

New on the Java Boutique:

New Article:
J2EE Deployment Specification
Why is it that J2EE applications written in the same language, Java, may not coexist on different servers? While the answer isn't simple Sun has set out to alleviate these problems with the "J2EE Deployment Specification".
... [more articles]

New Tutorial:
Designing Packages for Stability
Are your designs stable? This month Samudra will focus on the change impact relationship involved in designing classes showing us how to take them into account when designing the package relationship.
... [more Tutorials]

Year in Review:
The Best of 2002
The year 2002 saw 201 new applets posted to JavaBoutique. Check out the 2 most popular apps from each month of 2002!
... [popular applets]

Elsewhere on internet.com:

WebDeveloper Java
Lots of Java information on webdeveloper.com

WDVL Java
Thorough Java resource at the Web Developer's Virtual Library.

ScriptSearch Java
Hundreds of free Java code files to download.

internet.com logo




Developer News

JBoss Group: Defections Aren't a Big Deal

IE Object Tag Buffer Overflow Patched

SCO Shuts Down German Site



Database Journal Launched!
Jupiter Media has announced the launch of Database Journal. DBJ offers SQL courses and other database related resources for beginner to expert developers.



JWizardPane
Build modern wizard style interface quickly. API easy to use. Bulti-in show dialog and frame support.
Download of the Week
BSCOutline v5.10
BSCOutline Java Outline Applet is a customizable tree view control for use in Web pages, similar to that used by Windows File Manager or Explorer. BSCOutline has been written to be the simple to use and small to store.

JB User Poll
How does .NET fit into your programming?
The JavaBoutique Top 15:
1. ChompText
2. PingPong
3. PulseText
4. DJPopMenu
5. RushHour
6. NavBar
7. 3DMaze
8. AScroll2
9. Encyclo
10. Nibbly
11. AnimLetters_anim
12. Distorter
13. BMMenu
14. SiteBrowser
15. Viewer
Want more? Check out our Top 100!

Refer-It
Affiliate Program and Referral Directory.
New on internet.com
AOL 9.0 Represents Streaming Sea Change
After years of investment, AOL's own multimedia player technology represents an emerging agnostic standard among competing media player formats.

Lessons From the Lemonade Stand
10 ways for your small business to succeed at e-commerce..

Global Biz Still Unprepared
Record-breaking digital attacks and threats of more serious disasters have not inspired organizations to adopt complete business continuity plans for dealing with catastrophes.


100's of firms that help your Web site be found

Copyright 2003 Jupitermedia Corporation All Rights Reserved.
Legal Notices,  Licensing, Reprints, & Permissions,  Privacy Policy.
http://www.internet.com/