We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › image and pixels array manipulation
Page Index Toggle Pages: 1
image and pixels array manipulation (Read 617 times)
image and pixels array manipulation
Dec 27th, 2006, 12:32pm
 
Hi,

i'm new at processing and i wonder how to rotate an image by 45° using image's pixels array. (I've look a little bit at exemples and reference but i can't figure how to make that work) It means that the top left corner will become the bottom left one.

As far as i understood the pixel array is fed by an horizontal scan of the pixel included in the image. The main idea is that i want to assign an degree of rotation to a midi controller and to rotate the flow of pixel as i rotate the knob. My main idea is to start with the linear image exemple and make it go from left to right and later to make a rotation. I'm not wondering how to make the scanning of the pixels change but the displaying of the scanning.

I've try with some loops but it didn't work. Would it be better to use matrix or loops for that.

And is there somewhere an algorithm for simulate acceleration with the midi controller. It means that if the midi controller is at full the acceleration will increase in an exponential way and if it's at minus it will decrease until it stops.

Sorry if my english is confusing.

Cheers
Re: image and pixels array manipulation
Reply #1 - Dec 28th, 2006, 7:38pm
 
hi,

not sure this is what you are looking for ... try writing into an images pixel-array instead of the applets. then you can just rotate the view and draw a rotated version of the image you just wrote the pixels to. for example:

Code:

/**
* based on Processing's Linear Image example.
*/

PImage a, b;
boolean onetime = true;
int[] aPixels = new int[200*200];
int direction = 1;

float signal;

void setup()
{
size(200, 200);
stroke(255);
a = loadImage("florence03.jpg");
b = loadImage("florence03.jpg"); // just to have something in there to start with
frameRate(30);
}
int r = 0;
void draw()
{
if (signal > width-1 || signal < 0) {
direction = direction * -1;
}

if(mousePressed) {
signal = abs(mouseY%height);
} else {
signal += (0.3*direction);
}

if(keyPressed) {
image( a, 0, 0 );
line(0, signal, width, signal);
} else {
b.loadPixels();
for (int i=0; i<width*height; i++) {
// write into b's pixel-buffer
b.pixels[i] = a.pixels[int((width*int(signal))+(i%width))];
}
b.updatePixels();
// translate and rotate view, then draw b into it
translate( width/2, height/2 );
rotate( (millis()/600.0)%360 );
image( b, -b.width/2, -b.height/2 );
}

}


make the second question another thread, otherwise it's not gonna be answered .. i guess.

F
Re: image and pixels array manipulation
Reply #2 - Dec 29th, 2006, 9:05am
 
oh ok i didn't saw the function rotate and translate thx a lot i'll give a try as soon as possible Smiley.
Page Index Toggle Pages: 1