CreateGraphics2

This is the link, in case it does not work on a phone. Just drag the mouse or fingers over the canvas area.

The code:

var extraCanvas;
var x;
var y;
var old;
var recta;



function setup() {
  old = createCanvas(400, 400);
  extraCanvas = createGraphics(400, 400)
  extraCanvas.clear()
  background(220);
}

function draw() {
  //background(220);
  image(extraCanvas, 0, 0)
  x = random(200, 205)
  y = random(200, 205)
  fill(255, 0, 0)
  //noStroke()
  stroke(225)
  rectMode(CENTER)
  recta = rect(x, y, 50, 50)
  
  if(mouseIsPressed){
    extraCanvas.fill(0, 0, 255)
    extraCanvas.noStroke()
    extraCanvas.rect(mouseX, mouseY, 50, 50)
  }
  //image(extraCanvas, 0, 0)
  
  
  
}

Leave a Reply