Impossible Triangle for Artuarag

Reproduces the 2nd drawing method shown in this WikiHow

Crated for Artuaragon

wikihow.com/draw-an-impossible-triangle

Log in to post a comment.

// You can find the Turtle API reference here: https://turtletoy.net/syntax
// Crated for Artuaragon https://turtletoy.net/user/artuaragon
// Based on this guide: https://www.wikihow.com/Draw-an-Impossible-Triangle
// 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.


Canvas.setpenopacity(1);
// this is not the best version to plot as it draws 
// smail (width) lines to extend the first inner triangle
// todo save the location of the inner extended triangle lines 
// and draw them in one single line


// Global code will be evaluated once.
const turtle = new Turtle();

const scale = 70; //min=50 max=130 step=5
const width = scale * 0.1;

// a simple way to save the current location
// of the turtle so we can jump back to a specific position
var xPos = [];
var yPos = [];

turtle.penup();
turtle.goto(scale * -0.5, scale * 0.4);
turtle.pendown();

// save current location 0
xPos.push(turtle.x());
yPos.push(turtle.y());

// inner triangle
// lower line
turtle.forward(scale);
// save current location 1
xPos.push(turtle.x());
yPos.push(turtle.y());


// draw right side
turtle.left(360/3);
turtle.forward(scale);
// save current location 2
xPos.push(turtle.x());
yPos.push(turtle.y());

// drawnleft side
turtle.left(360/3);
turtle.forward(scale);

// extend the base line from the lower right corner
turtle.seth(0);
turtle.jump(xPos[1],yPos[1]);
turtle.forward(width);
// save current location 3
xPos.push(turtle.x());
yPos.push(turtle.y());

// extend the right side from the top corner
turtle.seth(-360/3);
turtle.jump(xPos[2],yPos[2]);
turtle.forward(width);
// save current location 4
xPos.push(turtle.x());
yPos.push(turtle.y());

// extend the right side from the top corner
turtle.seth(360/3);
turtle.jump(xPos[0],yPos[0]);
turtle.forward(width);
// save current location 5
xPos.push(turtle.x());
yPos.push(turtle.y());

// draw middle right side
turtle.jump(xPos[3],yPos[3]);
turtle.seth(-360/3);
turtle.forward(scale + width * 3);
// save current location 6
xPos.push(turtle.x());
yPos.push(turtle.y());

//draw middle left side
turtle.jump(xPos[4],yPos[4]);
turtle.seth(360/3);
turtle.forward(scale + width * 3);
// save current location 7
xPos.push(turtle.x());
yPos.push(turtle.y());

//draw middle bottom side
turtle.jump(xPos[5],yPos[5]);
turtle.seth(0);
turtle.forward(scale + width * 3);
// save current location 8
xPos.push(turtle.x());
yPos.push(turtle.y());

// draw 3 backwards facing widths
// bottom right
turtle.right(360/3)
turtle.forward(width);
// save current location 9
xPos.push(turtle.x());
yPos.push(turtle.y());

// top right
turtle.right(360/3)
turtle.jump(xPos[6],yPos[6]);
turtle.seth(0);
turtle.forward(width);
// save current location 10
xPos.push(turtle.x());
yPos.push(turtle.y());

// bottom left
turtle.right(360/3)
turtle.jump(xPos[7],yPos[7]);
turtle.seth(-360/3);
turtle.forward(width);
// save current location 11
xPos.push(turtle.x());
yPos.push(turtle.y());

// finish off outer 3 lines
// outer right
turtle.jump(xPos[10],yPos[10]);
turtle.seth(-360/3 + 180);
turtle.forward(scale + width * 4);

// outer left
turtle.jump(xPos[6],yPos[6]);
turtle.seth(360/3);
turtle.forward(scale + width * 4);

// outer bottom
turtle.jump(xPos[9],yPos[9]);
turtle.seth(180);
turtle.forward(scale + width * 4);