Processing

8. Tauler de Dibuix

Creat per Isaac Muro
Creative Commons Licence

pmouseX, pmouseY

Les variables pmouseX i pmouseY s'utilitzen per saber el valor de les variables mouseX, mouseY anterior.


function setup() {
  createCanvas(400, 400);
  // Escrivim el background aquí perquè no canvii el fons.
  background(255);
}

function draw() {
  // Definim l'amplada de la línea
  strokeWeight(3);

  // pmouse és la posició anterior que tenia el ratolí abans.
  line (mouseX, mouseY, pmouseX, pmouseY);
}
					

pmouseX, pmouseY Exemple

keyIsPressed


let ample = 3;
function setup() {
  createCanvas(400, 400);
  background(255);
}

function draw() {
  strokeWeight(ample);
  line (mouseX, mouseY, pmouseX, pmouseY);

  // Fem coses si apretem alguna tecla
  if (keyIsPressed){
    if(key == '+'){
      ample = ample + 1;
    }
    if(key == '-'){
      ample = ample - 1;
    }
    if(key == 'r'){
      background(255);
    }
  }
}
					

Que hem afegit?


  if (keyIsPressed){
    if(key == '+'){
      ample = ample + 1;
    }
    if(key == '-'){
      ample = ample - 1;
    }
    if(key == 'r'){
      background(255);
    }
  }
					

mouseIsPressed


let ample = 3;
function setup() {
  createCanvas(400, 400);
  background(255);
}

function draw() {
  if(mouseIsPressed){
    strokeWeight(ample);
    line (mouseX, mouseY, pmouseX, pmouseY);
  }

  if (keyIsPressed){
    if(key == '+'){
      ample = ample + 1;
    }
    if(key == '-'){
      ample = ample - 1;
    }
    if (key=='e'){
      stroke(0);
      fill(random(255),random(255),random(255));
      ellipse(mouseX, mouseY, pmouseX, pmouseY);
    }
  }
}
					

Que hem afegit?


if(mouseIsPressed){
  strokeWeight(ample);
  line (mouseX, mouseY, pmouseX, pmouseY);
}