Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

165
Views
how to change filter with key pressed function?

I was creating a mouse-based painter app. This is a code of a brush whose color is chosen by a color picker in p5js. all I want is = when i press [T] key, it should be changed into THRESHOLD filter i put this code on here:

if (key === 'T') filter(THRESHOLD);

but it's not working im curious why it isn't:) Is there anybody who can help me thanx https://editor.p5js.org/kiskl/sketches/cFGX_xUWE


const sketch = function(p) {

  let colorPicker;
  let brushSize = 20;
  
  p.setup = function() {
    p.createCanvas(800, 800);
    colorPicker = p.createColorPicker('red');
    colorPicker.position(0, 0);
  };



  p.keyPressed = function(e) {

    let key = e.key;
    if (key === '=') brushSize += brushSize * 0.1;
    else if (key === '-') brushSize -= brushSize * 0.1;
    else if (key === 'c') p.clear();
    
    else if (key === 'T') filter(THRESHOLD); //Here, why isn't it working?
    else if (key === 'I') filter(INVERT);
    else if (key === 'P') filter(POSTERIZE);
  }

  p.mouseDragged = function(e) {
    color = colorPicker.color()
    p.fill(color);
    p.stroke(color);
    p.ellipse(e.clientX, e.clientY, brushSize, brushSize)
  } };

let myp5 = new p5(sketch);
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!