Java学习者论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

手机号码,快捷登录

恭喜Java学习者论坛(https://www.javaxxz.com)已经为数万Java学习者服务超过8年了!积累会员资料超过10000G+
成为本站VIP会员,下载本站10000G+会员资源,购买链接:点击进入购买VIP会员
JAVA高级面试进阶视频教程Java架构师系统进阶VIP课程

分布式高可用全栈开发微服务教程

Go语言视频零基础入门到精通

Java架构师3期(课件+源码)

Java开发全终端实战租房项目视频教程

SpringBoot2.X入门到高级使用教程

大数据培训第六期全套视频教程

深度学习(CNN RNN GAN)算法原理

Java亿级流量电商系统视频教程

互联网架构师视频教程

年薪50万Spark2.0从入门到精通

年薪50万!人工智能学习路线教程

年薪50万!大数据从入门到精通学习路线年薪50万!机器学习入门到精通视频教程
仿小米商城类app和小程序视频教程深度学习数据分析基础到实战最新黑马javaEE2.1就业课程从 0到JVM实战高手教程 MySQL入门到精通教程
查看: 284|回复: 0

[图像处理学习]水中倒影

[复制链接]
  • TA的每日心情
    开心
    2021-3-12 23:18
  • 签到天数: 2 天

    [LV.1]初来乍到

    发表于 2014-10-31 23:57:15 | 显示全部楼层 |阅读模式
    import java.applet.*;
    import java.net.URL;
    import java.net.MalformedURLException;
    import java.awt.*;
    public class Lake extends Applet implements Runnable {
    Thread m_Lake = null;
    private Graphics m_Graphics, m_WaveGraphics;
    private Image m_Image, m_Overlay, m_WaveImage;
    private int m_nCurrImage; private int m_nImgWidth = 0;
    private int m_nImgHeight = 0;
    private int m_nOvlWidth = 0;
    private int m_nOvlHeight = 0;
    private boolean m_fAllLoaded = false, m_tAnimate = true;
    private final int NUM_FRAMES = 12;
    private String m_ImageName = "";
    private String m_OverlayName = "";
    private URL m_HRef; private String m_Frame = "_self";
    private final String PARAM_image = "image";
      
       
       
         
       

       
       
      

    1.         private final String PARAM_overlay = "overlay";
    2.         private final String PARAM_href = "href";
    3.         private final String PARAM_target = "target";
    4.         public Lake()
    5.         {
    6.                 // TODO: Add constructor code here
    7.         }
    8.         public String getAppletInfo()
    9.         {
    10.                 return "Name: Lake v3.0
    11. " +
    12.                        "Author: David Griffiths
    13. " +
    14.                        "Created with Microsoft Visual J++ Version 1.0";
    15.         }
    16.         public String[][] getParameterInfo()
    17.         {
    18.                 String[][] info =
    19.                 {
    20.                         { PARAM_image, "String", "JPG or GIF file to reflect" },
    21.                         { PARAM_overlay, "String", "JPG or GIF file to use as overlay" },
    22.                         { PARAM_href, "URL", "URL to link to" },
    23.                         { PARAM_target, "String", "Target frame" },
    24.                 };
    25.                 return info;               
    26.         }
    27.         public void init()
    28.         {
    29.                 String param;
    30.                 param = getParameter("image");
    31.                 if (param != null)
    32.                         m_ImageName = param;
    33.                 param = getParameter(PARAM_overlay);
    34.                 if (param != null)
    35.                         m_OverlayName = param;
    36.                 param = getParameter(PARAM_href);
    37.                 if (param != null)
    38.                 try
    39.                 {
    40.                     m_HRef = new URL(getDocumentBase(), param);
    41.                 }
    42.                 catch (MalformedURLException e)
    43.                 {
    44.                     getAppletContext().showStatus("Bad URL: " + param);
    45.                     return;
    46.                 }
    47.                 param = getParameter(PARAM_target);
    48.                 if (param != null)
    49.                         m_Frame = param;
    50.         }
    51.         public void destroy()
    52.         {
    53.                 // TODO: Place applet cleanup code here
    54.         }
    55.         private void displayImage(Graphics g)
    56.         {
    57.                 if (!m_fAllLoaded)
    58.                         return;
    59.                 if (m_WaveImage != null) {
    60.                         g.drawImage (m_WaveImage, (-m_nCurrImage * m_nImgWidth), m_nImgHeight, this);
    61.                         g.drawImage (m_WaveImage, ((NUM_FRAMES-m_nCurrImage) * m_nImgWidth),
    62.                                 m_nImgHeight, this);
    63.                 }
    64.                 g.drawImage (m_Image, 0, -1, this);
    65.         }
    66.         public void paint(Graphics g)
    67.         {
    68.                 if (m_fAllLoaded)
    69.                         displayImage(g);
    70.                 else
    71.                         g.drawString("Loading images...", 10, 20);
    72.                 // TODO: Place additional applet Paint code here
    73.         }
    74.         public void start()
    75.         {
    76.                 if (m_Lake == null)
    77.                 {
    78.                         m_Lake = new Thread(this);
    79.                         m_Lake.start();
    80.                 }
    81.         }
    82.        
    83.         public void stop()
    84.         {
    85.                 if (m_Lake != null)
    86.                 {
    87.                         m_Lake.stop();
    88.                         m_Lake = null;
    89.                 }
    90.         }
    91.         public void run()
    92.         {
    93.                 m_nCurrImage = 0;
    94.                
    95.         if (!m_fAllLoaded)
    96.                 {
    97.                     repaint();
    98.                     m_Graphics = getGraphics();
    99.                     MediaTracker tracker = new MediaTracker(this);
    100.                     String strImage;
    101.                     m_Image = getImage(getDocumentBase(), m_ImageName);
    102.             if (!"".equals(m_OverlayName))
    103.                             m_Overlay = getImage(getDocumentBase(), m_OverlayName);
    104.             tracker.addImage(m_Image, 0);
    105.             if (!"".equals(m_OverlayName))
    106.                                 tracker.addImage(m_Overlay, 1);
    107.                         try
    108.                         {
    109.                                 tracker.waitForAll();
    110.                                 m_fAllLoaded = !tracker.isErrorAny();
    111.                         }
    112.                         catch (InterruptedException e) {}
    113.                        
    114.                         if (!m_fAllLoaded)
    115.                         {
    116.                             stop();
    117.                             m_Graphics.drawString("Error loading images!", 10, 40);
    118.                             return;
    119.                         }
    120.                     m_nImgWidth  = m_Image.getWidth(this);
    121.                     m_nImgHeight = m_Image.getHeight(this);
    122.             if (!"".equals(m_OverlayName)) {
    123.                             m_nOvlWidth  = m_Overlay.getWidth(this);
    124.                             m_nOvlHeight = m_Overlay.getHeight(this);
    125.                         }
    126.                         createAnimation();
    127.         }               
    128.                 repaint();
    129.                 while (true)
    130.                 {
    131.                         try{
    132.                                 if (m_tAnimate)
    133.                                 {
    134.                                         displayImage(m_Graphics);
    135.                                         if (++m_nCurrImage == NUM_FRAMES)
    136.                                                 m_nCurrImage = 0;
    137.                                         Thread.sleep(50);
    138.                                 }
    139.                                 else
    140.                                         Thread.sleep(500);
    141.                        } catch (InterruptedException e){
    142.                                 stop();
    143.                           }
    144.                 }
    145.         }
    146.     public boolean mouseUp(Event event, int i, int j)
    147.     {
    148.         boolean flag = super.mouseUp(event, i, j);
    149.                 if (m_HRef == null)
    150.                         m_tAnimate = !m_tAnimate; // Toggle m_tAnimate to start/stop animation.
    151.                 else
    152.                 {
    153.                         showStatus("" + m_HRef);
    154.                         getAppletContext().showDocument(m_HRef, m_Frame);
    155.                 }
    156.         return true;
    157.     }
    158.     public void createAnimation ()
    159.         {
    160.                 Image backImg = createImage (m_nImgWidth, m_nImgHeight + 1);
    161.         Graphics backG = backImg.getGraphics();
    162.         backG.drawImage (m_Image, 0, 1, this);
    163.         for (int i = 0; i < (m_nImgHeight >> 1); i++)
    164.                 {
    165.             backG.copyArea (0, i, m_nImgWidth, 1, 0, m_nImgHeight - i);
    166.             backG.copyArea (0, m_nImgHeight - 1 - i, m_nImgWidth, 1,
    167.                         0, -m_nImgHeight + 1 + (i << 1));
    168.             backG.copyArea (0, m_nImgHeight, m_nImgWidth, 1, 0, -1 - i);
    169.         }
    170.         m_WaveImage = createImage ((NUM_FRAMES + 1) * m_nImgWidth, m_nImgHeight);
    171.         m_WaveGraphics = m_WaveImage.getGraphics();
    172.         m_WaveGraphics.drawImage (backImg, NUM_FRAMES * m_nImgWidth, 0, this);
    173.         for (int phase = 0; phase < NUM_FRAMES; phase++)
    174.            makeWaves (m_WaveGraphics, phase);
    175.                 backG.drawImage (m_Image, 0, 1, this);
    176.                 if (!"".equals(m_OverlayName))
    177.                         backG.drawImage (m_Overlay,
    178.                                 (m_nImgWidth - m_nOvlWidth) >> 1,
    179.                                 m_nImgHeight - (m_nOvlHeight >> 1), this);
    180.                 m_Image = backImg;
    181.         }
    182.         public void makeWaves (Graphics g, int phase)
    183.         {
    184.                 double p1;
    185.                 int     dispx, dispy;
    186.                 p1 = 2 * Math.PI * (double)phase / (double)NUM_FRAMES;
    187.                 dispx = (NUM_FRAMES - phase) * m_nImgWidth;
    188.                 for (int i = 0; i < m_nImgHeight; i++)
    189.                 {
    190.                         dispy = (int)((m_nImgHeight/14) * ((double) i + 28.0)
    191.                                 * Math.sin ((double)((m_nImgHeight/14)*(m_nImgHeight - i))
    192.                                 /(double)(i + 1)
    193.                                 + p1)
    194.                                 / (double) m_nImgHeight);
    195.                         if (i < -dispy)
    196.                                 g.copyArea (NUM_FRAMES * m_nImgWidth, i, m_nImgWidth, 1,
    197.                                         -dispx, 0);
    198.                         else
    199.                                 g.copyArea (NUM_FRAMES * m_nImgWidth, i + dispy,
    200.                                         m_nImgWidth, 1, -dispx, -dispy);
    201.                 }
    202.                 if (!"".equals(m_OverlayName))
    203.                         g.drawImage (m_Overlay,
    204.                                 (phase * m_nImgWidth) + ((m_nImgWidth - m_nOvlWidth) >> 1),
    205.                                 -m_nOvlHeight >> 1, this);
    206.         }
    207. }
    复制代码


      
      
       
       

         
       

         
       
      
    复制代码

    源码下载:http://file.javaxxz.com/2014/10/31/235715359.zip
    回复

    使用道具 举报

    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    QQ|手机版|Java学习者论坛 ( 声明:本站资料整理自互联网,用于Java学习者交流学习使用,对资料版权不负任何法律责任,若有侵权请及时联系客服屏蔽删除 )

    GMT+8, 2025-2-25 19:43 , Processed in 0.312275 second(s), 36 queries .

    Powered by Discuz! X3.4

    © 2001-2017 Comsenz Inc.

    快速回复 返回顶部 返回列表