Use a resolution greater than my screen?
in
Programming Questions
•
2 years ago
I want to do a high quality rendering of a fractal made with attractors and particles. How do I make a high resolution export?
I didn't make most of this code -- credits are in the comments at the top. I just changed around the variables and added the last part that exports a PNG when a key is pressed, but the export is really low quality. How do I make a high quality export?
This is the applet I got this from http://www.processing.org/exhibition/works/metropop/applet.html
- //
- // Tom Carden, May 2004, revised May 2005.
- // a simple particle system with naive gravitational attraction
- //
- int NUM_PARTICLES = 10000;
- int NUM_ATTRACTORS = 15;
- Particle[] particle;
- Attractor[] attractor;
- import processing.pdf.*;
- boolean record = false;
- void setup() {
-
- size(1416,800,JAVA2D);
- attractor = new Attractor[NUM_ATTRACTORS];
- particle = new Particle[NUM_PARTICLES];
-
- scatter();
-
- }
- void draw() {
- // move and draw particles
- stroke(0,2); // use lower alpha for finer detail
-
- beginShape(POINTS);
- for (int i = 0; i < particle.length; i++) {
- particle[i].step();
- vertex(particle[i].x,particle[i].y);
- }
- endShape();
-
- // reset on mouse click
- if (mousePressed) {
- scatter();
- }
-
- }
- void scatter() {
- // clear the preview
- background(255);
- // randomise attractors
- for (int i = 0; i < attractor.length; i++) {
- attractor[i] = new Attractor();
- println("attractor["+i+"] = new Attractor("+attractor[i].x+","+attractor[i].y+");"); // so you *can* get your
- favourite one back, if you want!
- }
- println();
-
- // randomise particles
- for (int i = 0; i < particle.length; i++) {
- particle[i] = new Particle();
- }
-
- }
- // a point in space with a velocity
- // moves according to acceleration and damping parameters
- // in this case, it moves very fast so the process is basically "scattering"
- // changing these parameters can give very different results
- float damp = 0.00002; // remember a very small amount of the last direction
- float accel = 4000.0; // move very quickly
- class Particle {
- // location and velocity
- float x,y,vx,vy;
-
- Particle() {
-
- // initialise with random velocity:
- x = random(width);
- y = random(height);
-
- // initialise with random velocity:
- vx = random(-accel/2,accel/2);
- vy = random(-accel/2,accel/2);
-
- }
-
- void step() {
-
- // move towards every attractor
- // at a speed inversely proportional to distance squared
- // (much slower when further away, very fast when close)
-
- for (int i = 0; i < attractor.length; i++) {
-
- // calculate the square of the distance
- // from this particle to the current attractor
- float d2 = sq(attractor[i].x-x) + sq(attractor[i].y-y);
- if (d2 > 0.1) { // make sure we don't divide by zero
- // accelerate towards each attractor
- vx += accel * (attractor[i].x-x) / d2;
- vy += accel * (attractor[i].y-y) / d2;
- }
-
- }
-
- // move by the velocity
- x += vx;
- y += vy;
-
- // scale the velocity back for the next frame
- vx *= damp;
- vy *= damp;
-
- }
-
- }
- // this is basically just a random point
- class Attractor {
- float x,y;
- Attractor(float x, float y) {
- this.x = x;
- this.y = y;
- }
- Attractor() {
- x = random(width/8, width/8 *7); // In between 1 and 3 quarters
- y = random(height/8, height/8 *7); // of the height and width
- }
- }
- // Use a keypress so thousands of files aren't created
- void keyPressed() {
- save("Export.png");
- }
I didn't make most of this code -- credits are in the comments at the top. I just changed around the variables and added the last part that exports a PNG when a key is pressed, but the export is really low quality. How do I make a high quality export?
This is the applet I got this from http://www.processing.org/exhibition/works/metropop/applet.html
1