archo_p
YaBB Newbies
Offline
Posts: 9
CA
beginnger stuck: for function not exiting
Jul 2nd , 2008, 10:13pm
Hello Processing Community, I started learning processing from the new book a few months ago, and it has been a blast to learn programming from this angle. I have a background in architecture (graduated 2 years ago) but a heavy interest in programming which I would like to use for design and art. Recently I have been trying to learn the ropes of using processing for 'VJ' and music visualization purposes. I am still learning all I can, and recently came against a wall whilst trying to carry out a simple exercise in creating a 2dimensional grid in 3d space. I successfully made one that starts as a grid and undulates to sine and cosine as you increase certain parameters (using controlP5). I am now trying to structure the program more ( using classes) so that I can create multiple grids and control the point values better (using cellular automata, fft data, etc.) In doing this I have come up against an annoying problem when I try to iterate over my 2D array of 'y-values' for the grid. I have been awaiting my chance to get involved on the forums and start learning from all of you out there, so I suppose this a great time to start! I am sure the problem at hand is something that I have just overlooked, and would love help nailing it down. I am also sure that the way in which I have made these grids is rather inefficient and would welcome pointers to hone the code while keeping control flexibility intact ( being able to render lots of different shapes at the points, and use different equations and rules to move and pulsate the grid). Following is my original, successful code, unclassed and laid out relatively simply: import controlP5.*; import processing.opengl.*; float zn = 75; float xn = 75; float xrange = 600; float zrange = 600; float ypos = 200; float zcenter = -200; float xcenter = 0; float xstart; float xend; float xint; float zstart; float zend; float zint; float[][] grid1y; float[] grid1z; float[] grid1x; float metroN = 0; float tempo = .5; float direction = 1; float yamp = 0; float waveFreq = 0; ControlP5 controlP5; ControlWindow controlWindow; void setup(){ size(1200,800, OPENGL); background(0); frameRate(20); stroke(255); fill(255); smooth(); colorMode(HSB, 360, 100, 100); controlP5 = new ControlP5(this); controlP5.setAutoDraw(false); controlWindow = controlP5.addControlWindow("controlP5window",100,100,400,500); controlWindow.setBackground(color(40)); Controller yampSlider = controlP5.addSlider("yamp",0,50,10,10,200,20); yampSlider.setWindow(controlWindow); Controller wavefreqSlider = controlP5.addSlider("waveFreq",0,50,10,30,200,20); wavefreqSlider.setWindow(controlWindow); xstart = -(xrange/2) + xcenter; xend = (xrange/2) + xcenter; zstart = -(zrange/2) + zcenter; zend = (zrange/2) + zcenter; grid1y = new float[(int)xn][(int)zn]; grid1z = new float[(int)zn]; grid1x = new float[(int)xn]; xint = xrange/xn; zint = zrange/zn; for ( int i = 0; i < zn; i++){ grid1z[i] = zstart + i*(zint); } for ( int i = 0; i < xn; i++){ grid1x[i] = xstart + i*(xint); } xint = xrange/xn; zint = zrange/zn; } void draw(){ background(0); camera(0, 0, 500.0, // eyeX, eyeY, eyeZ 0.0, 0.0, 0.0, // centerX, centerY, centerZ 0.0, 1.0, 0.0); // upX, upY, upZ for(int i = 0; i<xn-1; i ++){ for(int g = 0; g < zn-1; g ++){ grid1y[i][g] = (sin(metroN - map(i,0,xn-1,0,PI)*waveFreq)-(cos(metroN - map(g,0,zn-1,0,PI)*waveFreq)))*yamp; } } for(int x=1; x< xn-1; x++){ line(grid1x[x], ypos+grid1y[x][(int)zn-1], grid1z[(int)xn-1],grid1x[x]+xint, ypos+grid1y[x][(int)zn-1], grid1z[(int)zn-1]); for(int z = 1; z<zn-1; z++){ line(grid1x[x], ypos+grid1y[x-1][z], grid1z[z], grid1x[x]+xint, ypos+grid1y[x][z], grid1z[z]); line(grid1x[x], ypos+grid1y[x][z-1], grid1z[z], grid1x[x], ypos+grid1y[x][z], grid1z[z]+xint); } } for(int z = 0; z<zn-1; z++){ line(grid1x[(int)xn-1], ypos+grid1y[(int)xn-1][z], grid1z[z],grid1x[(int)xn-1], ypos+grid1y[(int)xn-1][z], grid1z[z]+zint); } metroN += (tempo * direction); } continued in first reply...