how to create an array of pre-defined colors?

I am new to processing and trying to create an array to contain a set of pre-defined colors. When I run, I get "Syntax error on token "int", invalid ClassType " for the line that contains "colors[c] = new color(hue);"

Is there a small change that I have to make in creating the array or am I going about this all wrong? I would like to use the array in creating 16 ellipses using a for loop, with each ellipse as a different color.

color c1 = #FF0000;
color c2 = #FFC000;
color c3 = #E0FF00;
color c4 = #7EFF00;
color c5 = #21FF00;
color c6 = #00FF41;
color c7 = #00FF9F;
color c8 = #00FDFF;
color c9 = #009FFF;
color c10 = #003DFF;
color c11 = #2100FF;
color c12 = #8300FF;
color c13 = #E500FF;
color c14 = #0052FF;
color c15 = #FF007C;
color c16 = #1000FF;
color c17 = #FFFFFF;


color[] colors;

void setup() {
  size(800, 950);
  background(c17);
  colors = new color[colors.length];
  for (int c = 0; c < colors.length; c ++) {
    color hue = color(c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13, c14, c15, c16, c17);
    colors[c] = new color(hue);
  }
}

void draw() { 

//still working out how to implement the color array into creating the ellipses, I'm very new to processing.

  for (float i = 150; i < 701; i = i+166) {
    for (float j = 150; j < 701; j = j+166) {
      ellipse(i, j, 100, 100);
     }
  }
}
Tagged:

Answers

  • edited March 2014 Answer ✓

    here...

    color c1 = #FF0000;
    color c2 = #FFC000;
    color c3 = #E0FF00;
    color c4 = #7EFF00;
    color c5 = #21FF00;
    color c6 = #00FF41;
    color c7 = #00FF9F;
    color c8 = #00FDFF;
    color c9 = #009FFF;
    color c10 = #003DFF;
    color c11 = #2100FF;
    color c12 = #8300FF;
    color c13 = #E500FF;
    color c14 = #0052FF;
    color c15 = #FF007C;
    color c16 = #1000FF;
    color c17 = #FFFFFF;
    
    
    color[] colors  = {  
      c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13, c14, c15, c16, c17
    };
    
    
    
    void setup() {
      size(800, 950);
      background(c17);
      //  colors = new color[colors.length];
      //  for (int c = 0; c < colors.length; c ++) {
      //    //colors 
      //    //    colors[c] = new color(hue);
      //  }
    }
    
    void draw() { 
      background(255);
    
      // still working out how to implement the color array into 
      // creating the ellipses, I'm very new to processing.
      int k=0;
      for (float i = 150; i < 701; i = i+166) {
        for (float j = 150; j < 701; j = j+166) {
    
          fill(colors[k]);
          ellipse(i, j, 100, 100);
          k++;
        }
      }
      //
    }
    //
    
  • Answer ✓
    color[] colors = 
    { 
    #FF0000,
    #FFC000,
    #E0FF00,
    #7EFF00,
    #21FF00,
    #00FF41,
    #00FF9F,
    #00FDFF,
    #009FFF,
    #003DFF,
    #2100FF,
    #8300FF,
    #E500FF,
    #0052FF,
    #FF007C,
    #1000FF,
    #FFFFFF,
    };
    
    void setup() 
    {
      size(800, 950);
      background(colors[16]);
    }
    
    void draw() 
    {
      background(255);
    
      // still working out how to implement the color array into
      // creating the ellipses, I'm very new to processing.
      int k = 0;
      for (float i = 150; i < 701; i = i+166) 
      {
        for (float j = 150; j < 701; j = j+166) 
      {
          fill(colors[k]);
          ellipse(i, j, 100, 100);
          k++;
        }
      }
    }
    
  • you're welcome!

Sign In or Register to comment.