Add CellTemplate

pull/1/head
Yong Zhu 5 years ago
parent fcb7c8aba9
commit db02ef0f7d

@ -1,4 +1,4 @@
## Frog | 人工生命 ## Frog | 人工生命
这是一个人工生命试验项目最终目标是创建“有自我意识表现”的模拟生命体技术架构基于02年提出的 [一个人工脑模型](一个人工脑模型.md)。 这是一个人工生命试验项目最终目标是创建“有自我意识表现”的模拟生命体技术架构基于02年提出的 [一个人工脑模型](一个人工脑模型.md)。
这个项目永远没有结束的时候,开始于模拟一个简单的生命体,然后是青蛙、狗......, 结束于有“自我意识表现”的人工脑,或者说,结束于被机器人代替人类的那一天。 这个项目永远没有结束的时候,开始于模拟一个简单的生命体,然后是青蛙、狗......, 结束于有“自我意识表现”的人工脑,或者说,结束于被机器人代替人类的那一天。

@ -78,6 +78,21 @@
<encoding>UTF-8</encoding> <encoding>UTF-8</encoding>
</configuration> </configuration>
</plugin> </plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.2</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<useUniqueVersions>false</useUniqueVersions>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>com.github.drinkjava2.frog.Application</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins> </plugins>
</build> </build>

@ -0,0 +1,2 @@
mvn clean package
java -jar target/frog-*.jar

@ -78,10 +78,25 @@
<encoding>UTF-8</encoding> <encoding>UTF-8</encoding>
</configuration> </configuration>
</plugin> </plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.2</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<useUniqueVersions>false</useUniqueVersions>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>com.github.drinkjava2.frog.Application</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins> </plugins>
</build> </build>
<profiles> <profiles>
</profiles> </profiles>
</project> </project>

@ -0,0 +1,2 @@
mvn clean package
java -jar target/frog-*.jar

@ -32,7 +32,6 @@ public class BrainPicture extends JPanel {
Color color = Color.red; Color color = Color.red;
int brainDispWidth; // screen display piexls width int brainDispWidth; // screen display piexls width
float scale; // brain scale float scale; // brain scale
int pointDia; // point size
int xOffset = 0; // brain display x offset compare to screen int xOffset = 0; // brain display x offset compare to screen
int yOffset = 0; // brain display y offset compare to screen int yOffset = 0; // brain display y offset compare to screen
float xAngle = (float) (Math.PI / 2.5); // brain rotate on x axis float xAngle = (float) (Math.PI / 2.5); // brain rotate on x axis
@ -44,7 +43,6 @@ public class BrainPicture extends JPanel {
this.setLayout(null);// 空布局 this.setLayout(null);// 空布局
this.brainDispWidth = brainDispWidth; this.brainDispWidth = brainDispWidth;
scale = 0.7f * brainDispWidth / brainWidth; scale = 0.7f * brainDispWidth / brainWidth;
pointDia = Math.max(Math.round(scale), 1);
this.setBounds(x, y, brainDispWidth + 1, brainDispWidth + 1); this.setBounds(x, y, brainDispWidth + 1, brainDispWidth + 1);
MouseAction act = new MouseAction(this); MouseAction act = new MouseAction(this);
this.addMouseListener(act); this.addMouseListener(act);
@ -141,7 +139,7 @@ public class BrainPicture extends JPanel {
/** 画点固定以top视角的角度所以只需要在x1,y1位置画一个点 */ /** 画点固定以top视角的角度所以只需要在x1,y1位置画一个点 */
public void drawCubeCenter(float x, float y, float z) { public void drawCubeCenter(float x, float y, float z) {
drawPoint(x + 0.5f, y + 0.5f, z + 0.5f, pointDia); drawPoint(x + 0.5f, y + 0.5f, z + 0.5f, (int) Math.max(1, Math.round(scale * .7)));
} }
/** 画点固定以top视角的角度所以只需要在x1,y1位置画一个点 */ /** 画点固定以top视角的角度所以只需要在x1,y1位置画一个点 */
@ -183,7 +181,7 @@ public class BrainPicture extends JPanel {
return rainbow[nextColor++]; return rainbow[nextColor++];
} }
public static Color rainboColor(float i) { public static Color rainbowColor(float i) {
if (i == 0) if (i == 0)
return Color.black; return Color.black;
if (i == 1) if (i == 1)
@ -224,8 +222,8 @@ public class BrainPicture extends JPanel {
for (int y = 0; y < Env.FROG_BRAIN_YSIZE; y++) { for (int y = 0; y < Env.FROG_BRAIN_YSIZE; y++) {
if (f.cubes[x][y] != null) if (f.cubes[x][y] != null)
for (int z = 0; z < Env.FROG_BRAIN_ZSIZE; z++) { for (int z = 0; z < Env.FROG_BRAIN_ZSIZE; z++) {
if (f.existCube(x, y, z)) { if (f.existCube(x, y, z) && f.getCube(x, y, z).getActive()>0) {
setColor(rainboColor(f.getCube(x, y, z).getActive())); setColor(rainbowColor(f.getCube(x, y, z).getActive()));
drawCubeCenter(x, y, z); drawCubeCenter(x, y, z);
} }
} }

@ -13,14 +13,18 @@ package com.github.drinkjava2.frog.brain;
/** /**
* Cell is the basic unit of frog's brain * Cell is the basic unit of frog's brain
* *
* Cell便()CellTemplate
* type Cell
*
* @author Yong Zhu * @author Yong Zhu
* @since 1.0 * @since 2.0.2
*/ */
public class Cell { public class Cell {
public byte cellType; // 这个细胞的类型 public int type; // 这个细胞的类型见CellTemplate类中的type
// energy of cell, energy got from food // energy of cell, energy got from food
public float energy; // 每个细胞当前的能量值 public float energy; // 每个细胞当前的能量值
public float tire; // 每个细胞的疲劳值
public float tire; // 每个细胞的疲劳值,只取决于最近的激活频率
} }

@ -0,0 +1,59 @@
/*
* Copyright 2018 the original author or authors.
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by
* applicable law or agreed to in writing, software distributed under the
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
* OF ANY KIND, either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package com.github.drinkjava2.frog.brain;
import java.io.Serializable;
import com.github.drinkjava2.frog.Frog;
/**
* CellTemplate is the cell template, a group of CellTemplate be saved in egg
*
* CellTemplate
* cellType
* CellTemplateCellTemplate
* typeCellTemplate cell
*
*
*
* @author Yong Zhu
* @since 2.0.2
*/
public class CellTemplate implements Serializable {
private static final long serialVersionUID = 1L;
public int type; // 当创建CellType实例
public Synapse[] inputs; // 输入触突,位置是相对细胞而言的
public Synapse[] sides; // 侧面(通常是抑制,是负光子输出)输出触突们,才从脉冲神经网络了解到有这种侧向抑制
public Synapse[] outputs; // 输出触突
/**
* Each cell's act method will be called once at each loop step
*
* act
*
*/
public void act(Frog f, Cell cell, int x, int y, int z) {
switch (type) { // TODO 待添加细胞的行为,这是硬编码
case 0:
break;
case 1:
break;
case 2:
break;
case 3:
break;
case 4:
break;
default:
break;
}
}
}

@ -43,10 +43,15 @@ public class MouseAction implements MouseListener, MouseWheelListener, MouseMoti
@Override @Override
public void mouseWheelMoved(MouseWheelEvent e) {// 缩放 public void mouseWheelMoved(MouseWheelEvent e) {// 缩放
if (e.getWheelRotation() < 0) if (e.getWheelRotation() < 0) {
brainPic.scale *= 1.1; brainPic.scale *= 1.1;
else brainPic.xOffset *= 1.1;
brainPic.yOffset *= 1.1;
} else {
brainPic.scale /= 1.1; brainPic.scale /= 1.1;
brainPic.xOffset /= 1.1;
brainPic.yOffset /= 1.1;
}
} }
@Override @Override
@ -71,13 +76,13 @@ public class MouseAction implements MouseListener, MouseWheelListener, MouseMoti
} }
if (buttonPressed == 2) {// 平移 if (buttonPressed == 2) {// 平移
if (e.getX() > x) if (e.getX() > x)
brainPic.xOffset+=6; brainPic.xOffset += 6;
if (e.getX() < x) if (e.getX() < x)
brainPic.xOffset-=6; brainPic.xOffset -= 6;
if (e.getY() > y) if (e.getY() > y)
brainPic.yOffset+=6; brainPic.yOffset += 6;
if (e.getY() < y) if (e.getY() < y)
brainPic.yOffset-=6; brainPic.yOffset -= 6;
x = e.getX(); x = e.getX();
y = e.getY(); y = e.getY();
} }

@ -0,0 +1,29 @@
/*
* Copyright 2018 the original author or authors.
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by
* applicable law or agreed to in writing, software distributed under the
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
* OF ANY KIND, either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package com.github.drinkjava2.frog.brain;
import java.io.Serializable;
/**
* Synapse can be input, output, side synapse
*
*
*
* @author Yong Zhu
* @since 2.0.2
*/
public class Synapse implements Serializable {
private static final long serialVersionUID = 1L;
public int x; // 这个触突相对于细胞的x偏移坐标
public int y;// 这个触突相对于细胞的y偏移坐标
public int z;// 这个触突相对于细胞的z偏移坐标
public int r; // 这个触突的作用范围
}

@ -53,21 +53,22 @@ public class StringPixelUtils {
for (int y = 0; y < strHeight; y++) for (int y = 0; y < strHeight; y++)
for (int x = 0; x < strWidth; x++) for (int x = 0; x < strWidth; x++)
if (bi.getRGB(x, y) == -1) if (bi.getRGB(x, y) == -1)
b[x][strHeight-y-1] = 1; b[x][strHeight - y - 1] = 1;
else else
b[x][strHeight-y-1] = 0; b[x][strHeight - y - 1] = 0;
lettersMap.put(key, b); lettersMap.put(key, b);
return b; return b;
} }
/*-
public static void main(String[] args) { public static void main(String[] args) {
byte[][] c = getStringPixels(Font.SANS_SERIF, Font.PLAIN, 12, "Test点阵输出"); byte[][] c = getStringPixels(Font.SANS_SERIF, Font.PLAIN, 12, "Test点阵输出");
int w = c.length; int w = c.length;
int h = c[0].length; int h = c[0].length;
for (int y = 0; y < h; y++) { for (int y = 0; y < h; y++) {
for (int x = 0; x < w; x++) { for (int x = 0; x < w; x++) {
if (c[x][h-y-1]>0) if (c[x][h - y - 1] > 0)
System.out.print("*"); System.out.print("*");
else else
System.out.print(" "); System.out.print(" ");
@ -75,4 +76,5 @@ public class StringPixelUtils {
System.out.println(); System.out.println();
} }
} }
*/
} }

Binary file not shown.

@ -5,6 +5,7 @@ wangtao
dotao dotao
LongFer LongFer
张老湿 张老湿
王二麻子
目前收入总额:98.88元 目前收入总额:108.88元
目前支出总额:0元 目前支出总额:0元
Loading…
Cancel
Save