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 › rotations and trails
Page Index Toggle Pages: 1
rotations and trails (Read 667 times)
rotations and trails
Oct 31st, 2005, 8:47pm
 
Hi

I am trying to reverse the rotation / trail effect of an image - let me explain.  say you have a square which you want to rotate in the centre of the screen around its top left corner, it rotates and leaves a trail behind it.  What I actually want to produce is to leave the square where it is but have the trail rotate around.  So instead of the image itself moving the trail does.  I thought the best way to do this would be to produce a large square, roate the large square an increment at a time in a draw()  and then print my image on to it (always on the same position relative to the screen) so in effect the last time the draw() printed the image it will be turned but the current image will stay in the correct position.  Sorry there is no code but its a mess of several compltely different tries - not necessarily looking for somebody to hand me code readymade but...

a) is this the best way to do what I am trying to do and
b) how do i change pixels of a image, i can see how pixels of the screen are changed but an image??

thanks for any help in advance

a+
gar
Re: rotations and trails
Reply #1 - Nov 2nd, 2005, 5:23pm
 
Rotation:
Code:

// Storing Input
// by REAS <http://reas.com>
int num = 60;
float theta = 0.0;
float mx[] = new float[num];
float my[] = new float[num];
void setup()
{
size(200, 200);
fill(255, 153);
framerate(60);
rectMode(CENTER);
}
void draw()
{
background(51);
theta = (theta + 0.1) % TWO_PI;
// Reads throught the entire array
// and shifts the values to the left
for(int i=1; i<num; i++) {
mx[i-1] = mx[i];
my[i-1] = my[i];
}
// Add the new values to the end of the array
mx[num-1] = mouseX;
my[num-1] = mouseY;
for(int i=0; i<num; i++) {
pushMatrix();
translate(mx[i], my[i]);
if(i != num-1)
rotate(theta);
rect(0, 0, i/2, i/2);
popMatrix();
}
}

You can use get()/set() to change pixels in a stored image, using pixels[] is faster though (pixels[x + y * pimage.width]). You will have to use updatePixels() to effect the changes. You may want to do a search for PGraphics3 on the forum if you are interested in drawing to an image buffer. It's buggy but very useful.
Page Index Toggle Pages: 1