首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >p5.js音乐VIsualization

p5.js音乐VIsualization
EN

Stack Overflow用户
提问于 2017-01-27 18:05:46
回答 1查看 979关注 0票数 1

我创建了一个草图,其中包含一个数组,该数组将圆圈绘制到我在代码中加载的歌曲的幅度,用于iPad。我现在正试图修改那些圆圈。改变颜色或在振幅的某些值加上笔画,如果是这样的话,但是,我不确定这些语句的确切位置。我试过的每一件事都没有影响画的视觉效果。

关键是让圆圈/视觉“画”或做一些事情,即使你的手指不在屏幕上,在最后一个你“触摸”的地方。此外,这个草图可以在mmengle.com上作为startover_music链接进行交互。

代码语言:javascript
复制
var circles = [];


function preload() {
  sound = loadSound('assets/findingnemoegg.mp3');
}

function setup() {
  createCanvas(windowWidth, windowHeight);

  amplitude = new p5.Amplitude();
  sound.play();

for (var i = 0; i < 1; i++) {  
  circles[i] = {
    display: function() {
      var level = amplitude.getLevel();
      var size = map(level, 0, 1, 10, 900);
      noStroke();
      fill(128,166,206,40);
      ellipse(touchX + level, touchY + level, size, size);

  }
    }
  }

    }

function draw() {

  fill(255,8);
  rect(0,0,windowWidth, windowHeight);



  for (var i = 0; i < circles.length; i++) {
    circles[i].display();
  }

}
EN

回答 1

Stack Overflow用户

发布于 2017-01-27 19:18:17

我会假设这是你想要的:

代码语言:javascript
复制
var circles = [];
var lastTouchX;
var lastTouchY;

function preload() {
  sound = loadSound('assests/findingnemoegg.mp3');
}

function setup() {
  createCanvas(windowWidth, windowHeight);

  amplitude = new p5.Amplitude();
  sound.play();

  lastTouchX = width / 2;
  lastTouchY = height / 2;
}

function draw() {

  fill(255, 8);
  rect(0, 0, windowWidth, windowHeight);

  for (var i = 0; i < circles.length; i++) {
    circles[i].display();
  }

}

//change to touchEnded()
function mousePressed() {
  lastTouchX = mouseX;
  lastTouchY = mouseY;
  circles.push(new Circle());
}

function Circle() {
  this.x = lastTouchX;
  this.y = lastTouchY;

  this.display = function() {
    var level = amplitude.getLevel();
    var size = map(level, 0, 1, 10, 200);
    noStroke();
    //if statement to change fill
    fill(128, 166, 206, 40);
    //if statement to change fill
    ellipse(this.x, this.y, size, size);

  }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41900332

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档