high resolution issue

Exporting in high resolution makes my sketch look completely different. I'm using PGraphics and I wonder how this could affect my sketch. I have no idea why it changed the color of my stuff and remove the alpha channel. I guess is because because PGraphics can't interact with sketch's background. If I am right, how can made this alpha gradient trails in PGraphics?

import processing.pdf.*;

float size = 1;
float z = 0.0;
float z2 = 20.0;
float z3 = 30.0;
PFont myFont;
int offset = 10;

void setup(){
  size(413,945,P3D);
  background(10);
  pixelDensity(displayDensity());
  colorMode(HSB, height,300,360);
  noStroke();
  myFont = createFont("bmd Neuzeit Grotesk T Regular.ttf", 10);
  textFont(myFont);
  textAlign(CENTER, CENTER);

}

void drawGrid(PGraphics pg){

  pg.fill(0,20);
  pg.rect(0,0,width, height);

  String[] chars = split("b m d b m d m", ' ');

    for ( int x = -width/2; x < width + width/2; x +=offset){
    for ( int y = -height/2; y < height + height/2; y += offset){

      int nl = (int) map(noise(z, x / 550.0, y / 550.0), 0, 1, 0, 7);
      float ns = map(noise(z, x / 550.0, y / 550.0), 0, 1, 0, 3);

      pg.fill(0,0,350);
      pg.pushMatrix();

      if ((y - 16) % (2) == 0){
        pg.scale(ns);
        pg.text(chars[nl], x,y );}
        else{
        pg.text(chars[nl], x + 8 ,y);
        }
      pg.popMatrix();

    }
  }

  z = z + .003;

}

void draw() {


  drawGrid(this.g);


}

void keyPressed(){
  if (key == 's') {
    save("normal.png");
    hf(6);
    exit();

  }
}


void hf(int saveScale){
  PGraphics pg = createGraphics(int(width*saveScale), int(height*saveScale), PDF, "output.pdf");
  pg.beginDraw();
  pg.scale(saveScale);
  drawGrid(pg);
  pg.dispose();
  pg.endDraw();
}

Answers

  • import processing.pdf.*;
    
    float size = 1;
    float z = 0.0;
    float z2 = 20.0;
    float z3 = 30.0;
    PFont myFont;
    int offset = 10;
    
    boolean savePDF=false;
    int scale=1;
    PGraphics hires; 
    
    void setup() {
    
      size(413, 945, P3D);
      pixelDensity(displayDensity());
      noStroke();
    }
    
    void draw() {
    
      drawGrid();
    }
    
    void keyPressed() {
      saveHiRes(4);
    }
    
    void drawGrid() {
    
      if(savePDF){
      hires = createGraphics(width, height, PDF, "output.PDF");
      beginRecord(hires);
      }
    
      colorMode(HSB, height, 300, 360);
      background(170,300,230);
    
    
      myFont = createFont("bmd Neuzeit Grotesk T Regular.ttf", 10);
      textFont(myFont);
      textAlign(CENTER, CENTER);
    
      //fill(0,20);
      //rect(0,0,width, height);
    
    
      String[] chars = split("b m d b m d m", ' ');
    
      for ( int x = -width/2; x < width + width/2; x +=offset) {
        for ( int y = -height/2; y < height + height/2; y += offset) {
    
          int nl = (int) map(noise(z, x / 550.0, y / 550.0), 0, 1, 0, 7);
          float ns = map(noise(z, x / 550.0, y / 550.0), 0, 1, 0, 3);
    
          fill(0, 0, 350);
          pushMatrix();
    
          if ((y - 16) % (2) == 0) {
            scale(ns);
            text(chars[nl], x, y );
          } else {
            text(chars[nl], x + 8, y);
          }
          popMatrix();
        }
      }
    
      z = z + .003;
    
      if(savePDF){
      hires.scale(scale);
      endRecord();
      save("normal.png");
      exit();
      }
    
    }
    
    void saveHiRes(int scaleFactor) {
      savePDF = true;
      scale = scaleFactor;
    }
    
  • G_D thank you! but It is still missing opacity trails.

    Here is what I am trying to get:

    normal

    And this is what I get:

    normal1

Sign In or Register to comment.