Inspired by: machine.arm sketch 149
instagram.com/p/dawupp4ybsn/
Log in to post a comment.
// You can find the Turtle API reference here: https://turtletoy.net/syntax
Canvas.setpenopacity(1);
// const drawmode = 2; // min=1, max=2, step=1
const drawmode = 2; // min=0, max=2, step=1, (Black Lines, White Lines, Both)
const outline = 0; // min=0, max=1, step=1, (Yes, No)
const turtle = new Turtle();
const numLines = 44; //min=5 max=50 step=1
const x1 = -48; //min=-100 max=100 step=1
const y1 = -43; //min=-100 max=100 step=1
const x2 = 55; //min=-100 max=100 step=1
const y2 = 46; //min=-100 max=100 step=1
const x3 = -22; //min=-100 max=100 step=1
const y3 = -2; //min=-100 max=100 step=1
const x4 = 27; //min=-100 max=100 step=1
const y4 = 24; //min=-100 max=100 step=1
if(outline==0){
rectangle(x1,y1,x2,y2);
rectangle(x3,y3,x4,y4);
}
if(drawmode==0){
whiteLines(x1,y1,x2,y2,x3,y3,x4,y4)
}
else if(drawmode==1){
blackLines(x1,y1,x2,y2,x3,y3,x4,y4)
}
else{
whiteLines(x1,y1,x2,y2,x3,y3,x4,y4)
blackLines(x1,y1,x2,y2,x3,y3,x4,y4)
}
function rectangle(xA,yA,xB,yB){
// top line
turtle.penup();
turtle.goto(xA,yA);
turtle.pendown();
turtle.goto(xB,yA);
// bottom line
turtle.penup();
turtle.goto(xA,yB);
turtle.pendown();
turtle.goto(xB,yB);
// left line
turtle.penup();
turtle.goto(xA,yA);
turtle.pendown();
turtle.goto(xA,yB);
//right line
turtle.penup();
turtle.goto(xB,yA);
turtle.pendown();
turtle.goto(xB,yB);
} // end rectangle
function whiteLines(xA,yA,xB,yB,xC,yC,xD,yD){
// Top and Right sides of rectangles
var baseHeight = yA-yB;
var topWidth = xC-xD;
var topHeight = yC-yD;
// Outer edges
// top left corners
turtle.penup();
turtle.goto(xA,yA);
turtle.pendown();
turtle.goto(xC,yC)
//top right corners
turtle.penup();
turtle.goto(xB,yA);
turtle.pendown();
turtle.goto(xD,yC)
// divide the top line into x equal segments
var baseWidth = Math.abs(xA-xB);
var topGap = baseWidth / numLines;
var topWidth = Math.abs(xC-xD);
var bottomGap = topWidth / numLines;
var baseHeight = Math.abs(yA-yB);
var rightHeight = Math.abs(yA-yB);
var leftHeight = Math.abs(yC-yD);
var topSideGap = leftHeight / numLines;
var bottomSideGap = rightHeight / numLines;
// Loop though numLines to draw Top White lines
for(j=0; j<=numLines; j++){
turtle.penup();
turtle.goto(xA+j*topGap, yA);
turtle.pendown();
turtle.goto(xC+j*bottomGap,yC);
} // end top White lines
// Loop though numLines to draw Side White lines
for(j=0; j<=numLines; j++){
turtle.penup();
turtle.goto(xD,yC+j*topSideGap);
turtle.pendown();
turtle.goto(xB,yA+j*bottomSideGap);
} // end top White lines
}
function blackLines(xA,yA,xB,yB,xC,yC,xD,yD){
var baseHeight = yA-yB;
var topWidth = xC-xD;
var topHeight = yC-yD;
// divide the top line into x equal segments
var baseWidth = Math.abs(xA-xB);
var topGap = baseWidth / numLines;
var topWidth = Math.abs(xC-xD);
var bottomGap = topWidth / numLines;
var baseHeight = Math.abs(yA-yB);
var rightHeight = Math.abs(yA-yB);
var leftHeight = Math.abs(yC-yD);
var topSideGap = leftHeight / numLines;
var bottomSideGap = rightHeight / numLines;
// Loop though numLines to draw left side Black lines
for(j=0; j<=numLines; j++){
turtle.penup();
turtle.goto(xC,yC+j*topSideGap);
turtle.pendown();
turtle.goto(xA,yA+j*bottomSideGap);
} // end top White lines
// Loop though numLines to draw Bottom Black lines
for(j=0; j<=numLines; j++){
turtle.penup();
turtle.goto(xA+j*topGap, yB);
turtle.pendown();
turtle.goto(xC+j*bottomGap,yD);
} // end top black lines
}