ways to add color parameters to the function?

so I have a blue ball here:

void setup(){
  size(200,200);
}

void draw(){
  background(255);
  ball(20,22,174,255);
}

void ball(float size, int R, int G, int B){
  noStroke();
  fill(R,G,B);
  ellipse(width/2,height/2,size,size);
}

I'd like to ask if it's possible to make my function looks this ball(parameter1,color(__,__,__),parameter3,parameter4); rather than having 3 parameters for RGB

Thank you for your help!

Answers

  • edited June 2017 Answer ✓

    https://Processing.org/reference/color_.html

    // forum.Processing.org/two/discussion/23189/
    // ways-to-add-color-parameters-to-the-function#Item_1
    
    // 2017-Jun-24
    
    void setup() {
      size(200, 200);
      smooth(3);
      noLoop();
      colorMode(RGB);
      ellipseMode(CENTER);
    }
    
    void draw() {
      background(-1);
      drawBall(width>>1, height>>1, 20, color(22, 174, 255));
    }
    
    void drawBall(int x, int y, int diam, color c) {
      pushStyle();
      noStroke();
      fill(c);
      ellipse(x, y, diam, diam);
      popStyle();
    }
    
  • GoToLooP That's really helpful! Thanks!

  • Hi, I've got another piece of code here - they should be doing the same thing however I only see a black ball? Thank you

    Bubble b;
    
    void setup(){
      size(200,200);
      b = new Bubble(100,100,20,color(22,174,255));
    }
    void draw(){
      background(255);
      b.display();
    }
    
    class Bubble{
      float x;
      float y;
      float dia;
      float col;
    
      Bubble(float X, float Y, float DIA, color COL){
        x = X;
        y = Y;
        dia = DIA;
        col = COL; 
      }
    
      void display(){
        noStroke();
        fill(col);
        ellipse(x,y,dia,dia);
      }
    }
    
  • Answer ✓

    @ line # 16: float col; -> color col; L-)

  • ah thanks a lot

Sign In or Register to comment.