Processing:音画生成

视频见下方url

https://www.bilibili.com/video/BV1p34y1W7Py?spm_id_from=333.999.0.0

代码:


import ddf.minim.analysis.*;
import ddf.minim.*;

Minim       minim;
AudioPlayer lazysong;
FFT         fft;

void setup()
{
    size(640, 360, P3D);
  noStroke();
  minim = new Minim(this);
  lazysong = minim.loadFile("lazysong.mp3", 2048);
  lazysong.loop();
  fft = new FFT( lazysong.bufferSize(), lazysong.sampleRate() );
  colorMode(HSB, random(255), 255,255);
}

void draw() {
  defineLights();
  background(0);
  fft.forward( lazysong.mix );

  for (int x = 0; x <= width; x += 60) {
    for (int y = 0; y <= height; y += 60) {
      pushMatrix();
      translate(x, y);
      rotateY(map((fft.getBand(y))*0.4, 0, width, 100, PI*3));
      rotateX(map((fft.getBand(x))*0.5, 0, height, 100, PI*2));
      box(120);
      popMatrix();
    }
  }
}

void defineLights() {
  // Orange point light on the right
  pointLight(150, 255, 30,   // Color
             200, -150, 0); // Position

  // Blue directional light from the left
  directionalLight(80,25,255, // Color
                   1, 0, 0);    // The x-, y-, z-axis direction

  // Yellow spotlight from the front
  spotLight(255, 10, 255,  // Color
            0, 40, 200,     // Position
            0, -0.5, 5,  // Direction
            PI / 2, 2);     // Angle, concentration
}

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注