Working with PGraphics • tim rodenbröker creative coding

Working with PGraphics

Courses / PGraphics / Working with PGraphics

beginDraw() and endDraw()

The two functions beginDraw() and endDraw() open and close the draw loop for the PGraphics layer.

Since we want to reference a specific PGraphics object here, we need to target it using the so-called “Dot Syntax”.

Processing

PGraphics pg;

void setup(){
  size(900,900);
  createGraphics(600,600);
}

void draw() {

  pg.beginDraw();
  // This is the draw-loop of pg
  pg.endDraw();

}

P5.js

let pg;

function setup(){
  createCanvas(500,500);
  pg = createGraphics(300,300);
}

function draw() {
  image(pg, 10, 10);
}

Displaying the PGraphics-object with the image()-function

Processing

PGraphics pg;

void setup() {
  size(900, 900);
  pg = createGraphics(600, 600);
}

void draw() {
  background(#FFFF00);
  
  pg.beginDraw();
  pg.background(0);
  pg.endDraw();
  
  imageMode(CENTER);
  image(pg,width/2,height/2);
  
}

P5.js

let pg;

function setup() {
  createCanvas(500, 500);
  pg = createGraphics(300, 300);
}

function draw() {
  background('#FFFF00');

  pg.background(0);

  imageMode(CENTER);
  image(pg,width/2,height/2);

}

Language Comparison

Processingp5.js
image()image()
beginDraw() and endDraw()
Published by Tim on Wednesday July 7, 2021

Last modified on January 18th, 2023 at 17:08

  1. PGraphics
  2. Working with PGraphics
  3. Objects and Dot-Syntax
  4. Drawing on PGraphics
  5. Masking and Cropping
  6. Transformations
  7. Setting Renderers
  8. Transparency
  9. Layer Stacks
  10. Tabs
  11. Nesting PGraphics
  12. PGraphics Rasterization
  13. Wrapping Up