/* * Demonstration of a rotational mandala (albeit, not a very artistic one) * * Author: Michael Goldwasser */ void setup() { size(700, 700); } // This is the main draw for the entire sketch. void draw() { background(0); translate(0.5*width, 0.5*height); // put origin at center of canvas // draw a square (the hard way) fill(255); pushMatrix(); rotate(QUARTER_PI); regularPolygon(4, 480); popMatrix(); stroke(255,255,0); strokeWeight(3); fill(127); ellipse(0, 0, 505, 505); stroke(0); strokeWeight(3); fill(255, 0, 0); regularPolygon(8, 200); fill(56, 183, 240); star(8, 100, 200); stroke(0); strokeWeight(30); stamp(new Point(), 8, 100, 1.0, PI/8); stamp(new Smiley(), 8, 200, 1, 0); stamp(new Smiley(), 1, 0, 1.25, -HALF_PI); // single smiley in middle fill(56, 183, 240); stamp(new Arrow(), 4, 300, 0.7, QUARTER_PI); fill(255, 0, 0); stamp(new Arrow(), 4, 300, 0.7, HALF_PI); save("mandala.jpg"); } //****************************************************** // The following are examples of how to define a "Pattern" // for this project, which should draw an image // about the (0,0) origin. // // We offer these as examples, but you are to develop // your own shapes for this project //****************************************************** // A simple example of a Pattern consisting of a single point // Note that stroke color and width can be set before use // to provide variance in color and size class Point implements Pattern { void draw() { point(0,0); // draw one point at origin } } // An example of a right-facing Arrow class Arrow implements Pattern { void draw() { // Note: we assume fill color is set prior to this function. stroke(0); strokeWeight(1); beginShape(); vertex(-50, -25); vertex(50, -25); vertex(50, -50); vertex(100, 0); vertex(50, 50); vertex(50, 25); vertex(-50, 25); endShape(CLOSE); } } // An example of a smiley face class Smiley implements Pattern { // draw a smiley face centered around the origin void draw() { color faceColor = color(255, 255, 0); // white color irisColor = color(56, 183, 240); color mouthColor = color(243, 23, 56); // general face fill(faceColor); stroke(0); strokeWeight(1); ellipse(0, 0, 100, 100); // eyes float eyeWidth = 20; float eyeGap = 15; float eyeY = -15; fill(255); ellipse(-eyeGap, eyeY, eyeWidth, eyeWidth); ellipse(eyeGap, eyeY, eyeWidth, eyeWidth); noStroke(); fill(irisColor); ellipse(-eyeGap, eyeY, 0.6*eyeWidth, 0.6*eyeWidth); ellipse(eyeGap, eyeY, 0.6*eyeWidth, 0.6*eyeWidth); fill(0); ellipse(-eyeGap, eyeY, 0.35*eyeWidth, 0.35*eyeWidth); ellipse(eyeGap, eyeY, 0.35*eyeWidth, 0.35*eyeWidth); // mouth noFill(); stroke(mouthColor); strokeWeight(5); arc(0, 0, 60, 60, 0.25*PI, 0.75*PI); } } //****************************************************** // Do not make any changes below this line //****************************************************** interface Pattern { void draw(); } /* * render 'number' copies of the model pattern, with each drawn at * given radius from center and at given scale, and with the first * placed at angle theta. */ void stamp(Pattern model, int number, float radius, float scale, float theta) { float incr = TWO_PI/number; for (int j=0; j