Multiple Snowflakes working towards snowflakes Dan Catt see his work at: revdancatt.com/penplotter/036-snowflakes Dan's list of Pen Plotter Tools at: revdancatt.com/penplotter/
Log in to post a comment.
// Forked from "Snowflake 005" by rupertxrussell // Draw Multiple Snoflakes // https://turtletoy.net/turtle/6fcb393f39 // Forked from "Stars 001" by rupertxrussell // https://turtletoy.net/turtle/01d0bf10d6 // You can find the Turtle API reference here: https://turtletoy.net/syntax // MIT Licence // Draw a Single Snowflake // working towards Dan Catt's snowflakes // see his work at: https://revdancatt.com/penplotter/036-Snowflakes // See Dan's full list of Pen Plotter Tools at: https://revdancatt.com/penplotter/ Canvas.setpenopacity(1); let maxScale=20; //min=2 max=25 step=1 const turtle = new Turtle(); // generate a random number of branches // let nBranches = 3; //min=2 max=15 step=1 let xPos = 0; let yPos = 0; let nBranches = 0; let xOffset = 46 //min=20 max=55 step=1 let yOffset = 46 //min=20 max=55 step=1 for (let yPos = -70; yPos < 90; yPos = yPos + yOffset){ for (let xPos = -70; xPos < 90; xPos = xPos + xOffset){ if(nBranches == 1){ nBranches = 2 } snowFlake(xPos, yPos, nBranches); nBranches ++; } } function snowFlake(xPos, yPos, nBranches) { // scale = getRandomInt(maxScale + 1); scale = maxScale; armLength = scale; turtle.penup(); turtle.goto(xPos, yPos); // N S arm turtle.penup(); turtle.goto(xPos, yPos); turtle.pendown(); turtle.setheading(90); turtle.penup(); turtle.forward(scale); let position3 = turtle.position(); turtle.pendown(); turtle.right(180); turtle.forward(scale * 2); let position0 = turtle.position(); // NW SE arm turtle.penup(); turtle.goto(xPos, yPos); turtle.pendown(); turtle.setheading(30); turtle.penup(); turtle.forward(scale); turtle.pendown(); let position2 = turtle.position(); turtle.right(180); turtle.forward(scale * 2); let position5 = turtle.position(); // SW NE arm turtle.penup(); turtle.goto(xPos, yPos); turtle.setheading(-30); turtle.penup(); turtle.forward(scale); turtle.pendown(); let position1 = turtle.position(); turtle.right(180); turtle.forward(scale * 2); let position4 = turtle.position(); /* // draw star of david turtle.jump(position0); turtle.pendown(); turtle.goto(position2) turtle.goto(position4) turtle.goto(position0) turtle.jump(position5); turtle.pendown(); turtle.goto(position1) turtle.goto(position3) turtle.goto(position5) */ // draw nBarnches let stepLength = armLength / nBranches; for(let arm = 0; arm < 6; arm ++){ for(let n = 1; n < nBranches; n ++){ let branchLength = (armLength - stepLength * n) / 2 // go to center of the snowflake turtle.setheading(30 + arm * 60); turtle.penup(); turtle.goto(xPos, yPos); turtle.right(180); turtle.forward(stepLength * n); turtle.right(60); turtle.pendown(); turtle.forward(branchLength); turtle.back(branchLength); turtle.left(60 * 2) turtle.forward(branchLength); } } } // Used to draw the angled branches function branch(armLength, stepLength){ let branchLength = (armLength - stepLength) / 2 return branchLength; } function getRandomInt(max) { return Math.floor(Math.random() * max); }