/* * tracer des cercles et autres objets avec des vertices * */ PVector VCentre ; // centre du microscope float r ; // Rayon du microscope int sides ; // forme du cercle (sides faible = kaleidoscope plutôt) color colBkgnd, colQ1, colQ2, colQ3, colQ4 ; void setup() { size(600, 400) ; colorMode(HSB, 360, 100, 100, 100); VCentre = new PVector( 0, 0) ; r = 70 ; sides = 30 ; // avec 30 on a un cercle très bien déjà colBkgnd = #FFFFFF ; colQ1 = color( random(100, 250) , random(50,100), random(60,90), random(60,80) ) ; colQ2 = color( random(100, 250) , random(50,100), random(60,90), random(60,80) ) ; colQ3 = color( random(100, 250) , random(50,100), random(60,90), random(60,80) ) ; colQ4 = color( random(100, 250) , random(50,100), random(60,90), random(60,80) ) ; } void draw() { background( colBkgnd ) ; // Quadrant 1 (Nord Ouest) on trace un cercle dans un rect() VCentre = new PVector( width/4,height/4) ; stroke(#FFFFFF) ; strokeWeight(2); fill( colQ1 ) ; rect(0,0,width/2,height/2) ; beginShape(); drawCircle( VCentre, sides, r, true ) ; // true draws anticlockwise, false clockwise endShape(CLOSE); // Quadrant 2 (Sud Ouest) on trace un trou circulaire dans un rectangle noStroke() ; fill( colQ2 ); beginShape(); vertex( 0, height/2 ); vertex( width/2, height/2 ); vertex( width/2, height ); vertex( 0, height ); VCentre = new PVector( width/4,3*height/4) ; stroke(#FFFFFF) ; strokeWeight(2); beginContour(); // http://doc.gold.ac.uk/CreativeComputing/creativecomputation/?page_id=1142 // must be counterclockwise for a contour !!!! drawCircle( VCentre, sides, r, true ) ; // true draws anticlockwise, false clockwise endContour(); endShape(CLOSE); // Quadrant 3 (Nord Est) on trace un doughnut noStroke() ; fill( colQ3 ); beginShape(); VCentre = new PVector( 3*width/4,height/4) ; stroke(colQ3) ; strokeWeight(2); // on trace un cercle par dessus le rectangle drawCircle( VCentre, sides, 1.2*r, false ) ; beginContour(); // http://doc.gold.ac.uk/CreativeComputing/creativecomputation/?page_id=1142 // must be counterclockwise for a contour !!!! drawCircle( VCentre, sides, 0.8*r, true ) ; // true draws anticlockwise, false clockwise endContour(); endShape(CLOSE); // Quadrant 4 (Sud Est) on trace un doughnut dans un rectangle noStroke() ; fill( colQ4 ); beginShape(); vertex( width/2, height/2 ); vertex( width, height/2 ); vertex( width, height ); vertex( width/2, height ); VCentre = new PVector( 3*width/4,3*height/4) ; stroke(colQ4) ; strokeWeight(2); beginContour(); drawCircle( VCentre, sides, 1.2*r, true ) ; endContour(); endShape(CLOSE); beginShape() ; fill( colQ4 ); drawCircle( VCentre, sides, 0.8*r, false ) ; // true draws anticlockwise, false clockwise endShape(CLOSE); } void drawCircle(PVector Centre, int sides, float r, boolean aclockw) { // http://vormplus.be/blog/article/drawing-a-cylinder-with-processing float angle = 360 / sides; if ( aclockw ) { for (int i = sides; i >0 ; i--) { float x = Centre.x + cos( radians( i * angle ) ) * r; float y = Centre.y + sin( radians( i * angle ) ) * r; vertex( x, y ); // println( i, " - ", i * angle ) ; } } else if ( !aclockw ) { for ( int i = 0 ; i < sides ; i++) { float x = Centre.x + cos( radians( i * angle ) ) * r; float y = Centre.y + sin( radians( i * angle ) ) * r; vertex( x, y ); // println( i, " - ", i * angle ) ; } } }