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 › Dreamlines not showing anything drawing....
Page Index Toggle Pages: 1
Dreamlines not showing anything drawing.... (Read 638 times)
Dreamlines not showing anything drawing....
Nov 3rd, 2006, 6:10am
 
There isn't anything drawing in the window, odd, everything is setup fine, it executes fine, but nothing show up in the PGraphics department... Please help if you can


int cant=1500;

BGraphics img;
BImage inimg;
String id, archivo;
int n, nimg, enes, trazo;
float t;

Dot[] dots;

void setup(){
 size(640, 480);
 colorMode(HSB,360);
 background(360);
 
 id=param("id");
 img= new BGraphics(width,height);
 img.colorMode(HSB,360);
 trazo=int(random(8));
 nimg=-1;
 cargarImg();
 
 dots= new Dot[cant];
 for(int i=0; i<cant; i++){
   dots[i]=new Dot();
 }
}

void loop(){
 n++;
 if(n==500){
   cargarImg();
 }
 if(int(random(500))==1) trazo=int(random(8));
 for(int i=0; i<cant; i++){
   dots[i].paso();
 }
}

void cargarImg(){
 t=millis();
 nimg++; n=0;
 String cant[]=loadStrings("imgs/"+id+".txt");
 enes=Integer.parseInt(cant[0]);
 if(nimg==enes){nimg=0;}
 
 archivo=id+"_"+String(nimg)+".jpg";
 inimg=loadImage("imgs/"+archivo);
 img.image(inimg,0,0,width,height);

 t=millis()-t;
}

class Dot {
 float ax, ay, x, y;
 float ang, step;
 float h, s, b;
 color pix, este;
 int p;
 Dot(){
   iniciar();
   ang=random(TWO_PI);
   step=random(3);
   leer();
   este=(pix);
 }
 void paso(){
   if(int(random(cant/2))==1) iniciar();
   leer();
   stroke(h, s, b, 40);
   switch(trazo){
     case 0:
     ang+=radians(b-180)/5;
     step=(h-180)/10; break;
     case 1:
     ang+=radians(s-180)/3;
     step=(b-180)/25; break;
     case 2:
     ang=radians(h-180);
     step=(s-180)/10; break;
     case 3:
     ang=radians(s-180);
     step=(h-180)/12; break;
     case 4:
     ang+=radians(h-s);
     step=(b-h)/6; break;
     case 5:
     ang+=radians(b-h)/20;
     step=(s-180)/5; break;
     case 6:
     ang+=radians(h-180)/10;
     step=(b-180)/4; break;
     case 7:
     ang+=radians(h-180)/(constrain(b/10,1,100));
     step=(b-180)/(constrain(s/10,1,100)); break;
 }
 x+=(step*sin(ang));
 y-=(step*cos(ang));
 line(ax, ay, x, y);
 ax=x; ay=y;

 if (x<0){ax=x=width;}
 if (x>width){ax=x=0;}
 if (y<2){ay=y=height-3;}
 if (y>height-2){ay=y=3;}
 }
 void leer(){
   p=int(y)*img.width+int(x);
   pix=img.pixels[p];
   b=brightness(pix);
   h=hue(pix);
   s=saturation(pix);
 }
 void iniciar(){
   ax=x=random(width);
   ay=y=random(height);
 }
}

Re: Dreamlines not showing anything drawing....
Reply #1 - Nov 3rd, 2006, 10:29am
 
a: BGraphics and BImage? Those need updating to PGraphics (and createGraphics instead of "new PGraphics") and PImage

b: it's "void draw()" now not "void loop()"
Re: Dreamlines not showing anything drawing....
Reply #2 - Nov 3rd, 2006, 1:31pm
 
JohnG, I a very grateful for your assistance, the PGraphics change and the Draw from the LOOP change fixed everything... here is the new code if anyone wants it..


•••••••••••••••••••••••••••••••••••••••••••

int cant=1500;

PGraphics img;
PImage inimg;
String id, archivo;
int n, nimg, enes, trazo;
float t;

Dot[] dots;

void setup(){
 size(640, 480);
 colorMode(HSB,360);
 background(360);
 
 id=("imagelist");
 img=createGraphics(640, 480, JAVA2D);
 img.colorMode(HSB,360);
 trazo=int(random(8));
 nimg=-1;
 cargarImg();
 
 dots= new Dot[cant];
 for(int i=0; i<cant; i++){
   dots[i]=new Dot();
 }
}

void draw(){
 n++;
 if(n==500){
   cargarImg();
 }
 if(int(random(500))==1) trazo=int(random(8));
 for(int i=0; i<cant; i++){
   dots[i].paso();
 }
}

void cargarImg(){
 t=millis();
 nimg++; n=0;
 String cant[]=loadStrings(id+".txt");
 enes=Integer.parseInt(cant[0]);
 if(nimg==enes){nimg=0;}
 
 archivo=id+"_"+(nimg)+".jpg";
 inimg=loadImage(archivo);
 
 img.image(inimg, 0, 0, width, height);

 t=millis()-t;
}

class Dot {
 float ax, ay, x, y;
 float ang, step;
 float h, s, b;
 color pix, este;
 int p;
 Dot(){
   iniciar();
   ang=random(TWO_PI);
   step=random(3);
   leer();
   este=(pix);
 }
 void paso(){
   if(int(random(cant/2))==1) iniciar();
   leer();
   stroke(h, s, b, 40);
   switch(trazo){
     case 0:
     ang+=radians(b-180)/5;
     step=(h-180)/10; break;
     case 1:
     ang+=radians(s-180)/3;
     step=(b-180)/25; break;
     case 2:
     ang=radians(h-180);
     step=(s-180)/10; break;
     case 3:
     ang=radians(s-180);
     step=(h-180)/12; break;
     case 4:
     ang+=radians(h-s);
     step=(b-h)/6; break;
     case 5:
     ang+=radians(b-h)/20;
     step=(s-180)/5; break;
     case 6:
     ang+=radians(h-180)/10;
     step=(b-180)/4; break;
     case 7:
     ang+=radians(h-180)/(constrain(b/10,1,100));
     step=(b-180)/(constrain(s/10,1,100)); break;
 }
 x+=(step*sin(ang));
 y-=(step*cos(ang));
 line(ax, ay, x, y);
 ax=x; ay=y;

 if (x<0){ax=x=width;}
 if (x>width){ax=x=0;}
 if (y<2){ay=y=height-3;}
 if (y>height-2){ay=y=3;}
 }
 void leer(){
 
 println (cant);
 println (archivo);
 println (id);
 println (enes);
 println (img);
 println (inimg);
 println (nimg);
 println (n);

   p=int(y)*img.width+int(x);
   println (p);

   img.loadPixels();
   pix=img.pixels[p];
   b=brightness(pix);
   h=hue(pix);
   s=saturation(pix);
   img.updatePixels();
   }
 void iniciar(){
   ax=x=random(width);
   ay=y=random(height);
 }
}

Re: Dreamlines not showing anything drawing....
Reply #3 - Nov 3rd, 2006, 1:47pm
 
P.S. It works...  I used the JAVA2D renderer and man.... it is SLOW!!!!!!..  is there anyway o do this with the P2D renderer, or OpenGL renderer.  Though I did notice the same calls to JAVA2D didn't work in P2D, in fact I think they took some of them out of P2D and left them in JAVA2D...  Thansk so much
Page Index Toggle Pages: 1