Processing 处理/节奏记录

Processing 处理/节奏记录,processing,Processing,我正在做一个学生项目。我试着记录一个有节奏的构图,并在此基础上画一个垂直线的网格。这看起来就像把一辆有轨电车帕姆·帕姆撞倒在一个木箱上;标准厚壁菌。然后处理需要映射此记录的时间和屏幕的宽度,并在敲击的位置绘制垂直线 请,帮助,在哪里查找记录此时间,然后将其映射到屏幕 到目前为止,我有这个代码。但它只在有屏幕空间的情况下在敲门声上画线;并以pdf格式保存 import processing.serial.*; import cc.arduino.*; import processing.pd

我正在做一个学生项目。我试着记录一个有节奏的构图,并在此基础上画一个垂直线的网格。这看起来就像把一辆有轨电车帕姆·帕姆撞倒在一个木箱上;标准厚壁菌。然后处理需要映射此记录的时间和屏幕的宽度,并在敲击的位置绘制垂直线

请,帮助,在哪里查找记录此时间,然后将其映射到屏幕

到目前为止,我有这个代码。但它只在有屏幕空间的情况下在敲门声上画线;并以pdf格式保存

 import processing.serial.*;
 import cc.arduino.*;
 import processing.pdf.*;

 Arduino arduino;

 Serial myPort;       

 int x = 0;

 void setup() {
     size(500, 500);
     background(#ffffff);

     println(Arduino.list());

     arduino = new Arduino(this, "/dev/tty.usbmodem1411", 57600);

     //Set the Arduino digital pins as inputs.
     arduino.pinMode(0, Arduino.INPUT);

     beginRecord(PDF, "everything.pdf");
 }
 void draw() {
     stroke(0);

     for (int i = 0; i <= 0; i++) {
         if (arduino.analogRead(i)>0) {
             line(x, 0, x, height);
         }
         else {
              x +=1;
         }
     }
 }
 void keyPressed() {
     endRecord();
     codexit();
 } 

我终于完成了。假设它可以做得更好、范围更广,但事实是它是有效的

关于结果的小视频:

以及守则:

import processing.serial.*;
import cc.arduino.*;

Arduino arduino;
PrintWriter output;

// The serial port:
Serial myPort;       

int t = millis();
int[] time;

void setup() {
size(500, 500);
background(#ffffff);

// Prints out the available serial ports.
println(Arduino.list());


// Modify this line, by changing the "0" to the index of the serial
// port corresponding to your Arduino board (as it appears in the list
// printed by the line above).
arduino = new Arduino(this, "/dev/tty.usbmodem1411", 57600);

// Alternatively, use the name of the serial port corresponding to your
// Arduino (in double-quotes), as in the following line.
//arduino = new Arduino(this, "/dev/tty.usbmodem621", 57600);

// Set the Arduino digital pins as inputs.
arduino.pinMode(0, Arduino.INPUT);

// Creates the output for the time, dedicated to the beats.
output = createWriter("time.txt"); 

}

void draw() {

// when arduino sends signal, store the current
// time in milliseconds since the program started

if (arduino.analogRead(0)>30) {

// grabs the time, passed before the beat from start

String numbers = "millis()";
delay(100);
output.print (millis() + ",");

}
}

void keyPressed() {
output.flush();  // Writes the remaining data to the file
output.close();  // Finishes the file

}

void keyReleased() {

// Interprets the string from the saved beat sequence
String[] numbers = loadStrings("time.txt");
time = int(split(numbers[0],','));

stroke(0);
strokeWeight(5);

// Draws lines, based on a string

for (int i = 1;  i < time.length; i++) {
int c = time[i]-time[0];
int d = time[time.length - 2];
int e = time[0];
int f = d-e;

// Vertical lines
line(c*500/f, 0 , c*500/f , height);

// Horisontal lines
line(0, c*500/f, width, c*500/f);

// Drawing rects

// Yellow
fill (255, 255, 0);
int m = (time [1] - time [0])*500/f;
int n = (time [2] - time [0])*500/f;
rect (m, m, n-m, n-m);

// Blue
fill (0, 0, 255);
int o = (time [8] - time [0])*500/f;
int p = (time [4] - time [0])*500/f;
rect (o, m, p-o, p-o);

// Red
fill(255, 0, 0);
int v = (time [3] - time [0])*500/f;
int k = (time [6] - time [0])*500/f;
int z = (time [8] - time [0])*500/f;
rect(v, p, z-v, k-v);

}

}