javascript - p5.js 嵌套 For 循环不迭代
问题描述
我正在尝试为音乐可视化项目创建一些测量声音频率的音阶。它们旨在以 2x2 网格模式显示 4 个不同的频率(低音、低中、高中和高音)。我快到了我有我的矩形,但测量和显示频率本身的指针仅针对顶行 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();
};
解决方案
推荐阅读
- angular - ionic cordovar - 启动后未定义自定义组件
- python - Keras 问题与 3d 张量的前 k 个分类精度
- javascript - 动态渲染 vue 模板
- laravel - 配置仅在配置发布时加载
- java - 如何使用 pdfbox 修复“定义签名数据范围的意外字节范围值”
- aem - Adobe AEM 6.4.x:如何限制可以在页面上添加哪些组件(使用静态模板)?
- java - 具有一个命名空间和本地部分的多个 SOAP 端点
- c# - 如何从 SQLite 数据库的新记录中获取具有 char 数据类型的字段,它也由使用 dapper + c# 的触发器生成
- jquery - 如何在 jQuery 对象中使用“自我”?
- jquery - 使用 JQuery 构建选项卡