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_font

Both Processing and p5.js allow the specification of fonts with either a .ttf/.otf filename or a font string.

Processing

    PFont pf;

    pf = createFont("filename.otf", 32);    // create PFont object from .ttf/.otf filename
    // or
    pf = createFont("Courier", 32);         // create PFont object from font string

    textFont(fontObject);                   // set current font (object only)

p5.js

    let pf;

    pf = loadFont('filename.otf');          // create object from .ttf/.otf file

    textFont(pf);                           // set current font (object)
    // or
    textFont("Courier");                    // set current font (font string)

We make Processing and p5.js converted code work in the same directory, using fonts specified from font strings or .ttf/.otf font files with the following transformations:

Some nice open fonts: Gluk fonts

Converted p5.js:

//
// hello_font
//
let sudegnak;
let courier;
function setup() {
    createCanvas(400, 400);
    background(128);
    fill(0);
    textAlign(CENTER, CENTER);
    textFont(sudegnak, 128);
    text("!@#$%", width / 2, height / 2);
    textFont(courier, 14);
    text(
        "The quick brown fox jumps over the lazy dog.",
        width / 2,
        (height * 3) / 4
    );
}
function preload() {
    sudegnak = loadFont("data/sudegnakno4.ttf");
    courier = "Courier";
}

Original Processing:

//
// hello_font
//


PFont sudegnak;
PFont courier;


void setup() 
{
    size(400, 400);
    background(128);

    sudegnak = createFont("data/sudegnakno4.ttf", 64);
    courier = createFont("Courier", 32);

    fill(0);
    textAlign(CENTER, CENTER);

    textFont(sudegnak, 128);
    text("!@#$%", width/2, height/2);

    textFont(courier, 14);
    text("The quick brown fox jumps over the lazy dog.", width/2, height*3/4);
}



home