作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
好的,所以使用元胞自动机的一些基本原理,我设法让一个程序运行,该程序生成一组根据规则计算的数据。每个单元格都是一个 boolean 值。
目前我将其存储为 - boolean[][] 数据 - 其中第一个索引是行,第二个是单元格。
现在我已经到了想将音乐转换为乐谱(存储为数组)的地步。在 the page它显示了如何从 CA 数据转换的图表 -
给数据打分
我很难理解如何使用我的存储方案以编程方式完成此操作。如果有人可以提供帮助,那就太好了,如有必要,我可以提供更多信息。
最佳答案
映射看起来很简单:
target[x, y] = source[OFFSET - y, x]
OFFSET
是
的索引最后 要复制的行(
33
如果我数对了)。
public class Converter
{
public static boolean[][] convert(boolean[][] source, int offset, int width)
{
final boolean[][] target = new boolean[width][source.length];
for(int targetRow=0 ; targetRow<width ; targetRow++)
{
for(int targetCol=0 ; targetCol<source.length ; targetCol++)
{
target[targetRow][targetCol] = source[targetCol][offset + width-1 - targetRow];
}
}
return target;
}
}
2
(前两行省略),宽度为
7
(七列被转换):
█
███
██ █
██ ████
██ █ █
██ ████ ███
█ █
██
█ █ █
██ ███
██ █
██ █
██
public class ConverterTest
{
private final static int OFFSET = 2;
private final static int WIDTH = 7;
private static final String[] sourceString = {
" █ ",
" ███ ",
" ██ █ ",
" ██ ████ ",
" ██ █ █ ",
"██ ████ ███",
};
public static void main(String[] args)
{
final boolean[][] source = getSourceArray();
printArray(source);
final boolean[][] target = Converter.convert(source, OFFSET, WIDTH);
printArray(target);
}
private static boolean[][] getSourceArray()
{
final boolean[][] sourceArray = new boolean[sourceString.length][sourceString[0].length()];
for(int row=0 ; row<sourceString.length ; row++)
{
for(int col=0 ; col<sourceString[0].length() ; col++)
{
sourceArray[row][col] = (sourceString[row].charAt(col) != ' ');
}
}
return sourceArray;
}
private static void printArray(boolean[][] arr)
{
for(int row=0 ; row<arr.length ; row++)
{
for(int col=0 ; col<arr[0].length ; col++)
{
System.out.print(arr[row][col] ? '█' : ' ');
}
System.out.println();
}
System.out.println();
}
}
关于java - 将元胞自动机数据数组翻转为乐谱(如 WolframTones),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9887192/
好的,所以使用元胞自动机的一些基本原理,我设法让一个程序运行,该程序生成一组根据规则计算的数据。每个单元格都是一个 boolean 值。 目前我将其存储为 - boolean[][] 数据 - 其中第
我是一名优秀的程序员,十分优秀!