> show canvas only <


/* built with Studio Sketchpad: 
 *   https://sketchpad.cc
 * 
 * observe the evolution of this sketch: 
 *   https://studio.sketchpad.cc/sp/pad/view/ro.DQewLP$5fJn/rev.2
 * 
 * authors: 
 *   (Unnamed author)

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



// This sketch builds on a prior work, "Untitled Sketch", created by [unnamed author]
// http://sketchpad.cc/sp/pad/view/ro.USHF5wM7QYC/rev.1109



// Pressing Control-R will render this sketch.

int canvasWidth = 300;
int i = 0; 
int margin = 10;
var o = 0;
var x = margin;
var y = margin;
var w = canvasWidth - margin * 2;
var h = canvasWidth - margin * 2;
var a = 1;
var b = 2;
var c = 4;
var d = 12;


void setup() {  // this is run once.   
    
    // set the background color
    background(255);
    
    // canvas size (Integers only, please.)
    size(300, 300); 

    // smooth edges
    smooth();
    
    // limit the number of frames per second
    frameRate(1);
    
    // set the width of the line. 
    strokeWeight(1);

    // set the color
    //stroke(random(50), random(255), random(255), 100);
    stroke(0);

    // set up font
    PFont fontA = loadFont("Arial");  
    textFont(fontA, 16);  
    fill(0);
} 

void draw() {  // this is run repeatedly.  
    

    fill(255);
    rect(15, 100, 50, -50);
    fill(0);
    text(i, 15, 100);

    drawSquare(o, x, y, w);
    
    o = o == 0 ? 1 : 0;
    
    if ( o == 0 )
    {
        x = x - (w / 2);
        y = y + (w / 2);
        a1 = Math.abs(d - a);
        b1 = Math.abs(a - b);
        c1 = Math.abs(b - c);
        d1 = Math.abs(c - d);
    }
    else
    {
        x = x + (w / 2);
        y = y;
        w = w / 2;
        a1 = Math.abs(a - b);
        b1 = Math.abs(b - c);
        c1 = Math.abs(c - d);
        d1 = Math.abs(d - a);
    }
    a = a1;
    b = b1;
    c = c1;
    d = d1;

}

void drawSquare(o, x, y, w)
{
    if (a == 0 && b == 0 && c == 0 && d == 0)
        return;
                
    i = i + 1;
    
    if (o == 0)
    {
        text(a, x, y);
        line(x, y, x + w, y);
        text(b, x + w, y);
        line(x + w, y, x + w, y + w);
        text(c, x + w, y + w);
        line(x + w, y + w, x, y + w);
        text(d, x, y + w);
        line(x, y + w, x, y);
    } else
    {
        text(a, x, y);
        line(x, y, x + w, y + w);
        text(b, x + w, y + w, y);
        line(x + w, y + w, x, y + w * 2);
        text(c, x, y + w * 2);
        line(x, y + w * 2, x - w, y + w);
        text(d, x - w, y + w);
        line(x - w, y + w, x, y);
    }

}