Willkommen auf unserem Seminar-Blog

Immer auf dem aktuellen Stand bleiben

Dieser Seminar-Blog befindet sich noch im Aufbau und wird in den kommenden Tagen entsprechend verfeinert.

Member Login

Lost your password?

Registration is closed

Sorry, you are not allowed to register by yourself on this site!

You must either be invited by one of our team member or request an invitation by email at viad.info {at} zhdk {dot} ch.

Recursion & 3D

21. September 2012

Recursive Funktionen ermöglichen das Zeichnen fraktaler Formen, der Aufruf einer Funktion in sich selbst braucht natürlich eine Abruchbedingung, schliesslich muss ein Algorithmus terminiert sein, andernfalls käme es zum Stackoverflow... Ich mag nachvollziehbare Dinge, schmeisse daher alle random-werte raus, und experimentiere etwas mit dem 3D renderer: code: void setup() { size(600,600,P3D); // def. fenstergroesse randomSeed(millis()); // seed random smooth(); // aktiviere antialiasing strokeWeight(1); // linienbreite noStroke(); fill(0,127,255); background(255); pushMatrix(); translate(width *.5,height/2); wurzel(7); popMatrix(); } void draw() { lights(); background(204); float cameraY = height/2.0; float fov = mouseX/float(width) * PI/2; float cameraZ = cameraY / tan(fov / 2.0); float aspect = float(width)/float(height); perspective(fov, aspect, cameraZ/10.0, cameraZ*10.0); // translate(width/2+30, height/2, 0); // rotateX(-PI/6); rotateY(mouseY/float(height) * PI); background(255); pushMatrix(); translate(width *.5,height/2); wurzel(7); popMatrix(); } void mousePressed() { saveFrame("rec-######.png"); } // funktion void wurzel(int tiefe) { if(tiefe <=0) // teste ob das ende erreicht worden ist { return; } // zeichne zweige int x; int y; for(int i = 0; i < 4;i++) { x=200; y=x; switch (i) { case 0: x = x; y = y; break; case 1: x=x; y=-y; break; case 2: x=-x; y=-y; break; case 3: x=-x; y=y; break; } box(x); pushMatrix(); translate(x/2,y/2); scale(.5); wurzel(tiefe-1); popMatrix(); } } [/sourcecode]