processing-p5-convert

source code translator that converts Processing Java code to p5.js Javascript code

Home Minimal_example Command_line Notes About Project

(tests) hello bounce grid bounce_with_class cat hello_font hello_sound explode bounce_vectors hello_3d

(live conversion tests) phyllotaxis dandelin dogfooding

(student project tests) cow_game cross_the_road dinosaur_game greenhouse_game

hello_sound

Transformations:

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(); 
}


home