import java.applet.Applet;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Image; import net.java2000.tools.NoNull; /**
* 一段眼睛跟着鼠标转动的跟踪眼代码。<br>
* 你可以单独运行,或者放在html里面<br>
* <applet code="Eye" codebase="codebase" width="400" height="135"
* name="eyesApplet"><br>
* <param name="faceFile" value="doofus.jpg"/><br>
* <param name="testMode" value="false"/> <br>
* <param name="leftEyeX" value="75"/> <br>
* <param name="leftEyeY" value="77"/> <br>
* <param name="rightEyeX" value="310"/> <br>
* <param name="rightEyeY" value="75"/><br>
* <param name="irisRadius" value="20"/> <br>
* <param name="pupilRadius" value="8"/><br>
* <param name="leftEyeRadius" value="5"/><br>
* <param name="rightEyeRadius" value="5"/> <br>
* <param name="horizontalSkew" value="3.5"/><br>
* <param name="eyeIndependence" value="0.4"/> <br>
* <param name="irisRed" value="128"/><br>
* <param name="irisGreen" value="64"/> <br>
* <param name="irisBlue" value="0"/> <br>
* <param name="verticalOffset" value="100"/> <br>
* </applet>
*
* @author 赵学庆,Java世纪网(java2000.net)
*
*/
public class Eye extends Applet {
private static final long serialVersionUID = 4124530672062457469L;
private String mErrorMessage;
private Image mFace;
private Color mIrisColor, mPupilColor = Color.black;
private int mMouseX, mMouseY;
private int mLeftEyeX, mLeftEyeY, mRightEyeX, mRightEyeY;
private int mLeftIrisX, mLeftIrisY, mRightIrisX, mRightIrisY;
private int mLeftPupilX, mLeftPupilY, mRightPupilX, mRightPupilY;
private int mIrisRadius, mPupilRadius;
private int mLeftEyeRadius, mRightEyeRadius, mLeftPupilTR, mRightPupilTR;
private int mVerticalOffset; // 默认值
private int mFaceX = 0, mFaceY = 0; // image start at 0, 0
private int mIrisRed = 128, mIrisGreen = 64, mIrisBlue = 0;
private double mHorizontalSkew = 3.5, mEyeIndependence = 0.5, mGapFactor = 1.5;
private boolean mTestMode = false; private Dimension mDimension;
private Image mImage;
private Graphics mGraphics; public void init() {
mErrorMessage = null; try {
// 设置的一些参数
// 背景的面部图片
mFace = getImage(getCodeBase(), NoNull.toString(getParameter("faceFile"), "doofus.jpg")); // 左侧眼睛的x坐标
mLeftEyeX = mLeftIrisX = mLeftPupilX = Integer.parseInt(NoNull.toString(
getParameter("leftEyeX"), "75")); // 左侧眼睛的y坐标
mLeftEyeY = mLeftIrisY = mLeftPupilY = Integer.parseInt(NoNull.toString(
getParameter("leftEyeY"), "77")); // 右侧眼睛的x坐标
mRightEyeX = mRightIrisX = mRightPupilX = Integer.parseInt(NoNull.toString(
getParameter("rightEyeX"), "310")); // 右侧眼睛的y坐标
mRightEyeY = mRightIrisY = mRightPupilY = Integer.parseInt(NoNull.toString(
getParameter("rightEyeY"), "75")); // 眼睛的白眼球半径
mIrisRadius = Integer.parseInt(NoNull.toString(getParameter("irisRadius"), "20")); // 眼睛的瞳孔半径
mPupilRadius = Integer.parseInt(NoNull.toString(getParameter("pupilRadius"), "8")); // 左眼睛的移动半径
mLeftEyeRadius = Integer.parseInt(NoNull.toString(getParameter("leftEyeRadius"), "15")); // 右眼睛的移动半径
mRightEyeRadius = Integer.parseInt(NoNull.toString(getParameter("rightEyeRadius"), "5")); // 可选参数
if (getParameter("testMode") != null)
mTestMode = Boolean.valueOf(NoNull.toString(getParameter("testMode"), "true"))
.booleanValue(); if (getParameter("horizontalSkew") != null)
mHorizontalSkew = Double.valueOf(
NoNull.toString(getParameter("horizontalSkew"), "13.5")).doubleValue();
if (getParameter("eyeIndependence") != null)
mEyeIndependence = Double.valueOf(
NoNull.toString(getParameter("eyeIndependence"), "0.4")).doubleValue();
if (getParameter("irisRed") != null)
mIrisRed = Integer.parseInt(NoNull.toString(getParameter("irisRed"), "128"));
if (getParameter("irisGreen") != null)
mIrisGreen = Integer.parseInt(NoNull.toString(getParameter("irisGreen"), "64"));
if (getParameter("irisBlue") != null)
mIrisBlue = Integer.parseInt(NoNull.toString(getParameter("irisBlue"), "0"));
mIrisColor = new Color(mIrisRed, mIrisGreen, mIrisBlue);
if (getParameter("verticalOffset") != null)
mVerticalOffset = Integer.parseInt(NoNull.toString(getParameter("verticalOffset"),
"100"));
} catch (Exception e) {
mErrorMessage = "Bad or missing required parameter.";
e.printStackTrace();
} // 计算眼球的移动半径
mLeftPupilTR = mLeftEyeRadius + mIrisRadius - (int) (mGapFactor * mPupilRadius);
mRightPupilTR = mRightEyeRadius + mIrisRadius - (int) (mGapFactor * mPupilRadius); // 侦听鼠标事件
MouseMotion aMouseMotion = new MouseMotion();
this.addMouseMotionListener(aMouseMotion);
this.setSize(400, 135);
} public void paintFrame(Graphics g) {
if (mErrorMessage != null) {
showError(g);
return;
} // 背景面部
g.drawImage(mFace, mFaceX, mFaceY, this); // 画外部的球体
g.setColor(mIrisColor);
g.fillOval(mLeftIrisX - mIrisRadius, mLeftIrisY - mIrisRadius, 2 * mIrisRadius,
2 * mIrisRadius);
g.fillOval(mRightIrisX - mIrisRadius, mRightIrisY - mIrisRadius, 2 * mIrisRadius,
2 * mIrisRadius);
// 画瞳孔
g.setColor(mPupilColor);
g.fillOval(mLeftPupilX - mPupilRadius, mLeftPupilY - mPupilRadius, 2 * mPupilRadius,
2 * mPupilRadius);
g.fillOval(mRightPupilX - mPupilRadius, mRightPupilY - mPupilRadius, 2 * mPupilRadius,
2 * mPupilRadius); if (mTestMode) {
g.drawOval(mLeftEyeX - mLeftEyeRadius, mLeftEyeY - mLeftEyeRadius, 2 * mLeftEyeRadius,
2 * mLeftEyeRadius);
g.drawOval(mRightEyeX - mRightEyeRadius, mRightEyeY - mRightEyeRadius,
2 * mRightEyeRadius, 2 * mRightEyeRadius);
}
} public void mouseMoved() {
// coordinates for the left iris
int leftDX = mMouseX - mLeftEyeX;
int leftDY = mMouseY - mLeftEyeY;
if (leftDY == 0)
leftDY = 1; // prevent divide by zero
double leftDXDY = (double) leftDX / leftDY;
double leftdy = Math.sqrt(Math.pow(mLeftEyeRadius, 2) / (Math.pow(leftDXDY, 2) + 1));
if (leftDY < 0) {
leftdy = -leftdy;
}
double leftdx = leftDXDY * leftdy * mHorizontalSkew; // coordinates for the right iris
int rightDX = mMouseX - mRightEyeX;
int rightDY = mMouseY - mRightEyeY;
if (rightDY == 0)
rightDY = 1; // prevent divide by zero
double rightDXDY = (double) rightDX / rightDY;
double rightdy = Math.sqrt(Math.pow(mRightEyeRadius, 2) / (Math.pow(rightDXDY, 2) + 1));
if (rightDY < 0) {
rightdy = -rightdy;
}
double rightdx = rightDXDY * rightdy * mHorizontalSkew; // adjustments for the irises
double avedx = (rightdx + leftdx) / 2;
double avedy = (rightdy + leftdy) / 2;
leftdx = leftdx + (avedx - leftdx) * (1 - mEyeIndependence);
rightdx = rightdx + (avedx - rightdx) * (1 - mEyeIndependence);
leftdy = leftdy + (avedy - leftdy) * (1 - mEyeIndependence);
rightdy = rightdy + (avedy - rightdy) * (1 - mEyeIndependence);
// new iris positions
mLeftIrisX = mLeftEyeX + (int) leftdx;
mLeftIrisY = mLeftEyeY + (int) leftdy;
mRightIrisX = mRightEyeX + (int) rightdx;
mRightIrisY = mRightEyeY + (int) rightdy; // coordinates for the left pupil
double leftpdy = Math.sqrt(Math.pow(mLeftPupilTR, 2) / (Math.pow(leftDXDY, 2) + 1));
if (leftDY < 0) {
leftpdy = -leftpdy;
}
double leftpdx = leftDXDY * leftpdy * (mHorizontalSkew - mGapFactor); // coordinates for the right pupil
double rightpdy = Math.sqrt(Math.pow(mRightPupilTR, 2) / (Math.pow(rightDXDY, 2) + 1));
if (rightDY < 0) {
rightpdy = -rightpdy;
}
double rightpdx = rightDXDY * rightpdy * (mHorizontalSkew - mGapFactor); // adjustments for the pupils
double avepdx = (rightpdx + leftpdx) / 2;
double avepdy = (rightpdy + leftpdy) / 2;
leftpdx = leftpdx + (avepdx - leftpdx) * (1 - mEyeIndependence);
rightpdx = rightpdx + (avepdx - rightpdx) * (1 - mEyeIndependence);
leftpdy = leftpdy + (avepdy - leftpdy) * (1 - mEyeIndependence);
rightpdy = rightpdy + (avepdy - rightpdy) * (1 - mEyeIndependence); // new pupil positions
mLeftPupilX = mLeftEyeX + (int) leftpdx;
mLeftPupilY = mLeftEyeY + (int) leftpdy;
mRightPupilX = mRightEyeX + (int) rightpdx;
mRightPupilY = mRightEyeY + (int) rightpdy; repaint();
} public void update(Graphics g) {
paint(g);
} public void paint(Graphics g) {
Dimension d = getSize(); // create the offscreen graphics context
if ((mGraphics == null) || (d.width != mDimension.width)
|| (d.height != mDimension.height)) {
mDimension = d;
mImage = createImage(d.width, d.height);
mGraphics = mImage.getGraphics();
} // erase the previous image
mGraphics.setColor(getBackground());
mGraphics.fillRect(0, 0, d.width, d.height);
mGraphics.setColor(Color.black); // paint the frame into the image
paintFrame(mGraphics); // paint the image onto the screen
g.drawImage(mImage, 0, 0, null);
} class MouseMotion extends java.awt.event.MouseMotionAdapter {
public void mouseMoved(java.awt.event.MouseEvent event) {
Object object = event.getSource();
if (object == Eye.this)
mouseMovedInApplet(event);
}
} void mouseMovedInApplet(java.awt.event.MouseEvent event) {
// get the mouse coords
mMouseX = event.getX();
mMouseY = event.getY();
mouseMoved();
} public void mouseMovedInBrowser(int x, int y, int windowWidth) {
int appletW = getSize().width; // adjust mouse x and y relative to applet position
mMouseX = x - (windowWidth - appletW) / 2;
mMouseY = y - mVerticalOffset;
mouseMoved();
} private void showError(Graphics g) {
g.setFont(new Font("TimesRoman", Font.BOLD, 12));
g.drawString(mErrorMessage, 10, 20);
}
} 

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持

最新2021整理收集的一些高频面试题(都整理成文档),有很多干货,包含mysql,netty,spring,线程,spring cloud、jvm、源码、算法等详细讲解,也有详细的学习规划图,面试题整理等,需要获取这些内容的朋友请加Q君羊:547998459

瞧一瞧看一看啦“一段眼睛跟着鼠标转动的跟踪眼代码”相关推荐

  1. 我睁大了眼睛向四周瞧一瞧

    再把面放进去的火车 今天的再把面放进去的火车,如绸带舞跃于音符,然后加入少量80度-95度的热水,这样可以让调味料溶化,我睁大了眼睛向四周瞧一瞧,演奏完毕,摇摇头的自言自语道,那位美女成了我的新主人, ...

  2. 论文解读 | 微信看一看实时Look-alike推荐算法

    作者丨gongyouliu 编辑丨lily 来源 | 授权转载自大数据与人工智能(ID:ai-big-data) 微信看一看的精选文章推荐(见下面图1)大家应该都用过,微信团队在今年发表了一篇文章来专 ...

  3. Scrum模拟微信看一看“疫情专区”的敏捷开发过程

    无论作为产品用户还是管理咨询顾问,都非常非常喜欢微信.自认感情比较克制属于"高冷"挂,但从很多方面都太佩服太崇拜张小龙了(新书里微信也会是最喜欢的案例之一,真的不只是一个产品而已, ...

  4. 第一款鸿蒙摄像头,随时随地看一看!华为首款鸿蒙智能摄像头发布

    原标题:随时随地看一看!华为首款鸿蒙智能摄像头发布 当我们进入科技飞速发展的时代,越来越多的角落开始布控了一些摄像装置.截止到如今,不仅仅在一些公共死角位置安排了电子猫眼,一些养了宠物的年轻人也在家中 ...

  5. 深度学习核心技术精讲100篇(四十)-微信“看一看“内容理解与推荐,背后深层次的技术知多少?

    前言 相信对于不少人而言微信已经成为获取资讯的主要场景.与此同时,由于微信用户群体的庞大,也吸引了大量的内容生产者在微信公众平台创造内容,以获取用户关注.点赞.收藏等.微信内的内容推荐产品:看一看应运 ...

  6. 特斯拉马斯克直聘AI人才:不看学历看能力

    特斯拉马斯克直聘AI人才:不看学历看能力 火,大火,太火了. 这就是特斯拉2020年以来的股价趋势.在最新一轮暴涨后,马斯克都忍不住祭出"大火"表情包,庆祝市值创下新高--1400 ...

  7. php关键词分词搜索 最多匹配的排在最前面_百度搜索引擎工作原理,做Seo的建议看一看 - 蜘蛛池博客...

    原出处:蜘蛛池博客 原文链接:百度搜索引擎工作原理,做Seo的建议看一看 - 蜘蛛池博客 从事SEO(搜索引擎优化)工作的人可以比喻成搜索引擎的贴身管家,作为一名合格称职的管家必须要了解所服务对象的习 ...

  8. 揭秘微信「看一看」如何精准挖掘你感兴趣的内容

    作者:maricoliao,腾讯 WXG 应用研究员 一.背景 随着自媒体时代的蓬勃发展,各类自媒体平台每天涌现出海量信息.微信作为最优质的自媒体平台,每天新发表文章数百万篇.汹涌而来的信息,极大地丰 ...

  9. 20岁以后的男人应该知道的一些事,看一看吧

    酒吧认识的女人,多半就没有必要再留电话了. 2喝酒喝好,不代表喝完吐吐完喝,在量上占个老 3告别网恋吧,相比之下家人介绍的对象还是可以看看,必竟知根知底比较把握,少走弯路. 4周末有带情人泡午夜场的钱 ...

最新文章

  1. Python如何优化列表接口进行分页
  2. 详解:基于nginx tcp模块基本配置
  3. Windows窗体的所有菜单
  4. Spring AOP概念理解 (通俗易懂)【转】
  5. Kafka#4:存储设计 分布式设计 源码分析
  6. apache lucene_Apache Lucene中的并发查询执行
  7. 外星人跑深度学习_上海港汇外星人店,51M2020开光追和DLSS2.0畅玩《赛博朋克2077》...
  8. [导入]画带阴影效果的文字
  9. html中怎么在横线中加字_传说中仓颉造字,汉字是怎么演变来的?
  10. python字典调用_python 字典访问的三种方法
  11. git 入门操作指令
  12. FISCO BCOS共识优化之路
  13. 《Python核心编程》第二版第八章练习题答案 第三部分
  14. 手机怎么更改ip地址
  15. 如何提高技术团队的工作效率
  16. 我们无法设置移动热点_支付宝微信设置了密码,为何超市扫码枪能将钱扫走?多数人不了解...
  17. ojdbc连接oracle报错:IO 错误: The Network Adapter could not establish the connection
  18. Apache FTPServer本地部署FTP服务
  19. IOl流的分类与使用
  20. KMeans算法的Mapreduce实现

热门文章

  1. gitlab self-hosted server
  2. ie显示服务器拒接链接,IE浏览器拒接访问是怎么回事 IE浏览器显示拒接访问的有效解决方法...
  3. C# Format详解
  4. 函数定义涉及的三要素C语言,c语言函数的调用
  5. hdu1576 A/B
  6. Creator打android包时报Could not resolve all files for configuration ':jcore-react-native:lintClassPath'异
  7. 卡塔尔世界杯:带“芯片”的智能足球亮相!背后藏着哪些技术原理?
  8. macOS配置MAVEN环境变量执行source .bash_profile报错.bash_profile: not valid in this context: /xxx/xxx
  9. gimp: 如何透明化背景
  10. HDMI端口辐射(EMI)超标解决方案