hivemind
YaBB Newbies
Offline
Posts: 3
why doesn't screen.width and screen.height work
Mar 18th , 2007, 9:52am
hi, I've been trying to learn processing and like most people I'm waiting for Shiffman's book to come out but until then I'm trying to work out as much as possible on my own. I found this code on the net that someone posted. Its a water simulation. I tried to get it to go fullscreen and add a background image to get a handle on the syntax. The code is fairly simple to understand but why my additions will not work is not.I thought I inserted screen.width and screen.height into the maps and size command. can someone help me fix this code to go full screen and display a background image? color col; int i,j,g; float osc=0; int x=0; int y=0; float c=0; float newmap[]=new float[width*height]; float currentmap[]=new float[width*height]; float prevmap[]=new float[width*height]; //my addition-changed 500*500 on the maps to width*height void setup(){ size(screen.width, screen.height,P3D); loadPixels(); //colorMode(RGB,2.0,1.0,1.0); //commented out colormode for PImage noCursor(); PImage w; w = loadImage("Worn wall.jpg"); image(w, 0, 0); //My addition- changed 500*500 to screen.width and screen.height //added PImage code //get a null pointer exception on image(w, 0, 0) why? for(g=0;g<width*height;g++){ currentmap[g]=0; newmap[g]=0; } } float lu(int x, int y, float array[]){ // look up a table return(array[(y*width)+x]); } void draw(){ x=mouseX; y=mouseY; osc+=.2; splash(x,y,.6); if(mousePressed); line(mouseX, mouseY, pmouseX, pmouseY); for(i=155;i>100;i--){ for(j=100;j<155;j++){ // currentmap[(width*j)+i]=.7;// } } //splash(160,100,100.,1) for(j=2;j<height-1;j++){ for(i=1;i<width-1;i++){ newmap[i+(j*width)]=.99* ((( lu(i+1, j, currentmap)+ lu(i-1, j, currentmap)+ lu(i, j+1, currentmap)+ lu(i, j-1, currentmap)+ lu(i+1, j+1, currentmap)+ lu(i+1, j-1, currentmap)+ lu(i-1, j+1, currentmap)+ lu(i-1, j-1, currentmap))/4.)-lu(i,j,prevmap)); // newmap[i+(j*width)]= newmap[i+(j*width)]- (newmap[i+(j*width)]*16); } } for(g=400;g<(width*height)-2222;g++) { // c=(newmap[g+width+1]-newmap[g-width-1]); // pixels[g]=color(0,0,atan2(.15,c)); pixels[g]=color((.1)*(1.-abs((newmap[g]))),(.7)*(.6-abs(newmap[g])), 1.-abs(newmap[g])); } arraycopy(currentmap,prevmap); arraycopy(newmap,currentmap); // currentmap=newmap; updatePixels(); } void splash(int x, int y, float power){ int sqsize=3; //intensity float a,b; if(x>=sqsize && y>=sqsize && x<width-sqsize && y<height-sqsize){ for(int xx=-sqsize;xx<sqsize;xx++){ for(int yy=-sqsize;yy<sqsize;yy++){ a=xx; b=sqsize; currentmap[((y+yy)*width)+x+xx]-=power;//(power-((a/b)*power)); } } } }