> show canvas only <


/* built with Studio Sketchpad: 
 *   https://sketchpad.cc
 * 
 * observe the evolution of this sketch: 
 *   https://studio.sketchpad.cc/sp/pad/view/ro.QvqPq0C8R5y/rev.282
 * 
 * authors: 
 *   hansi raber
 *   

 * license (unless otherwise specified): 
 *   creative commons attribution-share alike 3.0 license.
 *   https://creativecommons.org/licenses/by-sa/3.0/ 
 */ 



// how to render a star... 
// code taken from: 
// http://processing.org/learning/anatomy/

void setup() {  // this is run once.   
    size(300, 300);  // 300x300 pixel groß
    smooth(); // weichzeichnen aktivieren
    frameRate(30); // 30 mal pro sekunde neu malen
} 

// das wird immer und immer wieder ausgeführt
void draw() {
    background(255); // hintergrund weiß
    stroke( 0 ); // strichfarbe schwarz
    
    float start = atan2( mouseY - height/2, mouseX - width/2 ); 
    float sz = min( width/2, height/2 ) - 10; 
    int n = round( 3 + mouseY*7/height );  // von 3...10
    float proportion = 2*mouseX/width;  // von 0...2
    star( n, width/2, height/2, sz, sz, start, proportion ); 
}


void star(int n, float cx, float cy, float w, float h,
  float startAngle, float proportion)
{
  if (n > 2)
  {
    float angle = TWO_PI/ (2 *n);  // twice as many sides
    float dw; // draw width
    float dh; // draw height
    
    w = w / 2.0;
    h = h / 2.0;
   
    beginShape();
    for (int i = 0; i < 2 * n; i++)
    {
      dw = w;
      dh = h;
      if (i % 2 == 1) // for odd vertices, use short radius
      {
        dw = w * proportion;
        dh = h * proportion;
      }
      vertex(cx + dw * cos(startAngle + angle * i),
        cy + dh * sin(startAngle + angle * i));
    }
    endShape(CLOSE);
  }
}