hello_sound
Transformations:
- comment out all
import
statements (preprocessing before parsing – java-parser doesn’t like them) new SoundFile(this, filename)
->loadSound(filename)
(not sure why Processing doesn’t have this function)
Web pages need to include p5.js sound library:
<script src="/path/to/p5.sound.min.js"></script>
Open access dataset of cat vocalizations: CatMeows
Converted p5.js:
//
// hello_sound
//
// [processing-p5-convert] import processing.sound.*;
let meow;
function setup() {
createCanvas(400, 400);
background(0);
}
function preload() {
meow = loadSound("meow.wav");
}
function draw() {
background(0);
if (dist(mouseX, mouseY, 200, 200) < 50) fill(0, 255, 0);
else fill(0, 0, 255);
ellipse(200, 200, 100, 100);
}
function mousePressed() {
if (dist(mouseX, mouseY, 200, 200) < 50) meow.play();
}
Original Processing:
//
// hello_sound
//
import processing.sound.*;
SoundFile meow;
void setup() {
size(400, 400);
background(0);
meow = new SoundFile(this, "meow.wav");
}
void draw()
{
background(0);
if (dist(mouseX, mouseY, 200, 200) < 50)
fill(0, 255, 0);
else
fill(0, 0, 255);
ellipse(200, 200, 100, 100);
}
void mousePressed()
{
if (dist(mouseX, mouseY, 200, 200) < 50)
meow.play();
}