colorMode

edited January 2018 in Questions about Code

Hi everybody! I want to realize a background with a progressive color change that goes from orange to violet but I don't know how to properly do it.

fullScreen ();
colorMode(HSB,360,100,100,100);
int l=20;
int a= 20;
for (int x=0; x<=width; x+=l)
{
  for (int y=0; y<=height; y+=a)
  {
    float hue=map(x,0,width,0,360);
    fill(hue,100,100);
    ellipse(x,y,30,30);
    noStroke();
    }
    }

This is my starting code; I think that it's possible to change the color "range" by colorMode but what number should I use? There's some specific colorMode or I must use RGB/HSB?

Answers

  • The best thing you can do is to draw out a few examples. What are the RGB or HSV values at different points on your gradient? Then come up with a formula that captures that pattern.

  • Answer ✓

    Check https://processing.org/reference/lerpColor_.html

    A demo below.

    Kf

    final color ORA=color(250,250,0);
    final color VIO=color(250,0,250);
    
    size(640,480);
    int dw=20;
    int dh= 20;
    
    noStroke();
    for (int x=0; x<width; x+=dw){
      for (int y=0; y<height; y+=dh)
      {
        int loc=x+y*width;
        float ratio=float(loc)/(width*height);
        color c=lerpColor(ORA, VIO, ratio);
        fill(c);
        ellipse(x, y, dw,dh);    
      }
    }
    
  • edited January 2018

    Thanks for the tips.

Sign In or Register to comment.