Jay*_*lor 3 javascript console json console.log
我正在使用 p5.js 和 Kinectron 让一台服务器计算机通过 LAN 显示来自另一台计算机的 RGB、深度和骨架数据,并且它是自己的 kinect。
使用 p5.js,我试图将两个不同的变量记录到控制台,但我只能记录其中一个变量。
代码:
...
function drawJoint(joint) {
fill(100);
console.log( "kinect1" + joint);
// Kinect location data needs to be normalized to canvas size
ellipse( ( joint.depthX * 300 ) + 400 , joint.depthY * 300 , 15, 15);
fill(200);
...
function draw2Joint(joint2) {
fill(100);
console.log ("kinect2" + joint2);
// Kinect location data needs to be normalized to canvas size
ellipse(joint2.depthX * 300 , joint2.depthY * 300, 15, 15);
fill(200);
...
Run Code Online (Sandbox Code Playgroud)
运行上述代码时,控制台仅实时显示来自 Kinect 1 的关节数据,而我需要将 Kinect 的关节数据都记录到控制台。
如何将 console.log 用于多个变量/参数?
提前致谢!
小智 7
您将不得不使用全局变量,以便您可以同时记录它们。以下是要添加到您目前拥有的函数中的代码行。
// add global variables
var joints1 = null;
var joints2 = null;
function bodyTracked(body) {
// assign value to joints1
joints1 = body.joints;
}
function bodyTracked2(body) {
// assign value to joints2
joints2 = body.joints;
}
function draw() {
// log current values at the same time
console.log(joints1, joints2);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
15238 次 |
| 最近记录: |