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

bounce_vectors

Transformation:

Converted p5.js:

//
// bounce_vectors
//
let position = new p5.Vector(100, 100);
let velocity = new p5.Vector(5, 3);
function setup() {
    createCanvas(400, 400);
}
function draw() {
    background(0);
    fill(0, 0, 255);
    ellipse(position.x, position.y, 100, 100);
    position.add(velocity);
    if (position.x < 50 || position.x > width - 50) velocity.x *= -1;
    if (position.y < 50 || position.y > height - 50) velocity.y *= -1;
}

Original Processing:

//
// bounce_vectors
//


PVector position = new PVector(100, 100);
PVector velocity = new PVector(5, 3);


void setup()
{
    size(400, 400);
}


void draw()
{
    background(0);
    fill(0, 0, 255);
    ellipse(position.x, position.y, 100, 100);

    position.add(velocity);

    if (position.x < 50 || position.x > width-50)
        velocity.x *= -1;

    if (position.y < 50 || position.y > height-50)
        velocity.y *= -1;
}


home