problem exporting .ase - generative design library

edited December 2017 in Library Questions

Hi, i was trying to work with this library, but i can't manage to export a proper .ase file. Illustrator never opens that, and if i print the color array i only get: [I@58bd518a

Here's is my code:

    import generativedesign.*;
    import processing.pdf.*;
    import java.util.Calendar;
    boolean savePDF = false;
    PImage img; 
    color[] colors;
    String sortMode = null; 

    void setup() {
      size(500, 500);
      colorMode(HSB, 360, 100, 100, 100);
      noStroke();
      noCursor();
      img = loadImage("pic2.jpg"); 
      img.resize(0, 500);
    }


    void draw() {
      if (savePDF) {
        beginRecord(PDF, timestamp()+".pdf");
        colorMode(HSB, 360, 100, 100, 100);
        noStroke();
      }

      int tileCount = width / 150; 

      float rectSize = width / float(tileCount); 
      int i = 0; 
      colors = new color[tileCount*tileCount]; 
      for (int gridY=0; gridY<tileCount; gridY++) {
        for (int gridX=0; gridX<tileCount; gridX++) {
          int px = (int) (gridX * rectSize); 
          int py = (int) (gridY * rectSize); 
          colors[i] = img.get(px, py);
          i++;
        }
      }



      // sort colors

       sortMode = GenerativeDesign.HUE;
      if (sortMode != null) colors = GenerativeDesign.sortColors(this, colors, sortMode); 
      // draw grid
      i = 0;
      for (int gridY=0; gridY<tileCount; gridY++) {
        for (int gridX=0; gridX<tileCount; gridX++) {
          fill(colors[i]);                                        
          rect(gridX*rectSize, gridY*rectSize, rectSize, rectSize);
          i++;
        }
      }

      if (savePDF) {
        savePDF = false;
        endRecord();
      }
    }


    void keyReleased() {
      if (key == '4') sortMode = null;
      if (key == '5') sortMode = GenerativeDesign.HUE;
      if (key == '6') sortMode = GenerativeDesign.SATURATION;
      if (key == '7') sortMode = GenerativeDesign.BRIGHTNESS;
      if (key == '8') sortMode = GenerativeDesign.GRAYSCALE;
      if (key=='s' || key=='S') savePDF = true;
      if (key=='c') {
        GenerativeDesign.saveASE(this, colors, "ase/"+timestamp()+".ase"); 
        print("salvato");
        exit();
      }
    }


    // timestamp
    String timestamp() {
      Calendar now = Calendar.getInstance();
      return String.format("%1$ty%1$tm%1$td_%1$tH%1$tM%1$tS", now);
    }

Thanks

Answers

  • if i print the color array i only get: [I@58bd518a

    How are you doing this? It seems you are not iterating through each element in the array.

    The code above works by the way. It seems it is an incompatibility between the saved format from Processing and what Illustrator is expecting. Hopefully some forum goers can comment on this.

    Kf

  • for (int gridY=0; gridY<tileCount; gridY++) { for (int gridX=0; gridX<tileCount; gridX++) { int px = (int) (gridX * rectSize); int py = (int) (gridY * rectSize); colors[i] = img.get(px, py); i++; print(colors); } }

    like this, if i place a noLoop(); at the end of draw() the output would be: [I@5036a3f0[I@5036a3f0[I@5036a3f0[I@5036a3f0[I@5036a3f0[I@5036a3f0[I@5036a3f0[I@5036a3f0[I@5036a3f

  • edited December 2017

    okay, if i print(hex(colors[i], 6)); i get the format i need later in Illustrator, i just have to find a way to make GenerativeDesign.saveASE(this, colors, "ase/"+timestamp()+".ase"); save hex colors i guess

  • Looking at the version 2 of this library:

    https://github.com/generative-design/GenerativeDesignLibrary2/blob/master/src/generativedesign/GenerativeDesign.java#L240

    I suggest you change your color[] array to an int[] array. See if it works.

    Kf

Sign In or Register to comment.