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 & HelpSyntax Questions › porting p68 code to p128
Page Index Toggle Pages: 1
porting p68 code to p128 (Read 392 times)
porting p68 code to p128
Oct 31st, 2007, 8:50pm
 
Hello,

I'm desperately trying to get this great piece of code from Harukit to work on Processing0128, though I can't seem to find the right trick. it works perfectly on Processing68.

any help will be much appreciated!

thanks,
sb


// Shining Particle by harukit
// Created with Processing 68 alpha on September 11 , 2004
// http://www.harukit.com


int pNum =4;
Particle[] p = new Particle[pNum];
float rr,gg,bb,dis;
int gain = 5;
float[] cc = new float[3];

void setup(){
 size(200,200);
 noStroke();
 background(0);
 for(int i=0;i<3;i++){
   cc[i]=random(40)+random(40)+random(40)+random(40)+random(40);
 }
 for(int i=0;i<pNum;i++){
   p[i] = new Particle(random(width),random(height),random(0.1,0.3));
 }
}

void loop(){
 for(int i=0;i<pNum;i++){
   p[i].update();
 }
 for(int y=0;y<height;y++){
   for(int x=0;x<width;x++){
       int pos=y*width+x;
       color col = pixels[pos];
       rr = col >> 16 & 0xff;
       gg = col >> 8 & 0xff;
       bb = col  & 0xff;
       for(int i=0;i<pNum;i++){
         dis =dist(p[i].xpos,p[i].ypos,x,y)/2;
         rr += cc[0]/dis-gain;
         gg += cc[1]/dis-gain;
         bb += cc[2]/dis-gain;
       }
       pixels[pos]=color(rr,gg,bb);
   }
 }
}

void mousePressed(){
 background(0);
 Particle[] p = new Particle[pNum];
}

void mouseReleased(){
 for(int i=0;i<3;i++){
   cc[i]=random(40)+random(40)+random(40)+random(40)+random(40);
 }
 background(0);
 for(int i=0;i<pNum;i++){
   p[i] = new Particle(random(width),random(height),random(0.1,0.3));
 }
}

class Particle{
 float xpos,ypos,del;
 Particle(float x,float y,float d){
   xpos=x;
   ypos=y;
   del = d;
 }
 void update(){
   xpos += (mouseX-xpos)*del;
   ypos += (mouseY-ypos)*del;
 }
}

Re: porting p68 code to p128
Reply #1 - Oct 31st, 2007, 9:02pm
 
the changes are covered in the docs:
http://processing.org/reference/changes.html#alpha
look for mention of using pixels[].
Page Index Toggle Pages: 1