Loading...
Logo
Processing Forum

Paint Program

in Contributed Library Questions  •  1 year ago  
So for my first real project in processing, I decided to go simple, and make paint. I have already finished and moved on, but there are still some things I would like to work out. The main thing I want to add is an "eyedropper" tool. I've tried many different codes that work in my mind, but I just can't seem to get it to run properly. I've already tried storing the color to a variable. I'm using controlP5 for the color picker.

Copy code
  1. import controlP5.*;

  2. ControlP5 slider;

  3. int r = 255;
  4. int g = 255;
  5. int b = 255;
  6. float s = 50;

  7. float br=0;
  8. float bg=0;
  9. float bb=0;

  10. void setup()
  11. {
  12.   size(screen.width,screen.height);
  13.   smooth();
  14.   frameRate(500);
  15.   background(br,bg,bb);
  16.   strokeWeight(50);
  17.   stroke(255,0,0);
  18.   cursor(CROSS);
  19.   
  20.   slider=new ControlP5(this);
  21.   slider.addSlider("r",0,255,10,10,255,30);
  22.   slider.addSlider("g",0,255,10,50,255,30);
  23.   slider.addSlider("b",0,255,10,90,255,30);
  24.   slider.addSlider("s",0,100,10,130,255,30);
  25.   slider.addSlider("br",0,255,10,610,255,30);
  26.   slider.addSlider("bg",0,255,10,650,255,30);
  27.   slider.addSlider("bb",0,255,10,690,255,30);
  28. }
  29. void draw()
  30. {
  31.   noStroke();
  32.   fill(0);
  33.   rect(0,0,350,height);
  34.   fill(r,g,b);
  35.   ellipse(100,300,s,s);
  36.   fill(br,bg,bb);
  37.   ellipse(100,500,50,50);
  38.   stroke(r,g,b);
  39.   strokeWeight(s);
  40.   if (mousePressed == true&&mouseX>350)
  41.   {
  42.     line(mouseX,mouseY,pmouseX,pmouseY);
  43.   }
  44. }
  45. void keyPressed()
  46. {
  47.   if(keyCode==' ')
  48.   {
  49.     background(br,bg,bb);
  50.   }
  51. }

Replies(5)

Re: Paint Program

1 year ago
get() allows you to get the color at the given coordinates, which can be mouseX/Y.

Re: Paint Program

1 year ago
Yes, i've tried that, but I can't find a way to store the color. As I said, I've tried using variables, but it just won't work.

Re: Paint Program

1 year ago
 Maybe  color c = get(x, y);
?

Re: Paint Program

1 year ago
If I understood correctly what you want, here is a simple change that allows you to pick a color with a right click (inside the app window):

Copy code
  1. if (mousePressed)
  2. {
  3.   if (mouseButton == LEFT && mouseX>350)
  4.   {  
  5.     line(mouseX,mouseY,pmouseX,pmouseY);
  6.   } else if (mouseButton == RIGHT) {
  7.     color c = get(mouseX, mouseY);
  8.     slider.controller("r").setValue(red(c));
  9.     slider.controller("g").setValue(green(c));
  10.     slider.controller("b").setValue(blue(c));
  11.   }
  12. }

I am setting the color to the sliders, but you can put it in a var instead.

Re: Paint Program

1 year ago
Wow, thanks! I had no idea I could access the RGB values of get() individually!