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

explode

Transformations:

Converted p5.js:

//
// explode
//
let explosionCount = 17;
let explosion = new Array(explosionCount);
let exploding = false;
let explosionIndex = 0;
function setup() {
    createCanvas(400, 400);
    imageMode(CENTER);
}
function preload() {
    for (let i = 0; i < explosion.length; i++)
        explosion[i] = loadImage("data/explode" + i + ".png");
}
function draw() {
    background(0);
    if (exploding == true) {
        if (explosionIndex < explosion.length)
            image(explosion[explosionIndex], width / 2, height / 2);
        if (frameCount % 10 == 0) explosionIndex++;
    } else {
        ellipse(width / 2, height / 2, 50, 50);
    }
}
function keyPressed() {
    if (exploding == true) {
        exploding = false;
    } else {
        exploding = true;
        explosionIndex = 0;
    }
}
function mousePressed() {
    keyPressed();
}

Original Processing:

//
// explode
//


final int explosionCount = 17;
PImage[] explosion = new PImage[explosionCount];

boolean exploding = false;
int explosionIndex = 0;


void setup()
{
    size(400, 400);
    imageMode(CENTER);

    for (int i=0; i<explosion.length; i++)
        explosion[i] = loadImage("data/explode" + i + ".png");
}


void draw()
{
    background(0);

    if (exploding == true)
    {
        if (explosionIndex < explosion.length)
            image(explosion[explosionIndex], width/2, height/2);

        if (frameCount%10 == 0)
          explosionIndex++;
    }
    else
    {
        ellipse(width/2, height/2, 50, 50);
    }
}


void keyPressed()
{
    if (exploding == true)
    {
        exploding = false;
    }
    else 
    {
        exploding = true;
        explosionIndex = 0;
    }
}

void mousePressed()
{
    keyPressed();
}

home