Skip to content

Language Settings

Create Graphics

Creates and returns a new p5.Renderer object. Use this class if you need to draw into an off-screen graphics buffer. The two parameters define the width and height in pixels.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
let pg;
function setup() {
  createCanvas(710, 400);
  pg = createGraphics(400, 250);
}
function draw() {
  fill(0, 12);
  rect(0, 0, width, height);
  fill(255);
  noStroke();
  ellipse(mouseX, mouseY, 60, 60);
  pg.background(51);
  pg.noFill();
  pg.stroke(255);
  pg.ellipse(mouseX - 150, mouseY - 75, 60, 60);
  //Draw the offscreen buffer to the screen with image()
  image(pg, 150, 75);
}
X

creative commons license