topical media & game development

talk show tell print

#javascript-processing-example-basic-transform-rotate.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>Rotate</h2>
  
  <p>Rotating a square around the Z axis. To get the results
  you expect, send the rotate function angle parameters that are
  values between 0 and PI*2 (TWO_PI which is roughly 6.28). If you prefer to 
  think about angles as degrees (0-360), you can use the radians() 
  method to convert your values. For example: scale(radians(90))
  is identical to the statement scale(PI/2).</p>
  
  <p><a href="http://processing.org/learning/basics/rotate.html"><b>Original Processing.org Example:</b> Rotate</a><br>
  <script type="application/processing">
  void setup()
  {
    size(200,200);
    noStroke();
    fill(255);
    frameRate(30);
  }
  
  float angle;
  float cosine;
  float jitter;
  
  void draw()
  {
    background(102);
    
    if(second()%2 == 0){
      jitter = (random(-0.1, 0.1));
    }
    angle = angle + jitter;
    cosine = cos(angle);
    
    translate(width/2, height/2);
    rotate(cosine);
    rectMode(CENTER);
    rect(0, 0, 115, 115);   
  }
  </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>
  void setup()
  {
    size(200,200);
    noStroke();
    fill(255);
    frameRate(30);
  }
  
  float angle;
  float cosine;
  float jitter;
  
  void draw()
  {
    background(102);
    
    if(second()%2 == 0){
      jitter = (random(-0.1, 0.1));
    }
    angle = angle + jitter;
    cosine = cos(angle);
    
    translate(width/2, height/2);
    rotate(cosine);
    rectMode(CENTER);
    rect(0, 0, 115, 115);   
  }</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.