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.
IndexDiscussionExhibition › any ideas on how to improove it
Page Index Toggle Pages: 1
any ideas on how to improove it? (Read 1331 times)
any ideas on how to improove it?
Nov 3rd, 2009, 3:04am
 
// koubia: r,t,y,f,g,h,q,a : +r,+g,+b,-r,-g,-b,+r+g+b,-r-g-b, kounontas to mouse mesa sto parathiro

int possa = 150;
float x[][] = new float [possa+3][possa+3]; //x  
float y[][] = new float [possa+3][possa+3]; //y
float r[][] = new float [possa+3][possa+3]; //color
float g[][] = new float [possa+3][possa+3]; //color
float b[][] = new float [possa+3][possa+3]; //color
float m[] = new float [possa+3]; //color
int metr = 0;
int i;
int j;
int apostash = 4;
float plus = 50000;
float misiapostash = apostash/2;
int sp = 2; //sinplin

void setup(){
  noStroke();
  rectMode(CENTER);
  noStroke();
  size(possa*apostash,possa*apostash);
  frameRate(30);
  for (int i = 0; i < possa; i++) {
    for (int j = 0; j < possa; j++) {
      x[i][j] = +i*apostash;
      y[i][j] = +j*apostash;
      r[i][j] = 0;
      g[i][j] = 0;
      b[i][j] = 0;
    }
  }
}

void draw(){
background(0);
 for (i = 2; i < possa-2; i++) {
   for (j = 2; j < possa-2; j++) {
     fill(r[i][j],g[i][j],b[i][j],255);
     col();
     float megethos = apostash;//map((r[i][j]+g[i][j]+b[i][j])/3,0,plus,apostash,apostash+2);
     //if (megethos>50){megethos = apostash;}
     if (r[i][j] > 0 || g[i][j]>0 ||b[i][j] > 0){
       rect(x[i][j],y[i][j],megethos,megethos);  
     }
    }  
   }
}
void col(){
 if ((mouseX > x[i][j]-sp-misiapostash) && (mouseX < x[i][j]+misiapostash+sp)  && (mouseY > y[i][j]-sp-misiapostash) && (mouseY < y[i][j]+misiapostash+sp)) {
 
 if (key == 'a') {
   r[i][j] = -plus;
   g[i][j] = -plus;
   b[i][j] = -plus;
 }
 if (key == 'q') {
   r[i][j] = plus;
   g[i][j] = plus;
   b[i][j] = plus;
 }
 
 if (key == 'r') {
     r[i][j] = plus;
 }
 
 if (key == 't') {
     g[i][j] = plus;
 }
 if (key == 'y') {
     b[i][j] = plus;
 }
 
 if (key == 'f') {
     r[i][j] = -plus;
 }
 
 if (key == 'g') {
     g[i][j] = -plus;
 }
 
 if (key == 'h') {
     b[i][j] = -plus;
 }
}

r[i][j] = (r[i][j] + r[i][j+1] +r[i][j-1] +r[i+1][j] +r[i-1][j])/5;
g[i][j] = (g[i][j] + g[i][j+1] +g[i][j-1] +g[i+1][j] +g[i-1][j])/5;
b[i][j] = (b[i][j] + b[i][j+1] +b[i][j-1] +b[i+1][j] +b[i-1][j])/5;

}
Re: any ideas on how to improove it?
Reply #1 - Nov 3rd, 2009, 3:27am
 
From size():

The size() function must be the first line in setup().

I'd be a little wary of basing size() on variables too, and would instead base the variables on the width/height of the applet; though that's just a personal preference...

It would also be good to set the default start colour as something visible:  Initially I didn't think it worked because nothing seemed to happen.  I know you would probably add written instructions, but it's good to make things as intuitive as possible, e.g. for the case in which someone doesn't understand the instructions...

Anyway it's a nice effect Smiley
Re: any ideas on how to improove it?
Reply #2 - Nov 4th, 2009, 8:17pm
 
Nice one.

The way it diffuses reminds me of Diffusion/Reaction algorithms.
Perhaps you are familiar with them, anyway, here's a nice java applet I found:

http://texturegarden.com/java/rd/

You can also check fluid dynamics algorithms, could be a way to add some more dynamism to the result.
Just for readability, I would suggest translating the variables to english.
(I can understand because we speak the same language, but it'd be nice for everyone, I think  Smiley )

Again, nice example.
Re: any ideas on how to improove it?
Reply #3 - Nov 6th, 2009, 5:20pm
 
thank u / you are both right, il try to do what u said but for now there is an improoved version:

// buttons(while moving the mouse):
//r for +r
//t for +g
//y for +b
//q for white
//
//f for -r
//g for -g
//h for -b
//a for black
//
//c for freezing screen
//e for defining where to paint next (after at least 1 c)
//
//right click for a tiff snapshot  

int howmany = 120;

float x[][] = new float [howmany+3][howmany+3]; //x  
float y[][] = new float [howmany+3][howmany+3]; //y
float r[][] = new float [howmany+3][howmany+3]; //color
float g[][] = new float [howmany+3][howmany+3]; //color
float b[][] = new float [howmany+3][howmany+3]; //color
float m[] = new float [howmany+3]; //color
float enable[][] = new float [howmany+3][howmany+3]; //works = 1, not = 0;
float transp[][] = new float [howmany+3][howmany+3]; //color

int i;
int j;
int howbig = 4;
float plus = 50000;

float halfhowbig = howbig/2;

int sp = 2; //sinplin
void setup(){
 size(howmany*howbig-howbig*4-2,howmany*howbig-howbig*4-2);  
 noStroke();
  rectMode(CENTER);
  frameRate(30);
  for (int i = 0; i < howmany; i++) {
    for (int j = 0; j < howmany; j++) {
      x[i][j] = +i*howbig;
      y[i][j] = +j*howbig;
      r[i][j] = 0;
      g[i][j] = 0;
      b[i][j] = 0;
      enable[i][j] = 1;
      transp[i][j] = 255;
    }
  }
}

void draw(){
 
 translate(-howbig*2,-howbig*2);
 
//background(0);
 for (i = 2; i < howmany-2; i++) {
   
   r[i][1] = r[i][howmany-3];//r[0][howmany];
   g[i][1] = g[i][howmany-3];
   b[i][1] = b[i][howmany-3];
   
   for (j = 2; j < howmany-2; j++) {
     enableit();
     
     
     fill(r[i][j],g[i][j],b[i][j],50);
     
     col();
     
     float size = howbig;//map((r[i][j]+g[i][j]+b[i][j])/3,0,plus,howbig,howbig+2);
         //if (r[i][j] > 0 || g[i][j]>0 ||b[i][j] > 0 ){
           if (enable[i][j] > 0){
             rect(x[i][j],y[i][j],size,size);  
     
     }
   }  
   
 }
 
 saveimage();
 changemind();
}

void changemind(){
if (key == 'c') {
  for (i = 2; i < howmany-2; i++) {
    for (j = 2; j < howmany-2; j++) {

      enable[i][j] = 0;
     
    }
  }

}  
}

void enableit(){

 if (key == 'e') {
   
  if (dist(mouseX,mouseY,x[i][j],y[i][j]) < 20){

    enable[i][j] = 100;
   
  }

}
}
     
void saveimage(){
 if (mousePressed && (mouseButton == RIGHT)) {
   saveFrame("image-####.tif");
 }
}

void col(){

if ((mouseX > x[i][j]-sp-halfhowbig) && (mouseX < x[i][j]+halfhowbig+sp)  && (mouseY > y[i][j]-sp-halfhowbig) && (mouseY < y[i][j]+halfhowbig+sp)) {

 if (key == 'a') {
   r[i][j] = -plus;
   g[i][j] = -plus;
   b[i][j] = -plus;
 }
 if (key == 'q') {
   r[i][j] = plus;
   g[i][j] = plus;
   b[i][j] = plus;
 }
 
 if (key == 'r') {
     r[i][j] = plus;
 }
 
 if (key == 't') {
     g[i][j] = plus;
 }
 if (key == 'y') {
     b[i][j] = plus;
 }
 
 if (key == 'f') {
     r[i][j] = -plus;
 }
 
 if (key == 'g') {
     g[i][j] = -plus;
 }
 
 if (key == 'h') {
     b[i][j] = -plus;
 }
}

r[i][j] = (r[i][j] + r[i][j+1] +r[i][j-1]*1.3 +r[i+1][j] +r[i-1][j])/5.3;
g[i][j] = (g[i][j] + g[i][j+1] +g[i][j-1]*1.3 +g[i+1][j] +g[i-1][j])/5.3;
b[i][j] = (b[i][j] + b[i][j+1] +b[i][j-1]*1.3 +b[i+1][j] +b[i-1][j])/5.3;

}
Re: any ideas on how to improove it?
Reply #4 - Nov 7th, 2009, 11:59am
 
is there any way to make it faster? if i increase the rects (int howmany) it can get very slow
Re: any ideas on how to improove it?
Reply #5 - Nov 14th, 2009, 10:16am
 
Page Index Toggle Pages: 1