import processing.opengl.*; float zoom = -600; int detail = 1; float coef = 10; float xmag, ymag = 0; float newXmag, newYmag = 0; float[] tamponX = new float[0]; float[] tamponY = new float[0]; float[] tamponZ = new float[0]; lorenzAttractor L = new lorenzAttractor (); void setup (){ size (500, 400, P3D); //smooth (); } void draw (){ background (0); translate (width/2, height/2, zoom); newXmag = mouseX/float(width) * TWO_PI; newYmag = mouseY/float(height) * TWO_PI; float diff = xmag-newXmag; if (abs(diff) > 0.01) { xmag -= diff/4.0; } diff = ymag-newYmag; if (abs(diff) > 0.01) { ymag -= diff/4.0; } rotateX(-ymag); rotateY(-xmag); stroke (255); beginShape(LINES); for (int n = detail; n < L.i; n += detail){ vertex (tamponX[n]*coef, tamponY[n]*coef, tamponZ[n]*coef); vertex (tamponX[n-detail]*coef, tamponY[n-detail]*coef, tamponZ[n-detail]*coef); } endShape(); if (L.i > 2){ translate (tamponX[L.i-1]*coef, tamponY[L.i-1]*coef, tamponZ[L.i-1]*coef); fill (255, 0, 0); noStroke (); box (5); } tamponX = append (tamponX, L.x0); tamponY = append (tamponY, L.y0); tamponZ = append (tamponZ, L.z0); L.getCoord (); } // lorenzAttractor.as // class de calcul de coordonnés 3d à partir des equations de lorenz class lorenzAttractor { int i; float h,a,b,c,x0,y0,z0,x1,y1,z1; lorenzAttractor() { i = 0; h = 0.01; a = 10.0; b = 28.0; c = 8.0/3.0; x0 = 0.1; y0 = 0; z0 = 0; } void getCoord() { x1 = x0+h*a*(y0-x0); y1 = y0+h*(x0*(b-z0)-y0); z1 = z0+h*(x0*y0-c*z0); x0 = x1; y0 = y1; z0 = z1; i ++; } } void keyPressed() { if (key == CODED) { if (keyCode == UP) { zoom += 4; } else if (keyCode == DOWN) { zoom -= 4; } if (keyCode == LEFT) { detail ++; } else if (keyCode == RIGHT) { if (detail > 1){ detail --; } } } }