Loading...
Logo
Processing Forum
I would like to generate a. Png for example 4000x5000 greater than the main window or other size indicated in the function void keyPressed () and can be applied to any code.

by example in this code:

Its posible?



Thanks so much!


int n = 1000;
int maxage = 20;
int rdodge = 30;
int opacity = 40;
float speed = .2;
float zoom = .01;
boolean crayons, soft, dodge = true;

float[][] a = new float[n][2];
int[] age = new int[n];
float w, h, s;
int t, c;


void setup() {


 size(1500, 1500);
 background(crayons ? 0 : #ffffff);

  img = createImage(2000,2000,RGB);


  
  w = width/2;
  h = height/2;
  colorMode(HSB, TWO_PI, 2, 1);
  smooth();
  reset();

}


void draw() {
  // create new particles
//co.background(255);
//co.fill(255);

  //translate(-offset, -offset);
  //image(co, 0, 0);
  int np = n / maxage;
 
  for(int i=0; i<np & c<n; i++, c++) newp(c);
  // draw particle traces
  for(int i=0; i<c; i++) {
    age[i]++;
    float[] p = a[i];
    if (age[i] > maxage) newp(i);
    else {
      float[] f = f(p[0], p[1]);    
      // opacity based on speed (soft mode) or age (hard mode)
      int m = maxage/2;
      float o = soft ? mag(f[0], f[1]) * 2 * opacity : (m - abs(m - age[i])) * opacity/m;
      // hue based on direction
      float h =  atan2(f[0], f[1]) + PI;  
      stroke(h, crayons ? 1 : 0, crayons ? 1 : 0, o);
      // draw line while updating position
      line(p[0], p[1], p[0] += s*f[0],  p[1] += s*f[1]);
    }
  }
 

}


// noise based flow field
float[] f(float x, float y) {;
  return new float[] {
    noise(t, x * zoom, y * zoom)-.5,
    noise(t+1, x * zoom, y * zoom) - .5
  };
}


void newp(int p) {
  if(dodge) {
    // particle inside a circle around the mouse position
    float r = random(rdodge), ang = random(TWO_PI);
    a[p] = new float[] { mouseX + r * cos(ang), mouseY + r *sin(ang) }; 
  } else { 
    // particle anywhere on screen
    a[p] = new float[] { random(width), random(height) };
  }
  age[p] = 0;
}


void reset() {
  background(crayons ? 0 : #ffffff);
  s = speed / zoom;
  c = 0;
}



void keyPressed() {
switch(key) {
    case 't' : saveFrame("doodle-###.png"); break;
    case 's' : soft = !soft; break;
    case 'd' : dodge = !dodge; break;
    case 'f' : t++; break;
    case 'c' : crayons = !crayons; break;
    case '+' : zoom /= 1.1; break;
    case '-' : zoom *= 1.1; break;
    case 'v' :    PImage partialSave = get(0,0,1500,1500); partialSave.save("partialSave.jpg");
    case 'z' :  img.save("file.jpg");
    case ' ' : break;
    default: return;
  }
 
 
}

Replies(3)

Yes. Generate it on an off-screen PGraphics object instead of in the main window.

Copy code
  1. PGraphics pg;

  2. void setup(){
  3.   size(220,220);
  4.   background(0);
  5.   pg = createGraphics(4000,5000,P2D);
  6.   pg.beginDraw();
  7.   pg.background(0);
  8.   pg.noFill();
  9.   pg.stroke(200,0,0);
  10.   pg.ellipse(100,100,200,200);
  11.   /// etc...
  12.   pg.endDraw();
  13.   pg.image.save("big1.png");
  14.   /// Might also try:
  15.   //pg.get().save("big2.png");
  16.   noLoop();
  17. }
  18. void draw(){} // Does nothing.
  19. /// UNTESTED CODE.
How you can in Place in the code That I have attached?
I do not see how to apply it.

I have tried everything but no way.

Thanks for your support!
You have to look at my code and understand what it is doing.
It's using an off-screen PGraphics object to do the drawing on, instead of just doing it in the main window.
This off-screen buffer can be of any size.

Look at how I define the object: PGraphics pg;
Look at how I create the object: pg = createGraphics(4000,5000,P2D);
Look at the additional functions I had to call to draw on it: beginDraw() and endDraw().
Look at the change in syntax for drawing on it instead of the main window: for example, "pg.stroke(200,0,0);" instead of just "stroke(200,0,0)"

Try to understand the concept here.
Then apply it to your own code.