← Back
Before you start
Java → C++ reference table for a convenient workflow
A quick cheat-sheet for porting a Processing (Java) sketch to Umfeld (C++).
This is the atomic, syntax-level reference. For conceptual differences and rationale, read the Umfeld and Processing article.
How to read each section: the left column is what you would type in Processing, the middle column is the Umfeld (C++) equivalent, the right column is a one-line note explaining the change or a gotcha.
Sketch structure
| Processing (Java) | Umfeld (C++) | Notes |
|---|---|---|
void setup() { size(800, 600); } |
void settings() { size(800, 600); } |
size() lives in settings(), not setup() |
void setup() { ... } |
void setup() { ... } |
Same role |
void draw() { ... } |
void draw() { ... } |
Same role |
void mousePressed() { ... } |
void mousePressed() { ... } |
Callback, unchanged |
void keyPressed() { ... } |
void keyPressed() { ... } |
Callback, unchanged |
void mouseWheel(MouseEvent e) |
void mouseWheel(float x, float y) |
Different signature |
void windowResized() |
void windowResized(int w, int h) |
Receives new size as parameters |
| n/a | void update() |
Umfeld-only, runs before draw() |
| n/a | void post() |
Umfeld-only, runs after draw() |
| n/a | void shutdown() |
Umfeld-only, runs on exit |
| n/a | void dropped(const char* path) |
Umfeld-only, file dropped on window |
Globals you read every frame
| Processing | Umfeld | Notes |
|---|---|---|
width, height |
width, height |
float — watch out for width % 2 errors |
frameCount |
frameCount |
int |
frameRate(60) |
frameRate = 60; |
frameRate is a variable, not a function |
mouseX, mouseY |
mouseX, mouseY |
float |
pmouseX, pmouseY |
pmouseX, pmouseY |
|
mouseButton |
mouseButton |
int |
mousePressed |
isMousePressed |
Renamed — collided with callback name |
key |
key |
int |
keyCode |
keyCode |
int |
keyPressed |
isKeyPressed |
Renamed — collided with callback name |
displayWidth |
display_width |
int |
displayHeight |
display_height |
int |
Colour
| Processing | Umfeld | Notes |
|---|---|---|
color c = color(255, 100, 0); |
color_t c = color(255, 100, 0); |
Type renamed to color_t |
fill(c); |
fill(c); |
Same |
fill(0.5) |
fill(0.5f) |
Add f suffix to avoid double/float mix |
| n/a | fill_color(0xFF44FF88); |
Explicit packed-ARGB to disambiguate |
colorMode(RGB, 1.0) |
colorMode(RGB, 1.0f) |
Warning: this breaks standard fill(255) |
stroke(c), background(c) |
same | |
lerpColor(a, b, t) |
lerpColor(a, b, t) |
Console output
| Processing | Umfeld | Notes |
|---|---|---|
println("hi") |
println("hi") |
Same |
println("x = " + mouseX) |
println("x = ", mouseX) |
Comma, not + |
print(x) |
print(x) |
|
| n/a | console("hi", x) |
Umfeld-only, adds timestamp |
| n/a | std::string s = str("x = ", mouseX); |
Build mixed-type strings via str() |
Keywords and constants
| Processing | Umfeld | Notes |
|---|---|---|
final |
const |
|
null |
nullptr |
|
import |
#include |
#include "Umfeld.h" |
color |
color_t |
Type rename |
Math.PI |
PI |
Umfeld exposes Processing-style constants |
Math.E |
E |
Strings
| Processing (Java) | Umfeld (C++) | Notes |
|---|---|---|
String s = "hi"; |
std::string s = "hi"; |
Always prefer std::string |
s.length() |
s.length() or s.size() |
|
s + "!" |
s + "!" |
Works only when at least one side is std::string |
s.equals(t) / s == t |
s == t |
Works for std::string |
Integer.parseInt(s) |
std::stoi(s) |
Throws if not parseable |
Float.parseFloat(s) |
std::stof(s) |
|
String.valueOf(x) |
std::to_string(x) |
|
mixed-type concat: "a" + 1 |
str("a", 1) |
Umfeld helper |
Numbers and math
| Processing | Umfeld | Notes |
|---|---|---|
float x = 1.0; |
float x = 1.0f; |
f suffix avoids double promotion |
int i = (int) 3.7; |
int i = (int) 3.7f; |
Same syntax |
random(100) |
random(100) |
Warning: not thread-safe. Use std::mt19937 in threads |
noise(x, y) |
noise(x, y) |
Resets each run unless noiseSeed() is set |
map(v, a, b, c, d) |
map(v, a, b, c, d) |
All args same float type or cast |
constrain(v, lo, hi) |
constrain(v, lo, hi) |
Same rule about types |
Integer.MAX_VALUE |
INT_MAX |
from <climits> |
Float.MAX_VALUE |
FLT_MAX |
from <cfloat> |
Arrays and collections
| Processing (Java) | Umfeld (C++) | Notes |
|---|---|---|
int[] a = new int[10]; |
std::vector<int> a(10); |
Prefer std::vector over raw arrays |
int[] a = {1, 2, 3}; |
std::vector<int> a = {1, 2, 3}; |
|
a.length |
a.size() |
|
a[i] |
a[i] or a.at(i) |
.at(i) adds bounds check |
ArrayList<Foo> list; |
std::vector<Foo> list; |
|
list.add(x) |
list.push_back(x) |
|
list.size() |
list.size() |
|
list.get(i) |
list[i] |
|
for (Foo f : list) |
for (auto& f : list) |
auto& avoids copies |
HashMap<K,V> m; |
std::unordered_map<K,V> m; |
Classes and objects
| Processing (Java) | Umfeld (C++) | Notes |
|---|---|---|
class Foo { int x; } |
class Foo { public: int x; }; |
Trailing ; required; everything is private by default |
new Foo() |
Foo f; (stack) or new Foo() (heap) |
Prefer stack; let scope manage lifetime |
Foo f = new Foo(); |
Foo f; |
Stack-allocated object |
null |
nullptr |
|
f.x |
f.x |
When f is an instance |
| n/a | f->x |
When f is a pointer |
this.x |
this->x or just x |
|
extends Bar |
: public Bar |
Public inheritance |
super.foo() |
Bar::foo() |
|
| automatic GC | RAII / delete / std::unique_ptr |
Stack objects clean up automatically |
Files and IO
| Processing (Java) | Umfeld (C++) | Notes |
|---|---|---|
loadStrings("f.txt") |
std::vector<std::string> loadStrings("f.txt") |
Reads into std::vector (unlike Processing’s String[]) |
saveStrings(...) |
saveStrings("f.txt", lines) |
Takes a std::vector<std::string> |
loadImage("p.jpg") |
PImage* img = loadImage("p.jpg"); |
Returns a pointer — use -> for methods |
loadFont("f.ttf") |
PFont* f = loadFont("f.ttf", 24); |
Required before text() will draw anything |
loadShader(...) |
PShader* s = loadShader(...); |
Caller owns the pointer — you must delete it |
Drawing
| Processing | Umfeld | Notes |
|---|---|---|
background(0) |
background(0) |
|
fill(255, 80, 40) |
fill(255, 80, 40) |
|
stroke(...) |
stroke(...) |
|
noFill() / noStroke() |
noFill() / noStroke() |
|
line(x1, y1, x2, y2) |
line(x1, y1, x2, y2) |
|
rect(x, y, w, h) |
rect(x, y, w, h) |
|
ellipse(x, y, w, h) |
ellipse(x, y, w, h) |
|
circle(x, y, d) |
circle(x, y, d) |
|
triangle(...) |
triangle(...) |
|
beginShape() / vertex / endShape() |
same | |
image(img, sx, sy, sw, sh, dx, dy, dw, dh) |
Not supported | PGraphics::image has no source-rect overload |
translate(x, y) |
translate(x, y) |
(0,0) is Top-Left (Y-DOWN) |
rotate(a) / scale(s) |
rotate(a) / scale(s) |
rotate() takes radians, not degrees |
pushMatrix() / popMatrix() |
pushMatrix() / popMatrix() |
Unbalanced calls will crash the stack |
Build and project layout
| Processing | Umfeld | Notes |
|---|---|---|
| Open in PDE, hit play | cmake -B build && cmake --build build && ./build/myapp |
One-liner per sketch |
MySketch/MySketch.pde |
MySketch/application.cpp + MySketch/CMakeLists.txt |
Flat layout per project |
import g4p_controls.*; |
add_subdirectory(<path>) + target_link_libraries(...) in CMake |
See umfeld-libraries |
data folder data/ next to sketch |
data folder next to executable | Look up actual lookup paths |
A few habits that travel well:
- Declare variable types explicitly — C++ will not infer them across scopes the way you might expect.
- Class definitions end with a semicolon
;. - Prefer
std::vectorover raw arrays; it behaves like Java’sArrayList.
Keep this page open in a tab while you port your first sketch.