mercredi 22 février 2023

Processing adding random colors to SVG files in a random grid layout

I'm inserting a few SVG files in a grid layout and want the colors to be random. But they're only applying random color to the square SVG object itself, not the shapes within the SVG. Is this something that I needed to embed in the SVG file? I'm very new to this and feel like I'm trying to learn Latin.

Grid layout code:

HDrawablePool pool;
HColorPool colors;

void setup(){
size(400,1300);
H.init(this).background(#000000);
smooth();

colors = new HColorPool(#9EA2A2, #C7C9C7, #101820, #FCE300, #78BE20, #FE5000, #E03E52);

pool = new HDrawablePool(12);
pool.autoAddToStage()
  .add(new HShape("BlockQ.svg"))
  .add(new HShape("BlockX.svg"))
  .add(new HShape("BlockY.svg"))
  .add(new HShape("BlockZ.svg"))
 

  .layout(
    new HGridLayout()
    .startX(50)
    .startY(50)
    .spacing(100,100)
    .cols(3)
  )

  .onCreate(
    new HCallback() {
      public void run(Object obj) {
        HShape d = (HShape) obj;
        d
          .enableStyle(false)
          .strokeJoin(ROUND)
          .strokeCap(ROUND)
          .strokeWeight(1)
          .stroke(#000000)
          .anchorAt(H.CENTER)
          .rotate( (int)random(4) * 90 );
        ;
        d.randomColors(colors.fillOnly());
     }
   }
 )
 .requestAll()
;

H.drawStage();
}

Code for one of the SVG files:

import processing.svg.*;

void setup() {
   size(100, 100, SVG, "BlockO.svg");
}

void draw() {
  //size (100,100);
   background (255);
   line (0,0,0,100);
   line (0,0,100,0);
   line (100,0,100,100);
   line (0,100,100,100);

  // Exit the program
  println("Finished.");
  exit();
}

I was hoping the random color would appear within the SVG files, like the little triangles and such.




Aucun commentaire:

Enregistrer un commentaire