package com.gitee.drinkjava2.frog.brain;
import static java.awt.Color.BLACK;
import static java.awt.Color.RED;
import static java.awt.Color.WHITE;
import static java.lang.Math.cos;
import static java.lang.Math.round;
import static java.lang.Math.sin;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
import javax.swing.JPanel;
import com.gitee.drinkjava2.frog.Animal;
import com.gitee.drinkjava2.frog.Application;
import com.gitee.drinkjava2.frog.Env;
import com.gitee.drinkjava2.frog.util.ColorUtils;
import com.gitee.drinkjava2.frog.util.Tree8Util;
/**
* BrainPicture show first frog's brain structure, for debug purpose only
*
* 这个类用来画出脑图,这不是一个关键类,对脑的运行逻辑无影响,但有了脑图后可以直观地看出脑的3维结构,进行有针对性的改进
* 可以用鼠标进行平移、缩放、旋转,以及t、f、l、r,x五个键来选择顶视、前视、左视、右视、斜视这5个方向的视图,以及空格暂停、方向键调整切面
* 鼠标的动作定义在MouseAction类中。
*
* @author Yong Zhu
* @since 1.0
*/
@SuppressWarnings("all")
public class BrainPicture extends JPanel {
private static final long serialVersionUID = 1L;
private static final float D90 = (float) (Math.PI / 2);
Color picColor = RED;
int brainDispWidth; // screen display piexls width
float scale; // brain scale
int xOffset = 0; // brain display x offset compare to screen
int yOffset = 0; // brain display y offset compare to screen
float xAngle = D90 * .8f; // brain rotate on x axis
float yAngle = D90 / 4; // brain rotate on y axis
float zAngle = 0;// brain rotate on z axis
int xMask = -1;// x Mask
int yMask = -1;// y Mask
BufferedImage buffImg;
Graphics g;
String note;
public KeyAdapter keyAdapter;
public BrainPicture(int x, int y, float brainWidth, int brainDispWidth) {
super();
this.setLayout(null);// 空布局
this.brainDispWidth = brainDispWidth;
scale = 0.5f * brainDispWidth / brainWidth;
this.setBounds(x, y, brainDispWidth + 1, brainDispWidth + 1);
buffImg = new BufferedImage(Env.FROG_BRAIN_DISP_WIDTH, Env.FROG_BRAIN_DISP_WIDTH, BufferedImage.TYPE_INT_RGB);
g = buffImg.getGraphics();
MouseAction act = new MouseAction(this);
this.addMouseListener(act); // 添加鼠标动作监听
this.addMouseWheelListener(act);// 添加鼠标滚轮动作监听
this.addMouseMotionListener(act);// 添加鼠标移动动作监听
keyAdapter = new KeyAdapter() {// 处理t,f,l,r,x键盘命令
@Override
public void keyPressed(KeyEvent e) {
switch (e.getKeyCode()){
case KeyEvent.VK_UP:// Y切面向上
yMask++;
if (yMask > Env.BRAIN_SIZE)
yMask = Env.BRAIN_SIZE;
break;
case KeyEvent.VK_DOWN:// Y切面向下
yMask--;
if (yMask < 0)
yMask = 0;
break;
case KeyEvent.VK_LEFT:// x切面向左
xMask--;
if (xMask < 0)
xMask = 0;
break;
case KeyEvent.VK_RIGHT:// x切面向右
xMask++;
if (xMask > Env.BRAIN_SIZE)
xMask = Env.BRAIN_SIZE;
break;
case ' ':// 暂停及继续
Application.pauseAction.actionPerformed(null);
break;
case 'T':// 顶视
xAngle = 0;
yAngle = 0;
zAngle = 0;
break;
case 'F':// 前视
xAngle = D90;
yAngle = 0;
zAngle = 0;
break;
case 'L':// 左视
xAngle = D90;
yAngle = D90;
zAngle = 0;
break;
case 'R':// 右视
xAngle = D90;
yAngle = -D90;
zAngle = 0;
break;
case 'X':// 斜视
xAngle = D90 * .8f;
yAngle = D90 / 4;
zAngle = 0;
break;
default:
}
}
};
addKeyListener(keyAdapter);
this.setFocusable(true);
}
public void drawCuboid(float x, float y, float z, float xe, float ye, float ze) {// 在脑图上画一个长立方体框架,视角是TopView
drawLine(x, y, z, x + xe, y, z);// 画立方体的下面边
drawLine(x + xe, y, z, x + xe, y + ye, z);
drawLine(x + xe, y + ye, z, x, y + ye, z);
drawLine(x, y + ye, z, x, y, z);
drawLine(x, y, z, x, y, z + ze);// 画立方体的中间边
drawLine(x + xe, y, z, x + xe, y, z + ze);
drawLine(x + xe, y + ye, z, x + xe, y + ye, z + ze);
drawLine(x, y + ye, z, x, y + ye, z + ze);
drawLine(x, y, z + ze, x + xe, y, z + ze);// 画立方体的上面边
drawLine(x + xe, y, z + ze, x + xe, y + ye, z + ze);
drawLine(x + xe, y + ye, z + ze, x, y + ye, z + ze);
drawLine(x, y + ye, z + ze, x, y, z + ze);
}
public void drawCentLine(float px1, float py1, float pz1, float px2, float py2, float pz2) {//从细胞中点之间画一条线
drawLine(px1 + 0.5f, py1 + 0.5f, pz1 + 0.5f, px2 + 0.5f, py2 + 0.5f, pz2 + 0.5f);
}
/*-
画线,固定以top视角的角度,所以只需要从x1,y1画一条到x2,y2的直线
绕 x 轴旋转 θ
x, y.cosθ-zsinθ, y.sinθ+z.cosθ
绕 y 轴旋转 θ
z.sinθ+x.cosθ, y, z.cosθ-x.sinθ
绕 z 轴旋转 θ
x.cosθ-y.sinθ, x.sinθ+y.consθ, z
-*/
public void drawLine(float px1, float py1, float pz1, float px2, float py2, float pz2) {
double x1 = px1 - Env.BRAIN_SIZE / 2;
double y1 = -py1 + Env.BRAIN_SIZE / 2;// 屏幕的y坐标是反的,显示时要正过来
double z1 = pz1 - Env.BRAIN_SIZE / 2;
double x2 = px2 - Env.BRAIN_SIZE / 2;
double y2 = -py2 + Env.BRAIN_SIZE / 2;// 屏幕的y坐标是反的,显示时要正过来
double z2 = pz2 - Env.BRAIN_SIZE / 2;
x1 = x1 * scale;
y1 = y1 * scale;
z1 = z1 * scale;
x2 = x2 * scale;
y2 = y2 * scale;
z2 = z2 * scale;
double x, y, z;
y = y1 * cos(xAngle) - z1 * sin(xAngle);// 绕x轴转
z = y1 * sin(xAngle) + z1 * cos(xAngle);
y1 = y;
z1 = z;
x = z1 * sin(yAngle) + x1 * cos(yAngle);// 绕y轴转
// z = z1 * cos(yAngle) - x1 * sin(yAngle);
x1 = x;
// z1 = z;
x = x1 * cos(zAngle) - y1 * sin(zAngle);// 绕z轴转
y = x1 * sin(zAngle) + y1 * cos(zAngle);
x1 = x;
y1 = y;
y = y2 * cos(xAngle) - z2 * sin(xAngle);// 绕x轴转
z = y2 * sin(xAngle) + z2 * cos(xAngle);
y2 = y;
z2 = z;
x = z2 * sin(yAngle) + x2 * cos(yAngle);// 绕y轴转
// z = z2 * cos(yAngle) - x2 * sin(yAngle);
x2 = x;
// z2 = z;
x = x2 * cos(zAngle) - y2 * sin(zAngle);// 绕z轴转
y = x2 * sin(zAngle) + y2 * cos(zAngle);
x2 = x;
y2 = y;
g.setColor(picColor);
g.drawLine((int) round(x1) + Env.FROG_BRAIN_DISP_WIDTH / 2 + xOffset, (int) round(y1) + Env.FROG_BRAIN_DISP_WIDTH / 2 + yOffset, (int) round(x2) + Env.FROG_BRAIN_DISP_WIDTH / 2 + xOffset,
(int) round(y2) + Env.FROG_BRAIN_DISP_WIDTH / 2 + yOffset)
没有合适的资源?快使用搜索试试~ 我知道了~
人工生命-人工智能人工生命-人工智能
共915个文件
java:686个
bat:105个
license:27个
需积分: 1 0 下载量 82 浏览量
2024-09-17
07:31:19
上传
评论
收藏 6.42MB ZIP 举报
温馨提示
“” 人工智能 人工智能 人工智能 人工智能 人工智能
资源推荐
资源详情
资源评论
收起资源包目录
人工生命-人工智能人工生命-人工智能 (915个子文件)
run.bat 105B
run.bat 105B
run.bat 101B
run.bat 101B
run.bat 101B
run.bat 101B
run.bat 101B
run.bat 100B
run.bat 100B
run.bat 100B
run.bat 100B
run.bat 100B
run.bat 100B
run.bat 100B
run.bat 100B
run.bat 100B
run.bat 100B
run.bat 100B
run.bat 100B
run.bat 100B
run.bat 100B
run.bat 100B
run.bat 100B
run.bat 100B
run.bat 100B
run.bat 100B
maven_eclipse_eclipse.bat 35B
maven_eclipse_eclipse.bat 35B
maven_eclipse_eclipse.bat 35B
maven_eclipse_eclipse.bat 35B
maven_eclipse_eclipse.bat 35B
maven_eclipse_eclipse.bat 35B
maven_eclipse_eclipse.bat 35B
maven_eclipse_eclipse.bat 35B
maven_eclipse_eclipse.bat 35B
maven_eclipse_eclipse.bat 35B
maven_eclipse_eclipse.bat 35B
maven_eclipse_eclipse.bat 35B
maven_eclipse_eclipse.bat 35B
maven_eclipse_eclipse.bat 35B
maven_eclipse_eclipse.bat 35B
maven_eclipse_eclipse.bat 35B
maven_eclipse_eclipse.bat 35B
maven_eclipse_eclipse.bat 35B
maven_eclipse_eclipse.bat 35B
maven_eclipse_eclipse.bat 35B
maven_eclipse_eclipse.bat 35B
maven_eclipse_eclipse.bat 35B
maven_eclipse_eclipse.bat 35B
maven_eclipse_eclipse.bat 35B
maven_eclipse_eclipse.bat 35B
maven_eclipse_eclipse.bat 35B
maven_eclipse_clean.bat 17B
maven_eclipse_clean.bat 17B
maven_eclipse_clean.bat 17B
maven_eclipse_clean.bat 17B
maven_eclipse_clean.bat 17B
maven_eclipse_clean.bat 17B
maven_eclipse_clean.bat 17B
maven_eclipse_clean.bat 17B
maven_eclipse_clean.bat 17B
maven_eclipse_clean.bat 17B
maven_eclipse_clean.bat 17B
maven_eclipse_clean.bat 17B
maven_eclipse_clean.bat 17B
maven_eclipse_clean.bat 17B
maven_eclipse_clean.bat 17B
maven_eclipse_clean.bat 17B
maven_eclipse_clean.bat 17B
maven_eclipse_clean.bat 17B
maven_eclipse_clean.bat 17B
maven_eclipse_clean.bat 17B
maven_eclipse_clean.bat 17B
maven_eclipse_clean.bat 17B
maven_eclipse_clean.bat 17B
maven_eclipse_clean.bat 17B
maven_eclipse_clean.bat 17B
maven_eclipse_clean.bat 17B
maven_clean.bat 9B
maven_clean.bat 9B
maven_clean.bat 9B
maven_clean.bat 9B
maven_clean.bat 9B
maven_clean.bat 9B
maven_clean.bat 9B
maven_clean.bat 9B
maven_clean.bat 9B
maven_clean.bat 9B
maven_clean.bat 9B
maven_clean.bat 9B
maven_clean.bat 9B
maven_clean.bat 9B
maven_clean.bat 9B
maven_clean.bat 9B
maven_clean.bat 9B
maven_clean.bat 9B
maven_clean.bat 9B
maven_clean.bat 9B
maven_clean.bat 9B
maven_clean.bat 9B
共 915 条
- 1
- 2
- 3
- 4
- 5
- 6
- 10
资源评论
csbysj2020
- 粉丝: 2172
- 资源: 5358
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 一个基于 Spring Boot 的RESTful API项目示例:图书管理系统
- 算法设计北航童咏昕老师-最长公共子序列问题(动态规划)C语言实现
- 一个基于QT + ffpemg仿网易云UI的音乐播放器项目,支持桌面歌词
- DIB(Deep Image Blending)是一种深度学习技术,用于将多个图像融合在一起,生成高质量的合成图像
- foc,stm32代码aaaaaa
- 蓝牙定位前端111111111111111111111
- 一个简单的用户会话管理系统 这个项目将展示如何使用 Redis 来存储和管理用户的会话信息
- 自动截图工具,自由设定路径,间隔时间,区域
- Unity 是一个非常流行的游戏开发引擎,支持多平台发布,包括 PC、移动设备、游戏主机等
- X2000项目实战入门大纲
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功