p5.j​​s嵌套For循环未迭代

时间:2020-05-15 04:23:59

标签: javascript for-loop nested p5.js

我正在尝试为音乐可视化器项目创建一些测量声频的音阶。它们旨在以2x2网格模式显示4个不同的频率(低音,lowMid,highMid和高音)。我几乎在那里,我有矩形,但是测量并显示频率本身的指针仅针对顶部x和不是最底下的一行。我对JavaScript还是很陌生,所以我敢肯定我可能会很简单地丢失它。

    // draw the plots to the screen
    this.draw = function() {
        //create an array amplitude values from the fft.
        var spectrum = fourier.analyze();
        //iterator for selecting frequency bin.
        var currentBin = 0;
        push();
        fill('#f0f2d2');
        //nested for loop to place plots in 2*2 grid.
        for(var i = 0; i < this.plotsDown; i++) {
            for(var j = 0; j < this.plotsAcross; j++) {

                //calculate the size of the plots
                var x = this.pad * j * 10;
                var y = height/20 * i * 10;
                var w = (width - this.pad) / this.plotsAcross;
                var h = (height - this.pad) / this.plotsDown;

                //draw a rectangle at that location and size
                rect(x, y, w, h);

                //add on the ticks
                this.ticks((x + w/2), h, this.frequencyBins[i])

                var energy = fourier.getEnergy(this.frequencyBins[currentBin]);

                //add the needle
                this.needle(energy, (x + w/2), h)

                currentBin++;
            }
        }

        pop();
    };

0 个答案:

没有答案
相关问题