alphachapmtl
Full Member
Offline
Posts: 128
Canada
Re: BGraphics, BImage ??
Reply #4 - Aug 19th , 2007, 10:50am
I made all the changes I could find, like BGraphics -> PGraphics, but blobs.pde still doesn't work. Since this is a downloaded demo, (not my program), it's difficult to see what's wrong. Here is the code, in case someone wants to try it: //blobs //2007-aug-17 //from http://www.hardcorepawn.com/blobs/ int NUM_BLOBS=100; boolean keyp=false; class Blob { float x,y,vx,vy; color c; int r; PGraphics target; // Blob(int _x, int _y, PGraphics _target) Blob(int _x, int _y, int _r, PGraphics target) { x=_x; y=_y; r=_r; vx=random(-2,2); vy=random(-2,2); // target=_target; c=color(int(random(255)),int(random(255)),int(random(255)),32); } void show() { float closest=width*height; int k; boolean found=false; for(int i=int(y-r);i<int(y+r);i++) { k=i*width; if(i>=0&&i<height) { for(int j=int(x-r);j<int(x+r);j++) { if(j>=0&&j<width) { if((overlay.pixels[j+i*width]&0x000000FF)==0) { found=true; int xd=i-int(y); int yd=j-int(x); if(sqrt(xd*xd+yd*yd)<closest) { closest=sqrt(xd*xd+yd*yd); } } } } } } if(!found) { closest=width*height; } if(closest<r) { int diam=r-int(closest); int alpha=254-int((255.0/float(r))*closest); fill(red(c),green(c),blue(c),alpha); noStroke(); // ellipse(x-(diam/2),y-(diam/2),x+(diam/2),y+(diam/2)); ellipse(x-(diam/2),y-(diam/2),diam,diam); } else { noStroke(); fill(red(c),green(c),blue(c),128); ellipse(x-1,y-1,2,2); // ellipse(x-1,y-1,2,2); } }//show() void move() { if(x+vx<=0 || x+vy>width) { vx=-vx; } if(y+vy<=0 || y+vy>height) { vy=-vy; } x+=vx; y+=vy; }//move() }//class Blob class Curvepoint { float x,y,vx,vy; Curvepoint(float _x, float _y) { x=_x; y=_y; vx=random(-5,5); vy=random(-5,5); } void move() { if(x+vy>=width || x+vy<0) { vx=0-vx; vx+=random(-0.5,0.5); } if(y+vy>=height || y+vy<0) { vy=0-vy; vy+=random(-0.5,0.5); } x+=vx; y+=vy; }//move() }//class Curvepoint Blob[] blobs; Curvepoint[] points; PGraphics overlay; void setup() { size(400,400); overlay=createGraphics(width,height,P2D); overlay.stroke(0); overlay.background(0); noStroke(); background(255,255,255); blobs=new Blob[NUM_BLOBS]; points=new Curvepoint[8]; int a=int(sqrt(blobs.length)); for(int i=0;i<blobs.length;i++) { blobs[i]=new Blob(((width/a)/2)+i%a*(width/a),((height/a)/2)+(i/a)*(height/a),width/a,overlay ); } for(int i=0;i<points.length;i++) { points[i]=new Curvepoint(random(width),random(height)); } }//setup() void draw() { background(255,255,255); overlay.background(255,255,255); stroke(0); overlay.beginShape();//@@**something WRONG here ?? { for(int i=0;i<points.length;i++) { overlay.curveVertex(points[i].x,points[i].y); points[i].move(); } } overlay.endShape(); for(int i=0;i<blobs.length;i++) { blobs[i].show(); // blobs[i].move(); } if(keyp) { setup(); keyp=false; } }//draw() void keyPressed() { if(key=='a' && NUM_BLOBS<12800) { NUM_BLOBS*=2; keyp=true; } if(key=='z' && NUM_BLOBS>25) { NUM_BLOBS/=2; keyp=true; } }