int w = 600; int h = 600; int min = -3; int max = 3; int scalingFactor = 30; int zoom = 0; DownhillSimplex simplex; void setup(){ size(w,h, P3D); simplex = new DownhillSimplex(new PVector(-1,-1, rosenbrock(-1,-1))); simplex.setMinChange(0.0001); } void draw(){ background(255); text("Best: " + simplex.getBest() + "\neval count: " + simplex.getNumEvals() + "\nmean change: " + (float)simplex.getChange() + " (min: " + simplex.getMinChange() + ")", 25 ,25); pushMatrix(); translate(width/2,height/2,zoom); rotateY(map(mouseX, 0, width, 0, radians(360))); rotateX(map(mouseY, 0, width, 0, radians(360))); drawAxes(); pushMatrix(); scale(scalingFactor, scalingFactor, 1/100.0); fill(0); stroke(0); for(float x = min; x < max; x+=0.05){ for(float y = min; y < max; y+=0.05){ float z = rosenbrock(x,y); point(x,y,z); } } simplex.draw(); popMatrix(); popMatrix(); } float rosenbrock(float x, float y){ return (sq(1-x) + 100*sq(y - sq(x))); } void drawAxes(){ pushStyle(); stroke(255,0,0); line(min*scalingFactor*10,0,0, max*scalingFactor*10, 0,0); stroke(0,255,0); line(0,min*scalingFactor*10,0, 0, max*scalingFactor*10,0); stroke(0,0,255); line(0,0,min*scalingFactor*10, 0, 0,max*scalingFactor*10); popStyle(); } void keyPressed(){ if(key == '='){ zoom += 100; // scalingFactor += 10; } if(key == '-'){ zoom -= 100; // scalingFactor -= 10; } if(key == ' '){ simplex.update(); } }