topical media & game development

talk show tell print

#javascript-processing-example-basic-transform-triangleflower.htm / htm



  <!DOCTYPE html>
  <html><head>
  <script src="javascript-processing-example-processing.js"></script>
  <script src="javascript-processing-example-init.js"></script>
  <link rel="stylesheet" href="javascript-processing-example-style.css">
  </head><body><h1><a href="http://ejohn.org/blog/processingjs/">Processing.js</a></h1>
  <h2>TriangleFlower</h2>
  
  <p>By Ira Greenberg 
  
  Using rotate() and triangle() 
  functions generate a pretty 
  flower. Uncomment the line
  // rotate(rot+=radians(spin));
  in the triBlur() function for 
  a nice variation.</p>
  
  <p><a href="http://processing.org/learning/basics/triangleflower.html"><b>Original Processing.org Example:</b> TriangleFlower</a><br>
  <script type="application/processing">
  Point[]p = new Point[3];
  float shift = 1.0;
  float fade = 0;
  float fillCol = 0;
  float rot = 0;
  float spin = 0;
  
  void setup(){
    size(200, 200);
    background(0);
    smooth();
    fade = 255.0/(width/2.0/shift);
    spin = 360.0/(width/2.0/shift);
    p[0] = new Point(-width/2, height/2);
    p[1] = new Point(width/2, height/2);
    p[2] = new Point(0, -height/2);
    noStroke();
    translate(width/2, height/2);
    triBlur();
  }
  
  void triBlur(){
    fill(fillCol);
    fillCol+=fade;
    rotate(spin);
    // another interesting variation: uncomment the line below 
    // rotate(rot+=radians(spin));
    triangle(p[0].x+=shift, p[0].y-=shift/2, p[1].x-=shift, p[1].y-=shift/2, p[2].x, p[2].y+=shift); 
    if(p[0].x<0){
      // recursive call
      triBlur();
    }
  }
  </script><canvas width="200" height="200"></canvas></p>
  <div style="overflow: hidden; height: 0px; width: 0px;"></div>
  
  <pre><b>// All Examples Written by <a href="http://reas.com/">Casey Reas</a> and <a href="http://benfry.com/">Ben Fry</a>
  // unless otherwise stated.</b>
  Point[]p = new Point[3];
  float shift = 1.0;
  float fade = 0;
  float fillCol = 0;
  float rot = 0;
  float spin = 0;
  
  void setup(){
    size(200, 200);
    background(0);
    smooth();
    fade = 255.0/(width/2.0/shift);
    spin = 360.0/(width/2.0/shift);
    p[0] = new Point(-width/2, height/2);
    p[1] = new Point(width/2, height/2);
    p[2] = new Point(0, -height/2);
    noStroke();
    translate(width/2, height/2);
    triBlur();
  }
  
  void triBlur(){
    fill(fillCol);
    fillCol+=fade;
    rotate(spin);
    // another interesting variation: uncomment the line below 
    // rotate(rot+=radians(spin));
    triangle(p[0].x+=shift, p[0].y-=shift/2, p[1].x-=shift, p[1].y-=shift/2, p[2].x, p[2].y+=shift); 
    if(p[0].x&lt;0){
      // recursive call
      triBlur();
    }
  }</pre>
  </body></html>
  


(C) Æliens 20/2/2008

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.