简体   繁体   English

将一系列Cellular Automata数据翻转为乐谱(例如WolframTones)

[英]Flip an array of Cellular Automata data into a music score (like WolframTones)

Ok, so using some basic principles of Cellular Automata, I've managed to get a program running which generates a set of data calculated from rules. 好的,因此,使用“细胞自动机”的一些基本原理,我设法使一个程序运行,该程序生成根据规则计算出的一组数据。 Each cell is a boolean. 每个单元格都是一个布尔值。

Currently I am storing it as so - boolean[][] data - where the first index is the row and the second is the cell. 目前,我将其存储为boolean [] []数据-第一个索引是行,第二个索引是单元格。

Now I have gotten up to the point where I would like to convert that music into a score (stored as an array). 现在,我想把音乐转换成乐谱(存储为数组)。 On the page it shows a diagram of how it would be converted from CA data - 页面上 ,该图显示了如何从CA数据进行转换的图表-

资源

to score data 评分数据

目标

I have trouble understanding how this would be done progmatically using my storage scheme. 我很难理解如何使用我的存储方案进行编程。 If anyone could help that would be great, I can provide more info if necessary. 如果有人可以帮助您,那将非常有用,如有必要,我可以提供更多信息。

The mapping looks straight forward: 映射看起来很直接:

target[x, y] = source[OFFSET - y, x]

where OFFSET is the index of the last row to copy ( 33 if I counted right). 其中OFFSET是要复制的最后一行的索引(如果我计算正确,则为33 )。

Your implementation could just use two nested loops to copy the array. 您的实现可以只使用两个嵌套循环来复制数组。


EDIT: 编辑:

This is what your converter could look like: 这是您的转换器的外观:

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;
    }
}

This is the output of the test-code below (original array and the transformed array) using an offset of 2 (the first two lines are omitted) and a width of 7 (seven columns are transformed): 这是下面的测试代码(原始数组和转换后的数组)的输出,使用偏移量2 (省略了前两行)和宽度7 (转换了七列):

     █     
    ███    
   ██  █   
  ██ ████  
 ██  █   █ 
██ ████ ███

   █ █
  ██  
 █ █ █
██ ███
 ██  █
  ██ █
   ██ 

The test-code is to convert the String-definition of the source-array and to output the array-content: 测试代码是要转换源数组的字符串定义并输出数组内容:

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();
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM