Blowing up an image using pixels[]
in
Programming Questions
•
3 months ago
hello,
I was blowing up an image after looking at the examples from Processing, and it works great, however I was wondering if there was a better way to implement this, because it works fine from cellsize=5, but lower cellsizes like "3" takes a lot of work.
should I have to use libraries like "three.js"?
Here's the code, you can test it with some image.
- PImage img;
- int res = 5; //resolution or cellsize
- boolean click = false;
- float tiempo;
- void setup() {
- size(1024, 720, P3D);
- img = loadImage("F1000009.jpg");
- }
- void draw() {
- background(0);
- //image to center
- translate(width/2-img.width/2, height/2-img.height/2);
- if (click) {
- img.loadPixels();
- for ( int x = 0; x < img.width; x+=res) {
- for ( int y = 0; y < img.height; y+=res) {
- color c = img.pixels[x + y*img.width];
- //explotion function
- float z = (log(1+tiempo/10.0)) * brightness(c);
- pushMatrix();
- translate(0, 0, z);
- fill(c);
- noStroke();
- rect(x, y, res, res);
- popMatrix();
- }
- }
- tiempo++;
- println(frameRate);
- }
- else {
- image(img, 0, 0);
- }
- }
- void mousePressed() {
- click=!click;
- tiempo=0;
- }
1