Truchet Tiles 002

Thanks to Dan Catt see:
youtu.be/1qlwiyrdeom?feature=shared&t=61

Log in to post a comment.

// Forked from "Truchet Tiles 001" by rupertxrussell
// https://turtletoy.net/turtle/ea4178a3db

// My first Turchet Tiles
// inspired by Rev Dan Catt 70's Pop 
// https://shop.revdancatt.com/collections/pen-plots/products/70s-pop-tiles-a3-64-up-2
// https://www.youtube.com/watch?v=1QLWiyrDEOM

// Released under the MIT licence 
// https://mit-license.org/
// you can use this for commercial gain if you like eg you can sell artworks with this image.

// You can find the Turtle API reference here: https://turtletoy.net/syntax
Canvas.setpenopacity(1);

// Global code will be evaluated once.

const turtle = new Turtle();
const scale = 24.5; // min=20 max=24.5 step=0.25
const margin = 0; // min=0 max=4.25 step=0.25
const drawBorders = 0; // min=0 max=1 step=1 (No, Yes)
const chanceOfLines = 5; // min=0 max=50 step=1

for(var i = -4; i < 4; i++){
    for(var j =-4; j < 4; j++){
    
        rand = getRandomInt(6);
       // rand = a;
        if(rand == 0){
            turtle.jump(i * scale, j * scale)
            turtle.penup();
            turtle.forward(margin * i);
            turtle.right(90);
            turtle.forward(margin * j)
            turtle.left(90);
            square(1)
        }
    
        if(rand == 1){
            turtle.jump(i * scale, j * scale);
            turtle.penup();
            turtle.forward(margin * i);
            turtle.right(90);
            turtle.forward(margin * j)
            turtle.left(90);            
            turtle.forward(scale) // reposition 
            turtle.right(90);
            
            square(1) 
            turtle.penup();
            turtle.left(90);
            turtle.back(scale) // reposition
        }
    
        if(rand == 2){
            turtle.jump(i * scale, j * scale);
            turtle.penup();
            turtle.forward(margin * i);
            turtle.right(90);
            turtle.forward(margin * j)
            turtle.left(90);
            turtle.right(180);
            turtle.jump(turtle.xcor()+scale, turtle.ycor()+scale);
            square(1) 
            turtle.left(180);
        }
    
        if(rand == 3){
            turtle.jump(i * scale, j * scale);
            turtle.penup();
            turtle.forward(margin * i)
            turtle.right(90);
            turtle.forward(margin * j)
            turtle.left(90);
            turtle.right(270);
            turtle.jump(turtle.xcor(), turtle.ycor()+scale);
            square(1) 
            turtle.left(270);
        }    
        
        if(rand == 4){
            // 8 vertical lines
            turtle.jump(i * scale, j * scale)
            turtle.penup();
            turtle.forward(margin * i);
            turtle.right(90);
            turtle.forward(margin * j)
            turtle.left(90);
            
            // modify chance of drawing paralel lines
            chance = getRandomInt(chanceOfLines);
            if(chance >= 1){
                square(2);
            }
            else if (chance <=1){
                square(1);
            }
        }
        
        if(rand == 5){
            // horizontal lines
            turtle.jump(i * scale, j * scale);
            turtle.penup();
            turtle.forward(margin * i);
            turtle.right(90);
            turtle.forward(margin * j)
            turtle.left(90);            
            turtle.forward(scale) // reposition 
            turtle.right(90);
            
             // modify chance of drawing paralel lines
            chance = getRandomInt(chanceOfLines);
            if(chance >= 1){
                square(2);
            }
            else if (chance <=1){
                square(1);
            }
            turtle.penup();
            turtle.left(90);
            turtle.back(scale) // reposition
            
        }
    }
}

function square(n) {
    turtle.pendown();
    
    // Square type 1
    if(n==1){
        for(var n=1; n<9; n++){
            // draw 8 arcs
            turtle.penup();
            turtle.forward(scale/8); 
            turtle.right(90);
            turtle.pendown();
            turtle.circle(scale/8*n, 90);
            turtle.penup();
            turtle.circle(scale/8*n, -90);
            turtle.left(90);
        }
        // finish square
        
        if(drawBorders ==  1){    
            turtle.pendown();
        }
        for(var sides = 0; sides <4; sides++ ){
            turtle.right(90);
            turtle.forward(scale);
        }
        
    // move to SE corner
    turtle.penup();
    turtle.right(90);
    turtle.forward(scale);
    
    // first small arc 
    turtle.left(270);
    for(var n=1; n<4; n++){
        // draw 3 full small arcs
        turtle.penup();
        turtle.forward(scale/8); 
        turtle.right(90);
        turtle.pendown();
        turtle.circle(scale/8*n, 90);
        turtle.penup();
        turtle.circle(scale/8*n, -90);  // reverse arc to edge
        turtle.left(90);
    }
  
    // South 1st half arc  
    turtle.forward(scale/8);
    turtle.right(90);
    turtle.pendown();
    turtle.circle(scale/8*4, 17);
    turtle.penup();
    turtle.circle(scale/8*4, -17); // reverse arc to edge
    turtle.left(90);     
    turtle.pendown();
     
    // east 1st half arc  
    turtle.penup();
    turtle.right(180);
    turtle.forward(4 * scale/8);
    turtle.left(90);
    turtle.forward(4 * scale/8)
    turtle.left(270);
    turtle.pendown();
    turtle.circle(scale/8*4,-17); 
    turtle.penup();
    turtle.circle(scale/8*4, 17); // reverse arc to edge
    turtle.right(270);     
    turtle.penup();
    
    // east 2nd half arc  
    turtle.penup();
    turtle.forward(scale/8);
    turtle.left(270);
    turtle.pendown()
    turtle.circle(scale/8*5, -6.8);
    turtle.circle(scale/8*5, 6.8);  // reverse arc to edge

    // start east 3rd half arc
    turtle.left(90);
    turtle.penup();
    turtle.forward(scale/8);
    turtle.left(270);
    turtle.pendown();
    turtle.circle(scale/8*6, -2.42);
    turtle.circle(scale/8*6, 2.42);  // reverse arc to edge
    // end 3rd half arc 

    // start of south 2rd half arc
    // move around the square to start pos
    turtle.penup();
    turtle.right(90)
    turtle.forward(6* scale/8);
    turtle.right(90)
    turtle.forward(5* scale/8);
    turtle.pendown()
    
    turtle.right(90);
    turtle.pendown()
    turtle.circle(scale/8*5, 6.8);
    turtle.penup();
    turtle.circle(scale/8*5, -6.8);

    // start of south 3rd half arc
    // move around the square to start pos
    turtle.penup();
    turtle.left(90);
    turtle.forward(scale/8);
    turtle.right(270);
    turtle.pendown();
    turtle.circle(scale/8*6, -2.42);
    turtle.circle(scale/8*6, 2.42)
   
    // start of south 4rd half arc
    // move around the square to start pos
    turtle.penup();
    turtle.right(90);
    turtle.forward(scale/8);
    turtle.right(270);
    turtle.pendown();
    turtle.circle(scale/8*6, -0.6); // -0.4
    turtle.circle(scale/8*6, 0.6)
  
    // start of east 4rd half arc
    // move around the square to start pos
    turtle.penup();
    turtle.right(90);
    turtle.forward(scale/8);
    turtle.right(270);
    turtle.pendown();
    turtle.circle(scale/8*6, -0.6); // -0.4
    turtle.circle(scale/8*6, 0.6)
    
    turtle.right(90);
    turtle.right(90);
    turtle.right(90);

    }  // end of square type 1
    
    // Square type 2 parallel lines
    if(n==2){

        if(drawBorders == 0){
            numOfLines = 10;
        }
        else if(drawBorders == 1){
           numOfLines = 9; 
        }

        for(var n=1; n<numOfLines; n++){
            // draw parallel lines
            turtle.right(90);
            turtle.pendown();
            turtle.forward(scale);
            turtle.penup();
            turtle.back(scale);
            turtle.left(90);
            turtle.penup();
            turtle.forward(scale/8); 
        }
        // finish square
        if(drawBorders ==  1){    
            turtle.pendown();
        }
        for(var sides = 0; sides <4; sides++ ){
            turtle.right(90);
            turtle.forward(scale);
        }
    }
} // end of function Square

 
function drawTurtle(turtleScale){
    var originalHeading =turtle.heading();   
    turtle.pendown();
    turtle.right(160);
    turtle.forward(turtleScale*.25);
    turtle.back(turtleScale*.25);
    turtle.left(160 *2);
    turtle.forward(turtleScale*.25);
    turtle.back(turtleScale*.25);
    turtle.seth(originalHeading);
    turtle.penup();
}

function getRandomInt(max) {
    return Math.floor(Math.random() * max);
}